From a025c97dcfcfe399622449a54897ca9593810d3d Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Thu, 31 Mar 2022 09:09:48 -0700 Subject: [PATCH] Invoke the User autocmd only when some handlers is present --- autoload/lsp/diag.vim | 12 ++++++------ autoload/lsp/lsp.vim | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index cba1364..d4d1284 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -45,7 +45,7 @@ enddef # Update the signs placed in the buffer for this file def ProcessNewDiags(lspserver: dict, 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): bool - var fname: string = expand('%:p') +def DiagsUpdateLocList(lspserver: dict, 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): void - if !DiagsUpdateLocList(lspserver) + if !DiagsUpdateLocList(lspserver, bufnr()) util.WarnMsg('No diagnostic messages found for ' .. @%) return endif diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 9c8accb..8dd73dc 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -406,7 +406,9 @@ export def AddFile(bnr: number): void endif augroup END - doautocmd User LspAttached + if exists('#User#LspAttached') + doautocmd User LspAttached + endif buf.BufLspServerSet(bnr, lspserver) enddef -- 2.48.1