]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Update the switch source header support
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 8 Mar 2022 22:22:09 +0000 (14:22 -0800)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 8 Mar 2022 22:22:09 +0000 (14:22 -0800)
autoload/lsp/handlers.vim
autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
doc/lsp.txt
plugin/lsp.vim

index b6fe2638b7f36c8e4373416b386dd29f56f6ce58..89b8ddf6ce3c05f9325dabbd29f64bda75f0d284 100644 (file)
@@ -147,8 +147,12 @@ def ProcessDefDeclReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>):
 enddef
 
 # process the 'textDocument/switchSourceHeader' reply from the LSP server
+# Clangd specific extension
 # Result: URI | null
 def ProcessSwitchHeaderReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
+  if reply.result->empty()
+    return
+  endif
   var fname = util.LspUriToFile(reply.result)
   if (&modified && !&hidden) || &buftype != ''
     # if the current buffer has unsaved changes and 'hidden' is not set,
index 19abc900bfc9502fa89019e78ccc892070fb1106..e4f4c8ba4c8cfd46471b42eb97fbb576844058c0 100644 (file)
@@ -216,6 +216,7 @@ export def GotoDefinition(peek: bool)
 enddef
 
 # Switch source header using "textDocument/switchSourceHeader" LSP request
+# (Clangd specifc extension)
 export def SwitchSourceHeader()
   var lspserver: dict<any> = CurbufGetServerChecked()
   if lspserver->empty()
index e99d941254defac369c11de3f48c8e179dcc62d8..92ab3b1fceb8df17814b7965fcb9cafa7e6f4f32 100644 (file)
@@ -479,6 +479,7 @@ enddef
 
 # Request: "textDocument/switchSourceHeader"
 # Param: TextDocumentIdentifier
+# Clangd specific extension
 def SwitchSourceHeader(lspserver: dict<any>)
   var req = lspserver.createRequest('textDocument/switchSourceHeader')
   req.params->extend({uri: util.LspFileToUri(@%)})
index 7f631ce58c10a7087246bbcd5e60d11ef1935966..0ad70a077aed7a2057c2c24ea7dd535294684471 100644 (file)
@@ -319,7 +319,9 @@ diagnostic messages, you can add the following line to your .vimrc file:
                        Default is false.
 
                                                *:LspSwitchSourceHeader*
-:LspSwitchSourceHeader Switch between source and header files.
+:LspSwitchSourceHeader Switch between source and header files. This is a
+                       Clangd specific extension and only works with C/C++
+                       source files.
 
                                                *:LspDiagShow*
 :LspDiagShow           Creates a new location list with the diagnostics
index d30577849e06b24db116f2b86be1fc347c14f1bd..dd3f79e432d7dd2d89db3c41b9317f368f7ad3e7 100644 (file)
@@ -6,6 +6,10 @@ if !has('patch-8.2.2342')
   finish
 endif
 
+# The following is needed to support both Vim 8.2.3741 (shipped with Ubuntu
+# 21.10) and the latest Vim. The Vim9 script syntax for import changed between
+# these two versions. Once offical Vim9 is out, the following can be
+# simplified.
 var opt = {}
 var lspf = {}
 if has('patch-8.2.4257')
@@ -85,6 +89,7 @@ elseif has('patch-8.2.4019')
   lspf.hover = lsp_import.Hover
   lspf.selectionExpand = lsp_import.SelectionExpand
   lspf.selectionShrink = lsp_import.SelectionShrink
+  lspf.switchSourceHeader = lsp_import.SwitchSourceHeader
   lspf.foldDocument = lsp_import.FoldDocument
   lspf.listWorkspaceFolders = lsp_import.ListWorkspaceFolders
   lspf.addWorkspaceFolder = lsp_import.AddWorkspaceFolder
@@ -121,6 +126,7 @@ else
          Hover,
          SelectionExpand,
          SelectionShrink,
+         SwitchSourceHeader,
          FoldDocument,
          ListWorkspaceFolders,
          AddWorkspaceFolder,
@@ -163,6 +169,7 @@ else
   lspf.hover = Hover
   lspf.selectionExpand = SelectionExpand
   lspf.selectionShrink = SelectionShrink
+  lspf.switchSourceHeader = SwitchSourceHeader
   lspf.foldDocument = FoldDocument
   lspf.listWorkspaceFolders = ListWorkspaceFolders
   lspf.addWorkspaceFolder = AddWorkspaceFolder
@@ -256,6 +263,8 @@ command! -nargs=0 -bar LspDiagHighlightEnable call TdiagHighlightEnable()
 command! -nargs=0 -bar LspDiagHighlightDisable call TdiagHighlightDisable()
 command! -nargs=0 -bar LspShowReferences call TshowReferences(v:false)
 command! -nargs=0 -bar LspPeekReferences call TshowReferences(v:true)
+# Clangd specifc extension to switch from one C/C++ source file to a
+# corresponding header file
 command! -nargs=0 -bar LspSwitchSourceHeader call TswitchSourceHeader()
 command! -nargs=0 -bar LspHighlight call LspDocHighlight()
 command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear()