76 lines
3.0 KiB
Lua
76 lines
3.0 KiB
Lua
-- 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.format()]])
|
|
-- Show diagnostics for current line
|
|
buf_nmap("<leader>dd", "<Cmd>lua vim.diagnostic.open_float()<CR>")
|
|
-- Jump between diagnostic messages
|
|
buf_nmap("<leader>dj", "<Cmd>lua vim.diagnostic.goto_next()<CR>")
|
|
buf_nmap("<leader>dk", "<Cmd>lua vim.diagnostic.goto_prev()<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>")
|
|
buf_nmap("<leader>du", "<Cmd>lua vim.lsp.buf.references()<CR>")
|
|
buf_nmap("<leader>da", "<Cmd>lua vim.lsp.buf.code_action()<CR>")
|
|
end
|
|
|
|
-- For cmp autocomplete
|
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
|
|
|
-- Comes with clang
|
|
require'lspconfig'.clangd.setup{on_attach = on_attach, capabilities = capabilities}
|
|
-- NPM: dockerfile-language-server-nodejs
|
|
require'lspconfig'.dockerls.setup{capabilities = capabilities}
|
|
-- Pacman: haskell-language-server
|
|
-- AUR: haskell-language-server-bin
|
|
-- GH: https://github.com/haskell/haskell-language-server
|
|
require'lspconfig'.hls.setup{
|
|
on_attach = on_attach,
|
|
settings = {
|
|
haskell = {
|
|
formattingProvider = "stylish-haskell"
|
|
}
|
|
},
|
|
capabilities = capabilities
|
|
}
|
|
-- Pacman: vieter-vls (requires my Vieter repository)
|
|
-- GH: https://github.com/vlang/vls
|
|
-- require'lspconfig'.vls.setup{
|
|
-- cmd = {'vls'},
|
|
-- filetypes = {'v'},
|
|
-- on_attach = on_attach
|
|
-- }
|
|
-- Pacman: rust-analyzer
|
|
-- GH: https://github.com/rust-analyzer/rust-analyzer
|
|
require'lspconfig'.rust_analyzer.setup{on_attach = on_attach, capabilities = capabilities}
|
|
-- Installed using R shell:
|
|
-- `install.packages('languageserver')`
|
|
-- GH: https://github.com/REditorSupport/languageserver
|
|
require'lspconfig'.r_language_server.setup{capabilities = capabilities}
|
|
-- Installed using Go CLI:
|
|
-- go install github.com/nametake/golangci-lint-langserver@latest
|
|
-- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
|
require'lspconfig'.gopls.setup{on_attach = on_attach, capabilities = capabilities}
|
|
|
|
require'lspconfig'.texlab.setup{on_attach = on_attach, capabilities = capabilities}
|
|
|
|
-- Fix that stops rust-analyzer interrupting typing when a request is cancelled
|
|
for _, method in ipairs({ 'textDocument/diagnostic', 'workspace/diagnostic' }) do
|
|
local default_diagnostic_handler = vim.lsp.handlers[method]
|
|
vim.lsp.handlers[method] = function(err, result, context, config)
|
|
if err ~= nil and err.code == -32802 then
|
|
return
|
|
end
|
|
return default_diagnostic_handler(err, result, context, config)
|
|
end
|
|
end
|