1
Fork 0
satellite/dotfiles/neovim/lua/my/plugins/lspconfig.lua

100 lines
3 KiB
Lua
Raw Normal View History

2022-01-31 21:41:13 +01:00
local M = {}
2022-03-09 19:44:21 +01:00
function M.on_attach(client, bufnr)
2022-07-19 20:19:36 +02:00
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
2022-01-31 21:41:13 +01:00
2022-07-19 20:19:36 +02:00
if client.server_capabilities.documentFormattingProvider then
vim.api.nvim_create_autocmd("BufWritePre", {
group = vim.api.nvim_create_augroup("LspFormatting", {}),
2022-10-09 03:28:51 +02:00
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ async = false })
2022-09-18 01:00:32 +02:00
end
})
2022-07-19 20:19:36 +02:00
end
2022-10-09 03:28:51 +02:00
local opts = function(desc)
return { noremap = true, silent = true, desc = desc }
end
2022-07-19 20:19:36 +02:00
-- Go to declaration / definition / implementation
2022-10-09 03:28:51 +02:00
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts("Go to declaration"))
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts("Go to definition"))
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts("Go to implementation"))
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts("Go to references"))
2022-07-19 20:19:36 +02:00
-- Hover
2022-10-09 03:28:51 +02:00
vim.keymap.set("n", "J", vim.diagnostic.open_float, opts("Show diagnostic"))
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts("Hover"))
vim.keymap.set("n", "L", vim.lsp.buf.signature_help, opts("Signature help"))
2022-07-19 20:19:36 +02:00
-- Code actions
2022-10-09 03:28:51 +02:00
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts("Rename"))
vim.keymap.set("n", "<leader>c", vim.lsp.buf.code_action, opts("Code actions"))
vim.keymap.set("n", "<leader>f", vim.lsp.buf.format, opts("Format"))
2022-05-10 14:28:36 +02:00
end
2022-02-01 15:18:36 +01:00
-- General server config
2022-12-14 03:20:59 +01:00
---@type lspconfig.options
2022-02-01 15:18:36 +01:00
local servers = {
2022-11-14 01:16:10 +01:00
tsserver = {
on_attach = function(client, bufnr)
-- We handle formatting using null-ls and prettierd
client.server_capabilities.documentFormattingProvider = false
M.on_attach(client, bufnr)
end
},
2022-07-19 20:19:36 +02:00
dhall_lsp_server = {},
purescriptls = {
settings = {
purescript = {
2022-11-14 01:16:10 +01:00
censorWarnings = { "UnusedName", "ShadowedName", "UserDefinedWarning" },
2022-07-19 20:19:36 +02:00
formatter = "purs-tidy"
}
}
},
hls = {
haskell = {
-- set formatter
formattingProvider = "ormolu"
}
},
rnix = {},
cssls = {},
2022-12-14 03:20:59 +01:00
jsonls = {},
rust_analyzer = {},
2022-12-14 03:20:59 +01:00
sumneko_lua = {
cmd = { "lua-language-server", "--logpath=/home/adrielus/.local/share/lua-language-server/log" }
}
2022-02-01 15:18:36 +01:00
}
M.capabilities = require('cmp_nvim_lsp').default_capabilities()
2022-01-31 21:41:13 +01:00
function M.setup()
2022-12-05 01:18:31 +01:00
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover,
{ border = "single" })
vim.lsp.handlers["textDocument/signatureHelp"] =
vim.lsp.with(vim.lsp.handlers.signature_help, { border = "single" })
2022-07-19 20:19:36 +02:00
-- Setup basic language servers
for lsp, details in pairs(servers) do
if details.on_attach == nil then
-- Default setting for on_attach
details.on_attach = M.on_attach
2022-01-31 21:41:13 +01:00
end
2022-07-19 20:19:36 +02:00
require('lspconfig')[lsp].setup {
on_attach = details.on_attach,
settings = details.settings, -- Specific per-language settings
flags = {
debounce_text_changes = 150 -- This will be the default in neovim 0.7+
},
cmd = details.cmd,
capabilities = M.capabilities
2022-07-19 20:19:36 +02:00
}
end
2022-01-31 21:41:13 +01:00
end
2022-02-01 00:06:48 +01:00
return M