Only use LSP mappings in buffers that have an LSP attached

This commit is contained in:
Danielle McLean 2023-11-04 16:34:18 +11:00
parent 152dac0e42
commit e27b22b51f
Signed by: 00dani
GPG key ID: 52C059C3B22A753E
2 changed files with 17 additions and 11 deletions

View file

@ -131,13 +131,3 @@ statusline.Init()
# necessary. # necessary.
import "./lsp.vim" import "./lsp.vim"
lsp.Configure() lsp.Configure()
set formatexpr=lsp#lsp#FormatExpr()
set keywordprg=:LspHover
nnoremap gD <Cmd>LspGotoDeclaration<CR>
nnoremap gd <Cmd>LspGotoDefinition<CR>
nnoremap gi <Cmd>LspGotoImpl<CR>
nnoremap <C-k> <Cmd>LspShowSignature<CR>
nnoremap gr <Cmd>LspShowReferences<CR>
xnoremap <silent> <Leader>e <Cmd>LspSelectionExpand<CR>
xnoremap <silent> <Leader>s <Cmd>LspSelectionShrink<CR>

View file

@ -162,7 +162,24 @@ 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 LspBufferSettings(): void
setlocal formatexpr=lsp#lsp#FormatExpr()
setlocal keywordprg=:LspHover
nnoremap <buffer> gD <Cmd>LspGotoDeclaration<CR>
nnoremap <buffer> gd <Cmd>LspGotoDefinition<CR>
nnoremap <buffer> gi <Cmd>LspGotoImpl<CR>
nnoremap <buffer> <C-k> <Cmd>LspShowSignature<CR>
nnoremap <buffer> gr <Cmd>LspShowReferences<CR>
xnoremap <buffer> <silent> <Leader>e <Cmd>LspSelectionExpand<CR>
xnoremap <buffer> <silent> <Leader>s <Cmd>LspSelectionShrink<CR>
enddef
export def Configure(): void export def Configure(): void
augroup dot/vim/lsp.vim
autocmd!
autocmd User LspAttached LspBufferSettings()
augroup END
# We have to use final rather than const because LspAddServer() assumes it can # We have to use final rather than const because LspAddServer() assumes it can
# modify the dicts it gets, rather than making a fresh copy to mess with. # modify the dicts it gets, rather than making a fresh copy to mess with.
final installedServers = InstalledServers() final installedServers = InstalledServers()
@ -173,7 +190,6 @@ export def Configure(): void
const missingCount = len(lspServers) - len(installedServers) const missingCount = len(lspServers) - len(installedServers)
const warn = $'{missingCount} language server{missingCount > 1 ? "s are" : " is"} configured, but not installed. You may want to run :LspInstall.' const warn = $'{missingCount} language server{missingCount > 1 ? "s are" : " is"} configured, but not installed. You may want to run :LspInstall.'
augroup dot/vim/lsp.vim augroup dot/vim/lsp.vim
autocmd!
exe $'autocmd VimEnter * ++once echo {strings.Quote(warn)}' exe $'autocmd VimEnter * ++once echo {strings.Quote(warn)}'
augroup END augroup END
endif endif