]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Invoke the User autocmd only when some handlers is present
authorYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 31 Mar 2022 16:09:48 +0000 (09:09 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 31 Mar 2022 16:09:48 +0000 (09:09 -0700)
autoload/lsp/diag.vim
autoload/lsp/lsp.vim

index cba1364896707f15d16fb91ed4c134f1ce299e96..d4d128429f1c8350e9b3b5ea3600a4d9e2c3b7b0 100644 (file)
@@ -45,7 +45,7 @@ enddef
 # Update the signs placed in the buffer for this file
 def ProcessNewDiags(lspserver: dict<any>, bnr: number)
   if opt.lspOptions.autoPopulateDiags
-    DiagsUpdateLocList(lspserver)
+    DiagsUpdateLocList(lspserver, bnr)
   endif
 
   if !opt.lspOptions.autoHighlightDiags
@@ -157,15 +157,15 @@ enddef
 # Update the location list window for the current window with the diagnostic
 # messages.
 # Returns true if diagnostics is not empty and false if it is empty.
-def DiagsUpdateLocList(lspserver: dict<any>): bool
-  var fname: string = expand('%:p')
+def DiagsUpdateLocList(lspserver: dict<any>, bnr: number): bool
+  var fname: string = bufname(bnr)->fnamemodify(':p')
   if fname == ''
     return false
   endif
-  var bnr: number = bufnr()
 
   var LspQfId: number = 0
-  if exists('b:LspQfId') && getloclist(0, {id: b:LspQfId}).id == b:LspQfId
+  if bnr->getbufvar('LspQfId', 0) != 0 &&
+                 getloclist(0, {id: b:LspQfId}).id == b:LspQfId
     LspQfId = b:LspQfId
   endif
 
@@ -203,7 +203,7 @@ enddef
 # Display the diagnostic messages from the LSP server for the current buffer
 # in a location list
 export def ShowAllDiags(lspserver: dict<any>): void
-  if !DiagsUpdateLocList(lspserver)
+  if !DiagsUpdateLocList(lspserver, bufnr())
     util.WarnMsg('No diagnostic messages found for ' .. @%)
     return
   endif
index 9c8accb18efd737c39ed27d5c6291305e208303c..8dd73dcfc3b4ad468b1be1aa955a58dcafdbe3e8 100644 (file)
@@ -406,7 +406,9 @@ export def AddFile(bnr: number): void
     endif
   augroup END
 
-  doautocmd <nomodeline> User LspAttached
+  if exists('#User#LspAttached')
+    doautocmd <nomodeline> User LspAttached
+  endif
 
   buf.BufLspServerSet(bnr, lspserver)
 enddef