Added lsp on_attach function

master
Jef Roosens 2021-10-14 14:41:19 +02:00
parent b0e53f9d09
commit 0fc639f10f
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
1 changed files with 32 additions and 3 deletions

View File

@ -109,17 +109,46 @@ g.tagbar_autoclose = 1
nmap("tr", ":TagbarToggle<CR>") nmap("tr", ":TagbarToggle<CR>")
-- neovim/neovim-lspconfig -- neovim/neovim-lspconfig
local function on_attach(client, bufnr)
local opts = {
silent = true,
noremap = true,
}
local function buf_nmap(mapping, cmd) vim.api.nvim_buf_set_keymap(bufnr, "n", mapping, cmd, opts) end
-- Jump to definition
buf_nmap("gd", "<Cmd>lua vim.lsp.buf.definition()<CR>")
-- Format current buffer on write
vim.api.nvim_command([[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]])
-- Show diagnostics for current line
buf_nmap("<leader>dd", "<Cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>")
-- Jump between diagnostic messages
buf_nmap("<leader>dj", "<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>")
buf_nmap("<leader>dk", "<Cmd>lua vim.lsp.diagnostic.goto_previous()<CR>")
-- Rename symbol under cursor
buf_nmap("<leader>dr", "<Cmd>lua vim.lsp.buf.rename()<CR>")
-- Show hover info
buf_nmap("<leader>df", "<Cmd>lua vim.lsp.buf.hover()<CR>")
end
-- Comes with clang -- Comes with clang
require'lspconfig'.clangd.setup{} require'lspconfig'.clangd.setup{on_attach = on_attach}
-- NPM: dockerfile-language-server-nodejs -- NPM: dockerfile-language-server-nodejs
require'lspconfig'.dockerls.setup{} require'lspconfig'.dockerls.setup{}
-- Pacman: haskell-language-server -- Pacman: haskell-language-server
-- AUR: haskell-language-server-bin -- AUR: haskell-language-server-bin
-- GH: https://github.com/haskell/haskell-language-server -- GH: https://github.com/haskell/haskell-language-server
require'lspconfig'.hls.setup{} require'lspconfig'.hls.setup{
on_attach = on_attach,
settings = {
haskell = {
formattingProvider = "stylish-haskell"
}
}
}
-- Pacman: rust-analyzer -- Pacman: rust-analyzer
-- GH: https://github.com/rust-analyzer/rust-analyzer -- GH: https://github.com/rust-analyzer/rust-analyzer
require'lspconfig'.rust_analyzer.setup{} require'lspconfig'.rust_analyzer.setup{on_attach = on_attach}
-- Installed using R shell: -- Installed using R shell:
-- `install.packages('languageserver')` -- `install.packages('languageserver')`
-- GH: https://github.com/REditorSupport/languageserver -- GH: https://github.com/REditorSupport/languageserver