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,
# 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(@%)})
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
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')
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
Hover,
SelectionExpand,
SelectionShrink,
+ SwitchSourceHeader,
FoldDocument,
ListWorkspaceFolders,
AddWorkspaceFolder,
lspf.hover = Hover
lspf.selectionExpand = SelectionExpand
lspf.selectionShrink = SelectionShrink
+ lspf.switchSourceHeader = SwitchSourceHeader
lspf.foldDocument = FoldDocument
lspf.listWorkspaceFolders = ListWorkspaceFolders
lspf.addWorkspaceFolder = AddWorkspaceFolder
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()