ajs-nvim/lua/setup/lsp.lua

118 lines
3.2 KiB
Lua
Raw Normal View History

2024-03-14 11:57:26 +00:00
local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities()
local default_setup = function(server)
require("lspconfig")[server].setup({
capabilities = lsp_capabilities,
})
end
-- enable mason and configure icons
require("mason").setup({
ui = {
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = "",
},
},
})
require("mason-lspconfig").setup({
ensure_installed = {
2024-03-17 22:05:12 +00:00
-- "tsserver",
2024-03-14 11:57:26 +00:00
"cssls",
"html",
"bashls",
"eslint",
2024-03-16 13:30:30 +00:00
"ltex",
--"marksman",
2024-03-16 12:25:01 +00:00
--"lua_ls" has to be installed via package manager on ARM systems
2024-03-14 11:57:26 +00:00
},
handlers = {
default_setup,
},
})
2024-03-17 22:04:58 +00:00
local on_attach = function()
vim.api.nvim_create_autocmd("LspAttach", {
desc = "LSP actions",
callback = function()
local bufmap = function(mode, lhs, rhs)
local opts = { buffer = true }
vim.keymap.set(mode, lhs, rhs, opts)
end
-- Displays hover information about the symbol under the cursor
bufmap("n", "K", "<cmd>lua vim.lsp.buf.hover()<cr>")
-- Jump to the definition
bufmap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<cr>")
-- Jump to declaration
bufmap("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<cr>")
-- Lists all the implementations for the symbol under the cursor
bufmap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<cr>")
-- Jumps to the definition of the type symbol
bufmap("n", "go", "<cmd>lua vim.lsp.buf.type_definition()<cr>")
-- Lists all the references
bufmap("n", "gr", "<cmd>lua vim.lsp.buf.references()<cr>")
-- Displays a function's signature information
bufmap("n", "gs", "<cmd>lua vim.lsp.buf.signature_help()<cr>")
-- Renames all references to the symbol under the cursor
bufmap("n", "<F2>", "<cmd>lua vim.lsp.buf.rename()<cr>")
-- Selects a code action available at the current cursor position
bufmap("n", "<F4>", "<cmd>lua vim.lsp.buf.code_action()<cr>")
-- Show diagnostics in a floating window
bufmap("n", "gl", "<cmd>lua vim.diagnostic.open_float()<cr>")
-- Move to the previous diagnostic
bufmap("n", "nd", "<cmd>lua vim.diagnostic.goto_prev()<cr>")
-- Move to the next diagnostic
bufmap("n", "nd", "<cmd>lua vim.diagnostic.goto_next()<cr>")
end,
})
end
2024-03-14 11:57:06 +00:00
local lspconfig = require("lspconfig")
require("mason-lspconfig").setup_handlers({
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function(server_name)
require("lspconfig")[server_name].setup({
on_attach = on_attach,
2024-03-16 13:30:30 +00:00
capabilities = lsp_capabilities,
2024-03-14 11:57:06 +00:00
})
end,
2024-03-17 22:03:40 +00:00
-- ["eslint"] = function()
-- lspconfig.eslint.setup({
-- capabilities = lsp_capabilities,
-- on_attach = require("config.lsp.servers.eslint").on_attach,
-- settings = require("config.lsp.servers.eslint").settings,
-- })
-- end,
2024-03-16 12:25:01 +00:00
["lua_ls"] = function()
lspconfig.lua_ls.setup({
2024-03-16 13:30:30 +00:00
capabilities = lsp_capabilities,
2024-03-17 22:04:58 +00:00
on_attach = on_attach,
2024-03-16 12:25:01 +00:00
settings = require("config.lsp.servers.lua").settings,
})
2024-03-16 13:30:30 +00:00
end,
["ltex"] = function()
2024-03-17 22:03:58 +00:00
lspconfig.ltex.setup({
capabilities = lsp_capabilities,
on_attach = on_attach,
settings = require("config.lsp.servers.latex").settings,
})
end,
2024-03-14 11:57:06 +00:00
})