From 37c3a4bea6d4c016a22ef0a2122fa93015787602 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Tue, 28 Mar 2023 19:22:53 -0700 Subject: [PATCH] When using virtual text for diag messages, don't display the diag popup. Check the LSP server job status instead of the channel status. --- autoload/lsp/diag.vim | 26 +++++++++++++++----------- autoload/lsp/lsp.vim | 13 +++++++------ autoload/lsp/lspserver.vim | 20 ++++++++++---------- autoload/lsp/options.vim | 6 ++++++ 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 83ae122..2f868ed 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -19,7 +19,7 @@ export def InitOnce() {name: 'LspDiagHint', text: 'H>', texthl: 'Question', linehl: lineHL}]) - if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText + if opt.lspOptions.showDiagWithVirtualText if !hlexists('LspDiagVirtualText') hlset([{name: 'LspDiagVirtualText', linksto: opt.lspOptions.diagVirtualTextHL}]) @@ -51,7 +51,7 @@ def DiagsRefreshSigns(lspserver: dict, bnr: number) # Remove all the existing diagnostic signs sign_unplace('LSPDiag', {buffer: bnr}) - if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText + if opt.lspOptions.showDiagWithVirtualText # Remove all the existing virtual text prop_remove({type: 'LspDiagVirtualText', bufnr: bnr, all: true}) endif @@ -71,7 +71,7 @@ def DiagsRefreshSigns(lspserver: dict, bnr: number) lnum: lnum, name: DiagSevToSignName(diag.severity)}) - if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText + if opt.lspOptions.showDiagWithVirtualText prop_add(lnum, 0, {bufnr: bnr, type: 'LspDiagVirtualText', text: $'┌─ {diag.message}', @@ -399,8 +399,10 @@ export def LspDiagsJump(lspserver: dict, which: string): void if which == 'first' setcursorcharpos(diags[0].range.start.line + 1, diags[0].range.start.character + 1) - :redraw - DisplayDiag(diags[0]) + if !opt.lspOptions.showDiagWithVirtualText + :redraw + DisplayDiag(diags[0]) + endif return endif @@ -416,8 +418,10 @@ export def LspDiagsJump(lspserver: dict, which: string): void && col < curcol)) || (which == 'here' && (lnum == curlnum && col >= curcol)) setcursorcharpos(lnum, col) - :redraw - DisplayDiag(diag) + if !opt.lspOptions.showDiagWithVirtualText + :redraw + DisplayDiag(diag) + endif return endif endfor @@ -435,12 +439,12 @@ export def DiagsHighlightDisable() opt.lspOptions.autoHighlightDiags = false # Remove the diganostics virtual text in all the buffers. - for binfo in getbufinfo({bufloaded: true}) - if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText + if opt.lspOptions.showDiagWithVirtualText + for binfo in getbufinfo({bufloaded: true}) # Remove all virtual text prop_remove({type: 'LspDiagVirtualText', bufnr: binfo.bufnr, all: true}) - endif - endfor + endfor + endif # Remove all the existing diagnostic signs in all the buffers sign_unplace('LSPDiag') diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 3a9eafb..f66b957 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -301,9 +301,8 @@ def AddBufLocalAutocmds(lspserver: dict, bnr: number): void endif # Displaying inlay hints needs the Vim virtual text support. - if has('patch-9.0.0178') && opt.lspOptions.showInlayHints - && (lspserver.isInlayHintProvider - || lspserver.isClangdInlayHintsProvider) + if opt.lspOptions.showInlayHints && (lspserver.isInlayHintProvider + || lspserver.isClangdInlayHintsProvider) inlayhints.BufferInit(bnr) endif @@ -416,13 +415,15 @@ enddef # Restart the LSP server for the current buffer export def RestartServer() - var lspserver: dict = buf.CurbufGetServerChecked() + var lspserver: dict = buf.CurbufGetServer() if lspserver->empty() return endif - # Stop the server - lspserver.stopServer() + # Stop the server (if running) + if lspserver.running + lspserver.stopServer() + endif # Remove all the buffers with the same file type as the current buffer var ftype: string = &filetype diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 483b6f6..fc22eec 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -37,7 +37,7 @@ enddef # LSP server exit callback def Exit_cb(lspserver: dict, job: job, status: number): void - util.WarnMsg($'LSP server exited with status {status}') + util.WarnMsg($'[{strftime("%m/%d/%y %T")}]: LSP server exited with status {status}') lspserver.running = false lspserver.ready = false lspserver.requests = {} @@ -584,12 +584,12 @@ enddef # Send a request message to LSP server def SendMessage(lspserver: dict, content: dict): void - var ch = lspserver.job->job_getchannel() - if ch->ch_status() != 'open' + var job = lspserver.job + if job->job_status() != 'run' # LSP server has exited return endif - ch->ch_sendexpr(content) + job->ch_sendexpr(content) if content->has_key('id') util.TraceLog(false, $'Sent [{strftime("%m/%d/%y %T")}]: {content->string()}') endif @@ -610,8 +610,8 @@ def Rpc(lspserver: dict, method: string, params: any, handleError: bool = t req.params = {} req.params->extend(params) - var ch = lspserver.job->job_getchannel() - if ch->ch_status() != 'open' + var job = lspserver.job + if job->job_status() != 'run' # LSP server has exited return {} endif @@ -619,7 +619,7 @@ def Rpc(lspserver: dict, method: string, params: any, handleError: bool = t util.TraceLog(false, $'Sent [{strftime("%m/%d/%y %T")}]: {req->string()}') # Do the synchronous RPC call - var reply = ch->ch_evalexpr(req) + var reply = job->ch_evalexpr(req) util.TraceLog(false, $'Received [{strftime("%m/%d/%y %T")}]: {reply->string()}') @@ -677,8 +677,8 @@ def AsyncRpc(lspserver: dict, method: string, params: any, Cbfunc: func): n req.params = {} req.params->extend(params) - var ch = lspserver.job->job_getchannel() - if ch->ch_status() != 'open' + var job = lspserver.job + if job->job_status() != 'run' # LSP server has exited return -1 endif @@ -695,7 +695,7 @@ def AsyncRpc(lspserver: dict, method: string, params: any, Cbfunc: func): n Fn(test_null_channel(), reply) else # Otherwise, make an asynchronous RPC call - reply = ch->ch_sendexpr(req, {callback: Fn}) + reply = job->ch_sendexpr(req, {callback: Fn}) endif if reply->empty() return -1 diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index 1b20a99..bda616f 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -58,6 +58,12 @@ export var lspOptions: dict = { # set the LSP plugin options from the user provided option values export def OptionsSet(opts: dict) lspOptions->extend(opts) + if !has('patch-9.0.0178') + lspOptions.showInlayHints = false + endif + if !has('patch-9.0.1157') + lspOptions.showDiagWithVirtualText = false + endif enddef # return a copy of the LSP plugin options -- 2.48.1