From 16a0dc2460f2cd6785f9cd90d5edb254300974d9 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Sat, 17 Jun 2023 18:26:16 -0700 Subject: [PATCH] Not able to set language server trace level during initialization --- autoload/lsp/handlers.vim | 5 ++-- autoload/lsp/lsp.vim | 59 +++++++++++++++++++------------------- autoload/lsp/lspserver.vim | 45 ++++++++++++++--------------- doc/lsp.txt | 4 +++ 4 files changed, 57 insertions(+), 56 deletions(-) diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim index 9a04cb6..428fdd4 100644 --- a/autoload/lsp/handlers.vim +++ b/autoload/lsp/handlers.vim @@ -206,8 +206,9 @@ export def ProcessRequest(lspserver: dict, request: dict) # Explicitly ignored requests var lspIgnoredRequestHandlers: list = [ - # Eclipse java language server sends the 'workspace/executeClientCommand' - # request (to reload bundles) which is not in the LSP specification. + # Eclipse java language server sends the + # 'workspace/executeClientCommand' request (to reload bundles) which is + # not in the LSP specification. 'workspace/executeClientCommand', ] diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index b66d9f3..a2d7bed 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -600,42 +600,41 @@ export def AddServer(serverList: list>) endif continue endif - var args: list = [] if server->has_key('args') if server.args->type() != v:t_list util.ErrMsg($'Arguments for LSP server {server.args} is not a List') continue endif - args = server.args + else + server.args = [] endif - var initializationOptions: dict = {} - if server->has_key('initializationOptions') - initializationOptions = server.initializationOptions + if !server->has_key('initializationOptions') + || server.initializationOptions->type() != v:t_dict + server.initializationOptions = {} endif - var customNotificationHandlers: dict = {} - if server->has_key('customNotificationHandlers') - customNotificationHandlers = server.customNotificationHandlers + if !server->has_key('customNotificationHandlers') + || server.customNotificationHandlers->type() != v:t_dict + server.customNotificationHandlers = {} endif - var ProcessDiagHandler: func = null_function if server->has_key('processDiagHandler') if server.processDiagHandler->type() != v:t_func util.ErrMsg($'Setting of processDiagHandler {server.processDiagHandler} is not a Funcref nor lambda') continue endif - ProcessDiagHandler = server.processDiagHandler + else + server.processDiagHandler = null_function endif - var customRequestHandlers: dict = {} - if server->has_key('customRequestHandlers') - customRequestHandlers = server.customRequestHandlers + if !server->has_key('customRequestHandlers') + || server.customRequestHandlers->type() != v:t_dict + server.customRequestHandlers = {} endif - var features: dict = {} - if server->has_key('features') - features = server.features + if !server->has_key('features') || server.features->type() != v:t_dict + server.features = {} endif if server.omnicompl->type() != v:t_bool @@ -648,7 +647,7 @@ export def AddServer(serverList: list>) endif if !server->has_key('name') || server.name->type() != v:t_string - || server.name->empty() + || server.name->empty() # Use the executable name (without the extension) as the language server # name. server.name = server.path->fnamemodify(':t:r') @@ -658,7 +657,15 @@ export def AddServer(serverList: list>) server.debug = false endif + if !server->has_key('traceLevel') + || server->type() != v:t_string + || (server.traceLevel != 'off' && server.traceLevel != 'debug' + && server.traceLevel != 'verbose') + server.traceLevel = 'off' + endif + if !server->has_key('workspaceConfig') + || server.workspaceConfig->type() != v:t_dict server.workspaceConfig = {} endif @@ -666,25 +673,17 @@ export def AddServer(serverList: list>) server.rootSearch = [] endif - if !server->has_key('runIfSearch') || server.runIfSearch->type() != v:t_list + if !server->has_key('runIfSearch') || + server.runIfSearch->type() != v:t_list server.runIfSearch = [] endif - if !server->has_key('runUnlessSearch') || server.runUnlessSearch->type() != v:t_list + if !server->has_key('runUnlessSearch') || + server.runUnlessSearch->type() != v:t_list server.runUnlessSearch = [] endif - var lspserver: dict = lserver.NewLspServer(server.name, server.path, - args, server.syncInit, - initializationOptions, - server.workspaceConfig, - server.rootSearch, - server.runIfSearch, - server.runUnlessSearch, - customNotificationHandlers, - customRequestHandlers, - ProcessDiagHandler, - features, server.debug) + var lspserver: dict = lserver.NewLspServer(server) var ftypes = server.filetype if ftypes->type() == v:t_string diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 8ccf2f5..03d89bd 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -135,6 +135,11 @@ def ServerInitReply(lspserver: dict, initResult: dict): void exe $'doautocmd User LspServerReady_{lspserver.id}' endif + # set the server debug trace level + if lspserver.traceLevel != 'off' + lspserver.setTrace(lspserver.traceLevel) + endif + # if the outline window is opened, then request the symbols for the current # buffer if bufwinid('LSP-Outline') != -1 @@ -1709,27 +1714,18 @@ def GetUniqueServerId(): number return UniqueServerIdCounter enddef -export def NewLspServer(name_arg: string, path_arg: string, args: list, - isSync: bool, initializationOptions: any, - workspaceConfig: dict, - rootSearchFiles: list, - runIfSearchFiles: list, - runUnlessSearchFiles: list, - customNotificationHandlers: dict, - customRequestHandlers: dict, - ProcessDiagHandler: func, - features: dict, debug_arg: bool): dict +export def NewLspServer(serverParams: dict): dict var lspserver: dict = { id: GetUniqueServerId(), - name: name_arg, - path: path_arg, - args: args, - syncInit: isSync, - initializationOptions: initializationOptions, - customNotificationHandlers: customNotificationHandlers, - customRequestHandlers: customRequestHandlers, - processDiagHandler: ProcessDiagHandler, - features: features, + name: serverParams.name, + path: serverParams.path, + args: serverParams.args->deepcopy(), + syncInit: serverParams.syncInit, + initializationOptions: serverParams.initializationOptions->deepcopy(), + customNotificationHandlers: serverParams.customNotificationHandlers->deepcopy(), + customRequestHandlers: serverParams.customRequestHandlers->deepcopy(), + processDiagHandler: serverParams.processDiagHandler, + features: serverParams.features->deepcopy(), running: false, ready: false, job: v:none, @@ -1737,9 +1733,9 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list, nextID: 1, caps: {}, requests: {}, - rootSearchFiles: rootSearchFiles, - runIfSearchFiles: runIfSearchFiles, - runUnlessSearchFiles: runUnlessSearchFiles, + rootSearchFiles: serverParams.rootSearch->deepcopy(), + runIfSearchFiles: serverParams.runIfSearch->deepcopy(), + runUnlessSearchFiles: serverParams.runUnlessSearch->deepcopy(), omniCompletePending: false, completionTriggerChars: [], signaturePopup: -1, @@ -1751,9 +1747,10 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list, peekSymbolFilePopup: -1, callHierarchyType: '', selection: {}, - workspaceConfig: workspaceConfig, + workspaceConfig: serverParams.workspaceConfig->deepcopy(), messages: [], - debug: debug_arg + debug: serverParams.debug, + traceLevel: serverParams.traceLevel } lspserver.logfile = $'lsp-{lspserver.name}.log' lspserver.errfile = $'lsp-{lspserver.name}.err' diff --git a/doc/lsp.txt b/doc/lsp.txt index 7bee0a0..6c8b47f 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -384,6 +384,10 @@ Additionally the following configurations can be made: debugging a language server. By default the messages are not logged. See |lsp-debug| for more information. + *lsp-cfg-traceLevel* + traceLevel (Optional) set the debug trace level for this language + server.  Supported values are: "off", "debug" and + "verbose". By default this is seto "off". The language servers are added using the LspAddServer() function. This function accepts a list of language servers with the above information. -- 2.48.1