From f2008af7f7ac68234715b0545c26f5bcd86ceea9 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Sat, 4 Nov 2023 16:45:29 +1100 Subject: [PATCH] Only use LSP features if the server supports them --- dot-config/vim/lsp.vim | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/dot-config/vim/lsp.vim b/dot-config/vim/lsp.vim index cee3e52..bf07868 100644 --- a/dot-config/vim/lsp.vim +++ b/dot-config/vim/lsp.vim @@ -162,16 +162,39 @@ def ListMissingServers(argLead: string, cmdLine: string, cursorPos: number): lis return MissingServers()->mapnew((_, server): string => server.name) enddef +def ServerHas(feature: string): bool + return lsp#buffer#CurbufGetServer(feature) != {} +enddef + def LspBufferSettings(): void - setlocal formatexpr=lsp#lsp#FormatExpr() - setlocal keywordprg=:LspHover - nnoremap gD LspGotoDeclaration - nnoremap gd LspGotoDefinition - nnoremap gi LspGotoImpl - nnoremap LspShowSignature - nnoremap gr LspShowReferences - xnoremap e LspSelectionExpand - xnoremap s LspSelectionShrink + if ServerHas('documentFormatting') + setlocal formatexpr=lsp#lsp#FormatExpr() + endif + + if ServerHas('hover') + setlocal keywordprg=:LspHover + endif + + if ServerHas('declaration') + nnoremap gD LspGotoDeclaration + endif + + if ServerHas('definition') + nnoremap gd LspGotoDefinition + endif + + if ServerHas('implementation') + nnoremap gi LspGotoImpl + endif + + if ServerHas('references') + nnoremap gr LspShowReferences + endif + + if ServerHas('selectionRange') + xnoremap e LspSelectionExpand + xnoremap s LspSelectionShrink + endif enddef export def Configure(): void