]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add support for LspSwitchSourceHeader command
authorSergey Vlasov <sergey@vlasov.me>
Tue, 8 Mar 2022 21:17:35 +0000 (23:17 +0200)
committerSergey Vlasov <sergey@vlasov.me>
Tue, 8 Mar 2022 21:31:15 +0000 (23:31 +0200)
autoload/lsp/handlers.vim
autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
doc/lsp.txt
plugin/lsp.vim

index d86156f1953207194d14055c38a4cda8682d0ee9..b6fe2638b7f36c8e4373416b386dd29f56f6ce58 100644 (file)
@@ -146,6 +146,19 @@ def ProcessDefDeclReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>):
   symbol.GotoSymbol(lspserver, location, req.method)
 enddef
 
+# process the 'textDocument/switchSourceHeader' reply from the LSP server
+# Result: URI | null
+def ProcessSwitchHeaderReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
+  var fname = util.LspUriToFile(reply.result)
+  if (&modified && !&hidden) || &buftype != ''
+    # if the current buffer has unsaved changes and 'hidden' is not set,
+    # or if the current buffer is a special buffer, then ask to save changes
+    exe 'confirm edit ' .. fname
+  else
+    exe 'edit  ' .. fname
+  endif
+enddef
+
 # process the 'textDocument/signatureHelp' reply from the LSP server
 # Result: SignatureHelp | null
 def ProcessSignaturehelpReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
@@ -710,6 +723,7 @@ export def ProcessReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>):
       'textDocument/definition': ProcessDefDeclReply,
       'textDocument/declaration': ProcessDefDeclReply,
       'textDocument/typeDefinition': ProcessDefDeclReply,
+      'textDocument/switchSourceHeader': ProcessSwitchHeaderReply,
       'textDocument/implementation': ProcessDefDeclReply,
       'textDocument/signatureHelp': ProcessSignaturehelpReply,
       'textDocument/completion': ProcessCompletionReply,
index e4b1c95e9106a935e5ab2c154b8967884a626847..19abc900bfc9502fa89019e78ccc892070fb1106 100644 (file)
@@ -215,6 +215,16 @@ export def GotoDefinition(peek: bool)
   lspserver.gotoDefinition(peek)
 enddef
 
+# Switch source header using "textDocument/switchSourceHeader" LSP request
+export def SwitchSourceHeader()
+  var lspserver: dict<any> = CurbufGetServerChecked()
+  if lspserver->empty()
+    return
+  endif
+
+  lspserver.switchSourceHeader()
+enddef
+
 # Go to a declaration using "textDocument/declaration" LSP request
 export def GotoDeclaration(peek: bool)
   var lspserver: dict<any> = CurbufGetServerChecked()
index 968eefec8f0b2216bbb02b6f688d6d7ed82ebd35..e99d941254defac369c11de3f48c8e179dcc62d8 100644 (file)
@@ -477,6 +477,16 @@ def GotoDefinition(lspserver: dict<any>, peek: bool)
   lspserver.waitForReponse(req)
 enddef
 
+# Request: "textDocument/switchSourceHeader"
+# Param: TextDocumentIdentifier
+def SwitchSourceHeader(lspserver: dict<any>)
+  var req = lspserver.createRequest('textDocument/switchSourceHeader')
+  req.params->extend({uri: util.LspFileToUri(@%)})
+  lspserver.sendMessage(req)
+
+  lspserver.waitForReponse(req)
+enddef
+
 # Request: "textDocument/declaration"
 # Param: DeclarationParams
 def GotoDeclaration(lspserver: dict<any>, peek: bool): void
@@ -1059,6 +1069,7 @@ export def NewLspServer(path: string, args: list<string>): dict<any>
     sendInitializedNotif: function(SendInitializedNotif, [lspserver]),
     getCompletion: function(GetCompletion, [lspserver]),
     gotoDefinition: function(GotoDefinition, [lspserver]),
+    switchSourceHeader: function(SwitchSourceHeader, [lspserver]),
     gotoDeclaration: function(GotoDeclaration, [lspserver]),
     gotoTypeDef: function(GotoTypeDef, [lspserver]),
     gotoImplementation: function(GotoImplementation, [lspserver]),
index 93ed7ccc3996c26b0f2d04ae7d74230807a535bd..7f631ce58c10a7087246bbcd5e60d11ef1935966 100644 (file)
@@ -101,6 +101,7 @@ The following commands are provided:
 :LspPeekReferences     Display the list of references to the keyword under
                        cursor in a location list associated with the preview
                        window.
+:LspSwitchSourceHeader Switch between source and header files.
 :LspHighlight          Highlight all the matches for the keyword under cursor
 :LspHighlightClear     Clear all the matches highlighted by :LspHighlight
 :LspOutline            Show the list of symbols defined in the current file
@@ -317,6 +318,9 @@ diagnostic messages, you can add the following line to your .vimrc file:
 <
                        Default is false.
 
+                                               *:LspSwitchSourceHeader*
+:LspSwitchSourceHeader Switch between source and header files.
+
                                                *:LspDiagShow*
 :LspDiagShow           Creates a new location list with the diagnostics
                        messages (if any) from the LSP server for the current
index a03eb65ea6bbe78883472ce0bd8991243e8ff4cb..d30577849e06b24db116f2b86be1fc347c14f1bd 100644 (file)
@@ -44,6 +44,7 @@ if has('patch-8.2.4257')
   lspf.hover = lsp.Hover
   lspf.selectionExpand = lsp.SelectionExpand
   lspf.selectionShrink = lsp.SelectionShrink
+  lspf.switchSourceHeader = lsp.SwitchSourceHeader
   lspf.foldDocument = lsp.FoldDocument
   lspf.listWorkspaceFolders = lsp.ListWorkspaceFolders
   lspf.addWorkspaceFolder = lsp.AddWorkspaceFolder
@@ -211,6 +212,7 @@ var TsymbolSearch = lspf.symbolSearch
 var Thover = lspf.hover
 var TselectionExpand = lspf.selectionExpand
 var TselectionShrink = lspf.selectionShrink
+var TswitchSourceHeader = lspf.switchSourceHeader
 var TfoldDocument = lspf.foldDocument
 var TlistWorkspaceFolders = lspf.listWorkspaceFolders
 var TaddWorkspaceFolder = lspf.addWorkspaceFolder
@@ -254,6 +256,7 @@ 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)
+command! -nargs=0 -bar LspSwitchSourceHeader call TswitchSourceHeader()
 command! -nargs=0 -bar LspHighlight call LspDocHighlight()
 command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear()
 command! -nargs=0 -bar LspOutline call Toutline()