autoload/lsp/handlers.vim | 4 ++++ autoload/lsp/lsp.vim | 1 + autoload/lsp/lspserver.vim | 1 + doc/lsp.txt | 4 +++- plugin/lsp.vim | 9 +++++++++ diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim index b6fe2638b7f36c8e4373416b386dd29f56f6ce58..89b8ddf6ce3c05f9325dabbd29f64bda75f0d284 100644 --- a/autoload/lsp/handlers.vim +++ b/autoload/lsp/handlers.vim @@ -147,8 +147,12 @@ symbol.GotoSymbol(lspserver, location, req.method) enddef # process the 'textDocument/switchSourceHeader' reply from the LSP server +# Clangd specific extension # Result: URI | null def ProcessSwitchHeaderReply(lspserver: dict, req: dict, reply: dict): 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, diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 19abc900bfc9502fa89019e78ccc892070fb1106..e4f4c8ba4c8cfd46471b42eb97fbb576844058c0 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -216,6 +216,7 @@ lspserver.gotoDefinition(peek) enddef # Switch source header using "textDocument/switchSourceHeader" LSP request +# (Clangd specifc extension) export def SwitchSourceHeader() var lspserver: dict = CurbufGetServerChecked() if lspserver->empty() diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index e99d941254defac369c11de3f48c8e179dcc62d8..92ab3b1fceb8df17814b7965fcb9cafa7e6f4f32 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -479,6 +479,7 @@ enddef # Request: "textDocument/switchSourceHeader" # Param: TextDocumentIdentifier +# Clangd specific extension def SwitchSourceHeader(lspserver: dict) var req = lspserver.createRequest('textDocument/switchSourceHeader') req.params->extend({uri: util.LspFileToUri(@%)}) diff --git a/doc/lsp.txt b/doc/lsp.txt index 7f631ce58c10a7087246bbcd5e60d11ef1935966..0ad70a077aed7a2057c2c24ea7dd535294684471 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -319,7 +319,9 @@ < 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 diff --git a/plugin/lsp.vim b/plugin/lsp.vim index d30577849e06b24db116f2b86be1fc347c14f1bd..dd3f79e432d7dd2d89db3c41b9317f368f7ad3e7 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -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 @@ lspf.symbolSearch = lsp_import.SymbolSearch 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 @@ SymbolSearch, Hover, SelectionExpand, SelectionShrink, + SwitchSourceHeader, FoldDocument, ListWorkspaceFolders, AddWorkspaceFolder, @@ -163,6 +169,7 @@ lspf.symbolSearch = SymbolSearch 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()