From: Andreas Louv Date: Sat, 15 Apr 2023 18:02:48 +0000 (+0200) Subject: Add "runUnlessSearch" which is the opposite of "runIfSearch" X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=39bb0cde57fb44e884d494ffdf45e617af0e1ae2;p=vim-lsp.git Add "runUnlessSearch" which is the opposite of "runIfSearch" --- diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 84534a0..7c86f8f 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -54,14 +54,26 @@ def LspGetServers(bnr: number, ftype: string): list> var bufDir = bnr->bufname()->fnamemodify(':p:h') return ftypeServerMap[ftype]->filter((key, lspserver) => { - if lspserver.runIfSearchFiles->empty() - return true + # Don't run the server if no path is found + if !lspserver.runIfSearchFiles->empty() + var path = util.FindNearestRootDir(bufDir, lspserver.runIfSearchFiles) + + if path->empty() + return false + endif endif - var path = util.FindNearestRootDir(bufDir, lspserver.runIfSearchFiles) + # Don't run the server if a path is found + if !lspserver.runUnlessSearchFiles->empty() + var path = util.FindNearestRootDir(bufDir, lspserver.runUnlessSearchFiles) - # Run the server if the path is found - return !path->empty() + if !path->empty() + return false + endif + endif + + # Run the server + return true }) enddef @@ -622,12 +634,17 @@ export def AddServer(serverList: list>) server.runIfSearch = [] endif + 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, features, server.debug) diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 02e8d9b..31cb666 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -1476,6 +1476,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list, workspaceConfig: dict, rootSearchFiles: list, runIfSearchFiles: list, + runUnlessSearchFiles: list, customNotificationHandlers: dict, features: dict, debug_arg: bool): dict var lspserver: dict = { @@ -1496,6 +1497,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list, requests: {}, rootSearchFiles: rootSearchFiles, runIfSearchFiles: runIfSearchFiles, + runUnlessSearchFiles: runUnlessSearchFiles, omniCompletePending: false, completionTriggerChars: [], signaturePopup: -1, diff --git a/doc/lsp.txt b/doc/lsp.txt index 05c4d27..c472668 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -282,7 +282,11 @@ To add a language server, the following information is needed: started, otherwise it will not. If this parameter is not specified or is an empty list, - then the server will always be started. + then the server will be started unless + |lsp-cfg-runUnlessSearch| prevents it. + + *lsp-cfg-runUnlessSearch* + runUnlessSearch (Optional) Opposite of |lsp-cfg-runIfSearch|. Additionally the following configurations can be made: