This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.config/nvim/lua/plugin/lsp/init.lua

96 lines
2.7 KiB
Lua
Raw Normal View History

-- Author : swytch
-- Created : Monday May 2, 2022 21:02:02 CET
-- License : GPLv3
-- Description : neovim global lsp config file
local lspconfig = require("lspconfig")
local mason = require("mason")
local mason_lspconfig = require("mason-lspconfig")
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
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-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",
}
mason.setup({
ui = {
icons = {
server_installed = "",
server_pending = "o",
2022-05-04 22:58:42 +02:00
server_uninstalled = ""
}
}
})
_G.lsp_root_dir = vim.fn.stdpath("data") .. "/mason/bin"
mason_lspconfig.setup({
ensure_installed = servers,
})
for _, server in ipairs(servers) do
local opts = {
on_attach = on_attach,
capabilities = capabilities,
}
local plugin = string.format("plugin.lsp.%s", server)
2022-05-04 22:58:42 +02:00
require(plugin).setup(opts)
lspconfig[server].setup(opts)
end