]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add support for custom request handlers
authorAndreas Louv <andreas@louv.dk>
Thu, 4 May 2023 21:23:16 +0000 (23:23 +0200)
committerAndreas Louv <andreas@louv.dk>
Wed, 17 May 2023 22:49:30 +0000 (00:49 +0200)
README.md
autoload/lsp/handlers.vim
autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
doc/lsp.txt

index 28527cbc22c04e311abace2acb55f0d5ed0de55f..63eebb1254be5c7a730161e25ce99d0f2c1ba7f5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -99,6 +99,7 @@ path|complete path to the LSP server executable (without any arguments).
 args|a list of command-line arguments passed to the LSP server. Each argument is a separate List item.
 initializationOptions|User provided initialization options. May be of any type. For example the *intelephense* PHP language server accept several options here with the License Key among others. 
 customNotificationHandlers|A dictionary of notifications and functions that can be specified to add support for custom language server notifications.
+customRequestHandlers|A dictionary of request handlers and functions that can be specified to add support for custom language server requests replies.
 features|A dictionary of booleans that can be specified to toggle what things a given LSP is providing (folding, goto definition, etc) This is useful when running multiple servers in one buffer.
 
 The LspAddServer() function accepts a list of LSP servers with the above information.
index 8d8204c21f8d36a46732e247de6413faa8737032..cc12626299bbd7b11c755fe6b6fc1114231087fa 100644 (file)
@@ -182,10 +182,6 @@ def ProcessClientUnregisterCap(lspserver: dict<any>, request: dict<any>)
   lspserver.sendResponse(request, {}, {})
 enddef
 
-def ProcessUnsupportedReq(lspserver: dict<any>, request: dict<any>)
-  util.ErrMsg($'Unsupported request message received from the LSP server ({lspserver.path}), message = {request->string()}')
-enddef
-
 # process a request message from the server
 export def ProcessRequest(lspserver: dict<any>, request: dict<any>)
   var lspRequestHandlers: dict<func> =
@@ -195,13 +191,13 @@ export def ProcessRequest(lspserver: dict<any>, request: dict<any>)
       'window/workDoneProgress/create': ProcessWorkDoneProgressCreate,
       'client/registerCapability': ProcessClientRegisterCap,
       'client/unregisterCapability': ProcessClientUnregisterCap,
-      'workspace/configuration': ProcessWorkspaceConfiguration,
-      'workspace/codeLens/refresh': ProcessUnsupportedReq,
-      'workspace/semanticTokens/refresh': ProcessUnsupportedReq
+      'workspace/configuration': ProcessWorkspaceConfiguration
     }
 
   if lspRequestHandlers->has_key(request.method)
     lspRequestHandlers[request.method](lspserver, request)
+  elseif lspserver.customRequestHandlers->has_key(request.method)
+    lspserver.customRequestHandlers[request.method](lspserver, request)
   else
     util.ErrMsg($'Unsupported request message received from the LSP server ({lspserver.path}), message = {request->string()}')
   endif
index b2f6dd3e0bc4bbd57be11389573395d95f4ede18..5e309df9de49dac1b1c12f33c5bcf1331ad15a5d 100644 (file)
@@ -612,6 +612,11 @@ export def AddServer(serverList: list<dict<any>>)
       customNotificationHandlers = server.customNotificationHandlers
     endif
 
+    var customRequestHandlers: dict<func> = {}
+    if server->has_key('customRequestHandlers')
+      customRequestHandlers = server.customRequestHandlers
+    endif
+
     var features: dict<bool> = {}
     if server->has_key('features')
       features = server.features
@@ -661,6 +666,7 @@ export def AddServer(serverList: list<dict<any>>)
                                                    server.runIfSearch,
                                                    server.runUnlessSearch,
                                                    customNotificationHandlers,
+                                                   customRequestHandlers,
                                                    features, server.debug)
 
     var ftypes = server.filetype
index 89501a2c02498566cf1bff55d69e22a35f8c09a8..7e6715ff8bbfe94e6b647ffe12d06b871e19b8ea 100644 (file)
@@ -1505,6 +1505,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list<string>,
                        runIfSearchFiles: list<any>,
                        runUnlessSearchFiles: list<any>,
                        customNotificationHandlers: dict<func>,
+                       customRequestHandlers: dict<func>,
                        features: dict<bool>, debug_arg: bool): dict<any>
   var lspserver: dict<any> = {
     id: GetUniqueServerId(),
@@ -1514,6 +1515,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list<string>,
     syncInit: isSync,
     initializationOptions: initializationOptions,
     customNotificationHandlers: customNotificationHandlers,
+    customRequestHandlers: customRequestHandlers,
     features: features,
     running: false,
     ready: false,
index 7ce342a0a60210b4d96c845355ef86b8681d0a7a..c78a9ea4699cac413f5fb8710cff039dea523159 100644 (file)
@@ -311,7 +311,13 @@ Additionally the following configurations can be made:
                        }
                }])
 <
-                                       *lsp-cfg-features*
+                                               *lsp-cfg-customRequestHandlers*
+       customRequestHandlers
+                       (Optional) some lsp servers will send additional
+                       request replies which you might want to silence or
+                       handle.  The provided request handlers will be called
+                       with a reference to the "lspserver" and the "request".
+                                               *lsp-cfg-features*
        features
                        (Optional) toggle which features should be enabled for a
                        given language server. See |lsp-multiple-servers| and