Skip to content

Commit f82a3de

Browse files
YaLTeRautozimu
authored andcommitted
Store documentHighlight buffer
1 parent 6ce0384 commit f82a3de

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/languageclient.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,19 +331,26 @@ impl State {
331331
})
332332
}).collect::<Result<Vec<_>>>()?;
333333

334-
let source = if let Some(source) = self.document_highlight_source {
335-
source
336-
} else {
337-
let source = self.call(
338-
None,
339-
"nvim_buf_add_highlight",
340-
json!([0, 0, "Error", 1, 1, 1]),
341-
)?;
342-
self.document_highlight_source = Some(source);
343-
source
344-
};
334+
let HighlightSource { buffer, source } =
335+
if let Some(highlight_source) = self.document_highlight_source {
336+
highlight_source
337+
} else {
338+
let buffer = self.call(None, "nvim_win_get_buf", json!([0]))?;
339+
let source = self.call(
340+
None,
341+
"nvim_buf_add_highlight",
342+
json!([buffer, 0, "Error", 1, 1, 1]),
343+
)?;
344+
let highlight_source = HighlightSource { buffer, source };
345+
self.document_highlight_source = Some(highlight_source);
346+
highlight_source
347+
};
345348

346-
self.notify(None, "nvim_buf_clear_highlight", json!([0, source, 0, -1]))?;
349+
self.notify(
350+
None,
351+
"nvim_buf_clear_highlight",
352+
json!([buffer, source, 0, -1]),
353+
)?;
347354
self.notify(None, "s:AddHighlights", json!([source, highlights]))?;
348355
}
349356

@@ -354,8 +361,12 @@ impl State {
354361
pub fn languageClient_clearDocumentHighlight(&mut self, _: &Value) -> Result<()> {
355362
info!("Begin {}", NOTIFICATION__ClearDocumentHighlight);
356363

357-
if let Some(source) = self.document_highlight_source.take() {
358-
self.notify(None, "nvim_buf_clear_highlight", json!([0, source, 0, -1]))?;
364+
if let Some(HighlightSource { buffer, source }) = self.document_highlight_source.take() {
365+
self.notify(
366+
None,
367+
"nvim_buf_clear_highlight",
368+
json!([buffer, source, 0, -1]),
369+
)?;
359370
}
360371

361372
info!("End {}", NOTIFICATION__ClearDocumentHighlight);

src/types.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ pub enum Call {
7979
Notification(Option<String>, rpc::Notification),
8080
}
8181

82+
#[derive(Clone, Copy, Serialize)]
83+
pub struct HighlightSource {
84+
pub buffer: u64,
85+
pub source: u64,
86+
}
87+
8288
#[derive(Serialize)]
8389
pub struct State {
8490
// Program state.
@@ -109,7 +115,7 @@ pub struct State {
109115
pub highlights_placed: HashMap<String, Vec<Highlight>>,
110116
// TODO: make file specific.
111117
pub highlight_match_ids: Vec<u32>,
112-
pub document_highlight_source: Option<u64>,
118+
pub document_highlight_source: Option<HighlightSource>,
113119
pub user_handlers: HashMap<String, String>,
114120
#[serde(skip_serializing)]
115121
pub watchers: HashMap<String, notify::RecommendedWatcher>,

0 commit comments

Comments
 (0)