Only use LSP features if the server supports them

This commit is contained in:
Danielle McLean 2023-11-04 16:45:29 +11:00
parent e27b22b51f
commit f2008af7f7
Signed by: 00dani
GPG key ID: 52C059C3B22A753E

View file

@ -162,16 +162,39 @@ def ListMissingServers(argLead: string, cmdLine: string, cursorPos: number): lis
return MissingServers()->mapnew((_, server): string => server.name) return MissingServers()->mapnew((_, server): string => server.name)
enddef enddef
def ServerHas(feature: string): bool
return lsp#buffer#CurbufGetServer(feature) != {}
enddef
def LspBufferSettings(): void def LspBufferSettings(): void
setlocal formatexpr=lsp#lsp#FormatExpr() if ServerHas('documentFormatting')
setlocal keywordprg=:LspHover setlocal formatexpr=lsp#lsp#FormatExpr()
nnoremap <buffer> gD <Cmd>LspGotoDeclaration<CR> endif
nnoremap <buffer> gd <Cmd>LspGotoDefinition<CR>
nnoremap <buffer> gi <Cmd>LspGotoImpl<CR> if ServerHas('hover')
nnoremap <buffer> <C-k> <Cmd>LspShowSignature<CR> setlocal keywordprg=:LspHover
nnoremap <buffer> gr <Cmd>LspShowReferences<CR> endif
xnoremap <buffer> <silent> <Leader>e <Cmd>LspSelectionExpand<CR>
xnoremap <buffer> <silent> <Leader>s <Cmd>LspSelectionShrink<CR> if ServerHas('declaration')
nnoremap <buffer> gD <Cmd>LspGotoDeclaration<CR>
endif
if ServerHas('definition')
nnoremap <buffer> gd <Cmd>LspGotoDefinition<CR>
endif
if ServerHas('implementation')
nnoremap <buffer> gi <Cmd>LspGotoImpl<CR>
endif
if ServerHas('references')
nnoremap <buffer> gr <Cmd>LspShowReferences<CR>
endif
if ServerHas('selectionRange')
xnoremap <buffer> <silent> <Leader>e <Cmd>LspSelectionExpand<CR>
xnoremap <buffer> <silent> <Leader>s <Cmd>LspSelectionShrink<CR>
endif
enddef enddef
export def Configure(): void export def Configure(): void