2022-05-02 23:35:31 +02:00
|
|
|
-- Author : swytch
|
|
|
|
-- Created : Monday May 2, 2022 21:02:02 CET
|
|
|
|
-- License : GPLv3
|
|
|
|
-- Description : neovim global lsp config file
|
|
|
|
|
|
|
|
|
|
|
|
local lspconfig = require("lspconfig")
|
2022-11-10 20:53:58 +01:00
|
|
|
local mason = require("mason")
|
|
|
|
local mason_lspconfig = require("mason-lspconfig")
|
2022-05-02 23:35:31 +02:00
|
|
|
|
|
|
|
local globals = require("globals")
|
|
|
|
local signs = {
|
|
|
|
Error = globals.sign_error,
|
|
|
|
Warn = globals.sign_warn,
|
|
|
|
Hint = globals.sign_hint,
|
|
|
|
Info = globals.sign_info,
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:21:29 +02:00
|
|
|
for type, icon in pairs(signs) do
|
2022-05-02 23:35:31 +02:00
|
|
|
local hl = "DiagnosticSign" .. type
|
|
|
|
vim.fn.sign_define(hl, {
|
|
|
|
text = icon,
|
|
|
|
texthl = hl,
|
|
|
|
numhl = hl
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.diagnostic.config({
|
|
|
|
update_in_insert = true
|
|
|
|
})
|
|
|
|
|
|
|
|
local on_attach = function(_, bufnr)
|
|
|
|
local opts = { buffer = bufnr }
|
|
|
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
|
|
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
|
|
|
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
|
|
|
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
|
|
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
|
|
|
|
vim.keymap.set("n", "<leader>ln", vim.diagnostic.goto_next, opts)
|
|
|
|
vim.keymap.set("n", "<leader>lp", vim.diagnostic.goto_prev, opts)
|
|
|
|
vim.keymap.set("n", "<leader>lf", vim.lsp.buf.formatting, opts)
|
|
|
|
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
|
|
|
|
vim.keymap.set("n", "<leader>wa",
|
|
|
|
vim.lsp.buf.add_workspace_folder, opts)
|
|
|
|
vim.keymap.set("n", "<leader>wr",
|
|
|
|
vim.lsp.buf.remove_workspace_folder, opts)
|
|
|
|
vim.keymap.set("n", "<leader>wl", function()
|
|
|
|
vim.inspect(vim.lsp.buf.list_workspace_folders())
|
|
|
|
end, opts)
|
|
|
|
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, opts)
|
|
|
|
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
|
|
|
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
|
|
|
|
vim.keymap.set("n", "<leader>so",
|
|
|
|
require("telescope.builtin").lsp_document_symbols, opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- nvim-cmp supports additional completion capabilities
|
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
2022-10-19 23:27:36 +02:00
|
|
|
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
|
2022-05-02 23:35:31 +02:00
|
|
|
|
2022-12-02 16:14:33 +01:00
|
|
|
local servers = {
|
|
|
|
"clangd",
|
2022-12-02 16:15:29 +01:00
|
|
|
"rust_analyzer",
|
2022-12-02 16:14:33 +01:00
|
|
|
"sumneko_lua",
|
|
|
|
"texlab",
|
|
|
|
}
|
2022-11-10 20:53:58 +01:00
|
|
|
|
|
|
|
mason.setup({
|
2022-05-02 23:35:31 +02:00
|
|
|
ui = {
|
|
|
|
icons = {
|
|
|
|
server_installed = "✓",
|
|
|
|
server_pending = "o",
|
2022-05-04 22:58:42 +02:00
|
|
|
server_uninstalled = ""
|
2022-05-02 23:35:31 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-10 20:53:58 +01:00
|
|
|
})
|
|
|
|
|
2022-12-02 16:12:44 +01:00
|
|
|
_G.lsp_root_dir = vim.fn.stdpath("data") .. "/mason/bin"
|
|
|
|
|
2022-11-10 20:53:58 +01:00
|
|
|
mason_lspconfig.setup({
|
|
|
|
ensure_installed = servers,
|
|
|
|
})
|
|
|
|
|
2022-05-02 23:35:31 +02:00
|
|
|
|
|
|
|
for _, server in ipairs(servers) do
|
|
|
|
local opts = {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
}
|
|
|
|
|
2022-12-02 16:13:21 +01:00
|
|
|
local plugin = string.format("plugin.lsp.%s", server)
|
2022-05-04 22:58:42 +02:00
|
|
|
require(plugin).setup(opts)
|
2022-05-02 23:35:31 +02:00
|
|
|
|
|
|
|
lspconfig[server].setup(opts)
|
|
|
|
end
|