]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
When using virtual text for diag messages, don't display the diag popup. Check the...
authorYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 29 Mar 2023 02:22:53 +0000 (19:22 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 29 Mar 2023 02:22:53 +0000 (19:22 -0700)
autoload/lsp/diag.vim
autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
autoload/lsp/options.vim

index 83ae122bc348f6767406dc545274da9793b4b624..2f868ed8147ea30a523b02dd52572947a4411f85 100644 (file)
@@ -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<any>, 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<any>, 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<any>, 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<any>, 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')
index 3a9eafb56d971674c6bd2080fc59b2175b7a06d9..f66b957af05b085ceb314e97363d4cfd85e456d0 100644 (file)
@@ -301,9 +301,8 @@ def AddBufLocalAutocmds(lspserver: dict<any>, 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<any> = buf.CurbufGetServerChecked()
+  var lspserver: dict<any> = 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
index 483b6f695d249d2e6b9f252d6638703769d17f84..fc22eec30b3f38029132588e7ca36c9507948cea 100644 (file)
@@ -37,7 +37,7 @@ enddef
 
 # LSP server exit callback
 def Exit_cb(lspserver: dict<any>, 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<any>, content: dict<any>): 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<any>, 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<any>, 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<any>, 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<any>, 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
index 1b20a997d7fc7908d8bfd254390f73a6480190ed..bda616f2e5b375c5a743fc8401caecf720f40c1b 100644 (file)
@@ -58,6 +58,12 @@ export var lspOptions: dict<any> = {
 # set the LSP plugin options from the user provided option values
 export def OptionsSet(opts: dict<any>)
   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