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