From 4fc073b53b89931418b22b22b4a214315ebb85da Mon Sep 17 00:00:00 2001 From: Andreas Louv Date: Fri, 14 Apr 2023 23:07:54 +0200 Subject: [PATCH] Make it possible to disable langauge server features --- autoload/lsp/buffer.vim | 45 ++++++++++++---------- doc/lsp.txt | 84 ++++++++++++++++++++++++++--------------- 2 files changed, 80 insertions(+), 49 deletions(-) diff --git a/autoload/lsp/buffer.vim b/autoload/lsp/buffer.vim index 5e8a83d..c34f9a9 100644 --- a/autoload/lsp/buffer.vim +++ b/autoload/lsp/buffer.vim @@ -30,6 +30,23 @@ export def BufLspServerRemove(bnr: number, lspserver: dict) 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 @@ -45,23 +62,6 @@ export def BufLspServerGet(bnr: number, domain: string = null_string): dict 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 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 diff --git a/doc/lsp.txt b/doc/lsp.txt index c06181a..203f2e4 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -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: -- 2.50.0