autoload/lsp/lsp.vim | 27 ++++++++++++++++++++++----- autoload/lsp/lspserver.vim | 2 ++ doc/lsp.txt | 6 +++++- diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 84534a0202afc9b76b504e3324afd28982364ab7..7c86f8f43486d7556f7b8ee5d9e43b24b6854c86 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -54,14 +54,26 @@ 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 @@ 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 + 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 02e8d9ba1c7f971c06519097c6edd9b23ad33da8..31cb666f2ce97e24426aa7fc7022551ba5112716 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -1476,6 +1476,7 @@ isSync: bool, initializationOptions: any, workspaceConfig: dict, rootSearchFiles: list, runIfSearchFiles: list, + runUnlessSearchFiles: list, customNotificationHandlers: dict, features: dict, debug_arg: bool): dict var lspserver: dict = { @@ -1496,6 +1497,7 @@ caps: {}, requests: {}, rootSearchFiles: rootSearchFiles, runIfSearchFiles: runIfSearchFiles, + runUnlessSearchFiles: runUnlessSearchFiles, omniCompletePending: false, completionTriggerChars: [], signaturePopup: -1, diff --git a/doc/lsp.txt b/doc/lsp.txt index 05c4d27f506b91e3c540f6dd1e4e5a1e0484a540..c472668eee0e96b9806331b3ac0ccb09b2b6ef25 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -282,7 +282,11 @@ If a file or directory is found then the server will be 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: