]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Make it possible to disable langauge server features
authorAndreas Louv <andreas@louv.dk>
Fri, 14 Apr 2023 21:07:54 +0000 (23:07 +0200)
committerAndreas Louv <andreas@louv.dk>
Sat, 15 Apr 2023 05:47:04 +0000 (07:47 +0200)
autoload/lsp/buffer.vim
doc/lsp.txt

index 5e8a83d1479791bed3d01d1adce3639c00550fad..c34f9a929d99c6b097e26032defc2b914d2fe5c9 100644 (file)
@@ -30,6 +30,23 @@ export def BufLspServerRemove(bnr: number, lspserver: dict<any>)
   endif
 enddef
 
+var SupportedCheckFns = {
+  codeAction: (lspserver) => lspserver.isCodeActionProvider,
+  codeLens: (lspserver) => lspserver.isCodeLensProvider,
+  completion: (lspserver) => lspserver.isCompletionProvider,
+  declaration: (lspserver) => lspserver.isDeclarationProvider,
+  definition: (lspserver) => lspserver.isDefinitionProvider,
+  documentFormatting: (lspserver) => lspserver.isDocumentFormattingProvider,
+  documentHighlight: (lspserver) => lspserver.isDocumentHighlightProvider,
+  foldingRange: (lspserver) => lspserver.isFoldingRangeProvider,
+  hover: (lspserver) => lspserver.isHoverProvider,
+  implementation: (lspserver) => lspserver.isImplementationProvider,
+  references: (lspserver) => lspserver.isReferencesProvider,
+  rename: (lspserver) => lspserver.isRenameProvider,
+  selectionRange: (lspserver) => lspserver.isSelectionRangeProvider,
+  typeDefinition: (lspserver) => lspserver.isTypeDefinitionProvider,
+}
+
 # Returns the LSP server for the buffer 'bnr' and optionally 'domain'.
 # Returns an empty dict if the server is not found.
 export def BufLspServerGet(bnr: number, domain: string = null_string): dict<any>
@@ -45,23 +62,6 @@ export def BufLspServerGet(bnr: number, domain: string = null_string): dict<any>
     return bufnrToServers[bnr][0]
   endif
 
-  var SupportedCheckFns = {
-    'completion': (lspserver) => lspserver.isCompletionProvider,
-    'definition': (lspserver) => lspserver.isDefinitionProvider,
-    'declaration': (lspserver) => lspserver.isDeclarationProvider,
-    'typeDefinition': (lspserver) => lspserver.isTypeDefinitionProvider,
-    'implementation': (lspserver) => lspserver.isImplementationProvider,
-    'hover': (lspserver) => lspserver.isHoverProvider,
-    'references': (lspserver) => lspserver.isReferencesProvider,
-    'documentHighlight': (lspserver) => lspserver.isDocumentHighlightProvider,
-    'documentFormatting': (lspserver) => lspserver.isDocumentFormattingProvider,
-    'rename': (lspserver) => lspserver.isRenameProvider,
-    'codeAction': (lspserver) => lspserver.isCodeActionProvider,
-    'codeLens': (lspserver) => lspserver.isCodeLensProvider,
-    'selectionRange': (lspserver) => lspserver.isSelectionRangeProvider,
-    'foldingRange': (lspserver) => lspserver.isFoldingRangeProvider,
-  }
-
   if !SupportedCheckFns->has_key(domain)
     # If this happns it is a programming error, and should be fixed in the source code
     :throw $'Error: ''{domain}'' is not a valid domain'
@@ -91,8 +91,15 @@ export def BufLspServerGet(bnr: number, domain: string = null_string): dict<any>
     endif
   endfor
 
-  # Return the first LSP server that supports 'domain'
-  return possibleLSPs[0]
+  # Return the first LSP server that supports 'domain' and doesn't have it
+  # disabled
+  for lspserver in possibleLSPs
+    if !lspserver.features->has_key(domain)
+      return lspserver
+    endif
+  endfor
+
+  return {}
 enddef
 
 # Returns the LSP server for the buffer 'bnr' and with ID 'id'. Returns an empty
index c06181a88c91f809a80d3af5dcf06cba1b2851cc..203f2e4fb37ed24154a2f807fbe81a5a90455219 100644 (file)
@@ -302,8 +302,8 @@ Aditionally the following configurations can be made:
                                        *lsp-cfg-features*
        features
                        (Optional) toggle which features should be enabled for a
-                       given langauge server. See |lsp-multiple-servers| for
-                       more information.
+                       given language server. See |lsp-multiple-servers| and
+                       |lsp-features| for more information.
                                                *lsp-cfg-omnicompl*
        omnicompl       (Optional) a boolean value that enables (true)
                        or disables (false) omni-completion for this file
@@ -1332,10 +1332,11 @@ It's possible to run multiple language servers for a given buffer.
 
 By default the language server defined first will be used for as much as it
 supports, then the next and so on. With the exception that diagnostics from all
-running language servers will be joined together. This means that you can define
-a language server that only supports a subset of features at first and then
-define the general purpose language server after it: >
+running language servers will be combined.
 
+This means that you can define a language server that only supports a subset of
+features at first and then define the general purpose language server after it:
+>
        vim9script
 
        g:LspAddServer([
@@ -1361,32 +1362,18 @@ define the general purpose language server after it: >
                }
        ])
 <
-By proving the configuration |lsp-cfg-features| it's possible specify which
-servers should be used for a given method.  The following flags are supported: >
-
-       #{
-               completion: true,
-               definition: true,
-               declaration: true,
-               typeDefinition: true,
-               implementation: true,
-               hover: true,
-               references: true,
-               documentHighlight: true,
-               documentFormatting: true,
-               rename: true,
-               codeAction: true,
-               codeLens: true,
-               selectionRange: true,
-               foldingRange:  true
-       }
-<
-As shown above the order of when the language servers are being defined is taken
-into account for a given method.  However sometimes the language server that you
-want to use for formatting also reports that it supports other features, in such
-a case you can change the order of language servers, and specify that a given
-language server should be used for a given method.
+As shown in the example above the order of when the language servers are being
+defined is taken into account for a given method.  However sometimes the
+language server that you want to use for formatting also reports that it
+supports other features. In such a case you can do one of two things:
+
+1. change the order of language servers, and specify that a given language
+server should be used for a given method.
+
+2. set the unwanted features to |v:false| in the features |Dictionary| >
 
+       features: { 'codeAction': v:false }
+<
 For example, if you want to use the efm-langserver for formatting, but the
 typescript-language-server for everything else: >
 
@@ -1411,5 +1398,42 @@ typescript-language-server for everything else: >
                }
        ])
 <
+==============================================================================
+17. Language Server Features                   *lsp-features*
+
+By providing the configuration |lsp-cfg-features| it's possible to specify which
+servers should be used for a given method.  The following feature flags are
+supported: See |lsp-multiple-servers| for examples.
+
+                                               *lsp-features-codeAction*
+codeAction                     Used by |:LspCodeAction|
+                                               *lsp-features-codeLens*
+codeLens                       Used by |:LspCodeLens|
+                                               *lsp-features-completion*
+completion                     Used by 24/7 Completion and 'omnifunc'
+                                               *lsp-features-declaration*
+declaration                    Used by |:LspGotoDeclaration|, and
+                               |:LspPeekDeclaration|
+                                               *lsp-features-definition*
+definition                     Used by |:LspGotoDefinition|, and
+                               |:LspPeekDefinition|
+                                               *lsp-features-documentFormatting*
+documentFormatting             Used by |:LspFormat|, and 'formatexpr'
+                                               *lsp-features-documentHighlight*
+documentHighlight              Used by |:LspHighlight|, and |:LspHighlightClear|
+                                               *lsp-features-foldingRange*
+foldingRange                   Used by |:LspFold|
+                                               *lsp-features-hover*
+hover                          Used by |:LspHover|
+                                               *lsp-features-implementation*
+implementation                 Used by |:LspGotoImpl|, and |:LspPeekImpl|
+                                               *lsp-features-references*
+references                     Used by |:LspShowReferences|
+                                               *lsp-features-rename*
+rename                         Used by |:LspRename|
+                                               *lsp-features-selectionRange*
+selectionRange                 Used by |:LspSelectionExpand|, and |:LspSelectionShrink|
+                                               *lsp-features-typeDefinition*
+typeDefinition                 Used by |:LspGotoTypeDef|, and |:LspPeekTypeDef|
 
 vim:tw=78:ts=8:noet:ft=help:norl: