From: Andreas Louv Date: Thu, 4 May 2023 21:23:16 +0000 (+0200) Subject: Add support for custom request handlers X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=2cd275be9fc9d93d299fec5686667196dd595ec0;p=vim-lsp.git Add support for custom request handlers --- diff --git a/README.md b/README.md index 28527cb..63eebb1 100644 --- 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. diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim index 8d8204c..cc12626 100644 --- a/autoload/lsp/handlers.vim +++ b/autoload/lsp/handlers.vim @@ -182,10 +182,6 @@ def ProcessClientUnregisterCap(lspserver: dict, request: dict) lspserver.sendResponse(request, {}, {}) enddef -def ProcessUnsupportedReq(lspserver: dict, request: dict) - 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, request: dict) var lspRequestHandlers: dict = @@ -195,13 +191,13 @@ export def ProcessRequest(lspserver: dict, request: dict) '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 diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index b2f6dd3..5e309df 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -612,6 +612,11 @@ export def AddServer(serverList: list>) customNotificationHandlers = server.customNotificationHandlers endif + var customRequestHandlers: dict = {} + if server->has_key('customRequestHandlers') + customRequestHandlers = server.customRequestHandlers + endif + var features: dict = {} if server->has_key('features') features = server.features @@ -661,6 +666,7 @@ export def AddServer(serverList: list>) server.runIfSearch, server.runUnlessSearch, customNotificationHandlers, + customRequestHandlers, features, server.debug) var ftypes = server.filetype diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 89501a2..7e6715f 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -1505,6 +1505,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list, runIfSearchFiles: list, runUnlessSearchFiles: list, customNotificationHandlers: dict, + customRequestHandlers: dict, features: dict, debug_arg: bool): dict var lspserver: dict = { id: GetUniqueServerId(), @@ -1514,6 +1515,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list, syncInit: isSync, initializationOptions: initializationOptions, customNotificationHandlers: customNotificationHandlers, + customRequestHandlers: customRequestHandlers, features: features, running: false, ready: false, diff --git a/doc/lsp.txt b/doc/lsp.txt index 7ce342a..c78a9ea 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -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