]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add "runUnlessSearch" which is the opposite of "runIfSearch"
authorAndreas Louv <andreas@louv.dk>
Sat, 15 Apr 2023 18:02:48 +0000 (20:02 +0200)
committerAndreas Louv <andreas@louv.dk>
Sat, 15 Apr 2023 18:02:49 +0000 (20:02 +0200)
autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
doc/lsp.txt

index 84534a0202afc9b76b504e3324afd28982364ab7..7c86f8f43486d7556f7b8ee5d9e43b24b6854c86 100644 (file)
@@ -54,14 +54,26 @@ def LspGetServers(bnr: number, ftype: string): list<dict<any>>
   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<dict<any>>)
       server.runIfSearch = []
     endif
 
+    if !server->has_key('runUnlessSearch') || server.runUnlessSearch->type() != v:t_list
+      server.runUnlessSearch = []
+    endif
+
     var lspserver: dict<any> = lserver.NewLspServer(server.name, server.path,
                                                    args, server.syncInit,
                                                    initializationOptions,
                                                    server.workspaceConfig,
                                                    server.rootSearch,
                                                    server.runIfSearch,
+                                                   server.runUnlessSearch,
                                                    customNotificationHandlers,
                                                    features, server.debug)
 
index 02e8d9ba1c7f971c06519097c6edd9b23ad33da8..31cb666f2ce97e24426aa7fc7022551ba5112716 100644 (file)
@@ -1476,6 +1476,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list<string>,
                        workspaceConfig: dict<any>,
                        rootSearchFiles: list<any>,
                        runIfSearchFiles: list<any>,
+                       runUnlessSearchFiles: list<any>,
                        customNotificationHandlers: dict<func>,
                        features: dict<bool>, debug_arg: bool): dict<any>
   var lspserver: dict<any> = {
@@ -1496,6 +1497,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list<string>,
     requests: {},
     rootSearchFiles: rootSearchFiles,
     runIfSearchFiles: runIfSearchFiles,
+    runUnlessSearchFiles: runUnlessSearchFiles,
     omniCompletePending: false,
     completionTriggerChars: [],
     signaturePopup: -1,
index 05c4d27f506b91e3c540f6dd1e4e5a1e0484a540..c472668eee0e96b9806331b3ac0ccb09b2b6ef25 100644 (file)
@@ -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: