@@ -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 ) ;
0 commit comments