autoload/lsp/lsp.vim | 36 ++++++++++++------------------------ autoload/lsp/lspserver.vim | 2 ++ doc/lsp.txt | 22 +++++++++++++++------- diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 303e30ce51074be9e7f209413150404ac2fea6dc..84534a0202afc9b76b504e3324afd28982364ab7 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -51,35 +51,18 @@ if !ftypeServerMap->has_key(ftype) return [] endif - var lspservers = ftypeServerMap[ftype] - - # All the langauge servers with the same score are being used - var bestMatches: list> = [] - var bestScore: number = -2 - var bufDir = bnr->bufname()->fnamemodify(':p:h') - for lspserver in lspservers - var score: number = 0 - - if !lspserver.rootSearchFiles->empty() - # The score is calculated by how deep the workspace root dir is, the - # deeper the better. - var path = util.FindNearestRootDir(bufDir, lspserver.rootSearchFiles) - # subtract one to make servers with a non matching 'rootSearch' rank below - # servers without a 'rootSearch'. - score = path->strcharlen() - 1 + return ftypeServerMap[ftype]->filter((key, lspserver) => { + if lspserver.runIfSearchFiles->empty() + return true endif - if score > bestScore - bestMatches = [lspserver] - bestScore = score - elseif score == bestScore - bestMatches->add(lspserver) - endif - endfor + var path = util.FindNearestRootDir(bufDir, lspserver.runIfSearchFiles) - return bestMatches + # Run the server if the path is found + return !path->empty() + }) enddef # Add a LSP server for a filetype @@ -635,11 +618,16 @@ if !server->has_key('rootSearch') || server.rootSearch->type() != v:t_list server.rootSearch = [] endif + if !server->has_key('runIfSearch') || server.runIfSearch->type() != v:t_list + server.runIfSearch = [] + endif + var lspserver: dict = lserver.NewLspServer(server.name, server.path, args, server.syncInit, initializationOptions, server.workspaceConfig, server.rootSearch, + server.runIfSearch, customNotificationHandlers, features, server.debug) diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 69baa9c2029534842e1f664c50a18a7d0b1cabf4..02e8d9ba1c7f971c06519097c6edd9b23ad33da8 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -1475,6 +1475,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list, isSync: bool, initializationOptions: any, workspaceConfig: dict, rootSearchFiles: list, + runIfSearchFiles: list, customNotificationHandlers: dict, features: dict, debug_arg: bool): dict var lspserver: dict = { @@ -1494,6 +1495,7 @@ nextID: 1, caps: {}, requests: {}, rootSearchFiles: rootSearchFiles, + runIfSearchFiles: runIfSearchFiles, omniCompletePending: false, completionTriggerChars: [], signaturePopup: -1, diff --git a/doc/lsp.txt b/doc/lsp.txt index 828bfd468c8a1fe6ffe34d63deb1c1df7c12395e..05c4d27f506b91e3c540f6dd1e4e5a1e0484a540 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -265,18 +265,26 @@ multiple directories are found, then the directory closest to the directory of the current buffer is used as the workspace root. - This option is also used to decide which server to run - when multiple servers are defined for a filetype. The - servers that share the longest found workspace root will - be selected as the relevant language servers for a given - file. - If this parameter is not specified or the files are not found, then the current working directory is used as the workspace root for decendent files, for any other files the parent directory of the file is used. -Aditionally the following configurations can be made: + *lsp-cfg-runIfSearch* + runIfSearch (Optional) a List of file and directory names used to + determinate if a server should run or not. The directory + names in "runIfSearch" must end in "/" or "\". Each + file and directory name in "runIfSearch" is searched + upwards in all the parent directories. Exactly like + |lsp-cfg-rootSearch|. + + 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. + +Additionally the following configurations can be made: *lsp-cfg-customNotificationHandlers* customNotificationHandlers