dotfiles/dot_config/nvim/lua/lsp.lua

181 lines
4.0 KiB
Lua
Raw Normal View History

2023-10-17 19:22:48 +02:00
-- Load default lsp-zero keymaps
2023-10-24 11:46:00 +02:00
local lsp_zero = require("lsp-zero")
local telescope = require("telescope.builtin")
2024-01-08 23:56:35 +01:00
-- Install LSP servers automatically through Mason
2023-10-24 11:46:00 +02:00
require("mason").setup()
2024-01-08 23:56:35 +01:00
require("mason-lspconfig").setup({ automatic_installation = true })
2023-10-17 19:22:48 +02:00
lsp_zero.on_attach(function(_, bufnr)
2023-10-29 10:08:50 +01:00
-- see :help lsp-zero-keybindings to learn the available actions
lsp_zero.default_keymaps({ buffer = bufnr })
2023-10-17 19:22:48 +02:00
2023-10-29 10:08:50 +01:00
local opts = { buffer = bufnr, remap = false }
vim.keymap.set("n", "<leader>vc", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<leader>vr", vim.lsp.buf.rename, opts)
2023-10-17 19:22:48 +02:00
2023-10-29 10:08:50 +01:00
vim.keymap.set("n", "<leader>en", vim.diagnostic.goto_next, opts)
vim.keymap.set("n", "<leader>ep", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "<leader>ei", vim.diagnostic.open_float, opts)
vim.keymap.set("i", "<C-h>", vim.lsp.buf.signature_help, opts)
2023-10-24 11:46:00 +02:00
2023-10-29 10:08:50 +01:00
vim.keymap.set("n", "gr", function()
telescope.lsp_references({
include_declaration = false,
show_line = false,
fname_width = 64,
})
end, opts)
vim.keymap.set("n", "gd", function()
telescope.lsp_definitions({
show_line = false,
fname_width = 64,
})
end, opts)
vim.keymap.set("n", "gi", function()
telescope.lsp_implementations({
show_line = false,
fname_width = 64,
})
end, opts)
2023-10-17 19:22:48 +02:00
end)
lsp_zero.format_on_save({
2023-10-29 10:08:50 +01:00
format_opts = {
async = true,
timeout_ms = 10000,
},
servers = {
["efm"] = { "javascript", "typescript", "lua" },
["gopls"] = { "go" },
2023-12-07 09:27:24 +01:00
["terraformls"] = { "terraform" },
["yamlls"] = { "yaml" },
["jsonls"] = { "json" },
2023-10-29 10:08:50 +01:00
},
2023-10-17 19:22:48 +02:00
})
-- Setup LSP servers
2023-10-24 11:46:00 +02:00
local lspconfig = require("lspconfig")
2023-10-17 19:22:48 +02:00
-- go
2024-01-08 23:56:35 +01:00
lspconfig.golangci_lint_ls.setup({
root_dir = require("lspconfig.util").root_pattern(
"go.mod",
"go.work",
".golangci.yml",
".golangci.yaml",
".golangci.toml",
".golangci.json",
".git"
),
})
2023-12-07 09:27:24 +01:00
lspconfig.gopls.setup({
settings = {
gopls = {
gofumpt = true,
},
},
})
2024-01-08 23:56:35 +01:00
-- rust
lspconfig.rust_analyzer.setup({
settings = {
["rust-analyzer"] = {
diagnostics = {
enable = false,
},
},
},
})
2023-10-17 19:22:48 +02:00
-- lua
2023-10-24 11:46:00 +02:00
lspconfig.lua_ls.setup(lsp_zero.nvim_lua_ls())
2023-10-29 10:08:50 +01:00
-- protobuf
lspconfig.bufls.setup({})
2023-10-17 19:22:48 +02:00
-- python
2023-11-10 13:14:58 +01:00
lspconfig.pylsp.setup({
settings = {
pylsp = {
plugins = {
pycodestyle = {
maxLineLength = 100,
},
},
},
},
})
2023-10-29 10:08:50 +01:00
lspconfig.pyright.setup({})
2023-10-17 19:22:48 +02:00
-- typescript
2023-10-26 14:43:34 +02:00
lspconfig.eslint.setup({})
2023-10-24 11:46:00 +02:00
lspconfig.tsserver.setup({})
2023-11-20 19:17:58 +01:00
lspconfig.prismals.setup({})
2023-11-20 19:22:35 +01:00
lspconfig.graphql.setup({})
2023-10-29 10:08:50 +01:00
-- efm
local stylua = {
formatCommand = "stylua -",
formatStdin = true,
}
2023-10-24 14:20:33 +02:00
local prettier = {
2023-10-29 10:08:50 +01:00
formatCommand = 'prettierd "${INPUT}"',
formatStdin = true,
env = {
string.format(
"PRETTIERD_DEFAULT_CONFIG=%s",
vim.fn.expand("~/.config/nvim/utils/linter-config/.prettierrc.json")
),
},
2023-10-24 14:20:33 +02:00
}
2023-10-24 11:46:00 +02:00
local languages = {
2023-10-29 10:08:50 +01:00
lua = { stylua },
typescript = { prettier },
javascript = { prettier },
json = { prettier },
markdown = { prettier },
2023-10-24 11:46:00 +02:00
}
lspconfig.efm.setup({
2023-10-29 10:08:50 +01:00
-- capabilities = capabilities,
cmd = { "/home/pavle/.local/share/nvim/mason/bin/efm-langserver" },
-- on_attach = on_attach,
init_options = { documentFormatting = true },
root_dir = vim.loop.cwd,
filetypes = vim.tbl_keys(languages),
settings = {
rootMarkers = { ".git/", ".prettierignore" },
lintDebounce = 100,
logLevel = 5,
logFile = "/home/pavle/efm.log",
languages = languages,
},
single_file_support = true,
2023-10-24 11:46:00 +02:00
})
2023-10-29 10:08:50 +01:00
-- terraform
2023-10-17 19:22:48 +02:00
lspconfig.terraformls.setup({})
2023-11-23 20:10:51 +01:00
-- json & yaml
2023-10-17 19:22:48 +02:00
lspconfig.jsonls.setup({})
2023-11-23 20:10:51 +01:00
lspconfig.yamlls.setup({})
2024-03-07 13:10:43 +01:00
-- c/c++
lspconfig.ccls.setup({
init_options = {
compilationDatabaseDirectory = "build",
2024-03-18 15:49:34 +01:00
-- compilationDatabaseDirectory = ".",
2024-03-07 13:10:43 +01:00
index = {
threads = 0,
},
clang = {
excludeArgs = { "-frounding-math" },
},
},
})
2024-03-18 15:49:34 +01:00
2023-10-17 19:22:48 +02:00
-- Customize keymaps
2023-10-24 11:46:00 +02:00
local cmp = require("cmp")
2023-10-17 19:22:48 +02:00
cmp.setup({
2023-10-29 10:08:50 +01:00
mapping = cmp.mapping.preset.insert({
-- `Enter` key to confirm completion
["<CR>"] = cmp.mapping.confirm({ select = false }),
2023-10-17 19:22:48 +02:00
2023-10-29 10:08:50 +01:00
["<C-Space>"] = cmp.mapping.complete(),
2023-10-17 19:22:48 +02:00
2023-10-29 10:08:50 +01:00
-- Scroll up and down in the completion documentation
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
}),
2023-10-17 19:22:48 +02:00
})