Files
nvim/after/plugin/lsp.lua
T

99 lines
3.1 KiB
Lua

vim.diagnostic.config({
virtual_text = true, -- Text to the right of issues
signs = false,
underline = true,
})
-- Filetype by extension
vim.filetype.add {
extension = {
jinja = 'jinja',
jinja2 = 'jinja',
j2 = 'jinja',
py = 'python'
},
}
-- Languageserver config overrides
-- To enable a server a config must be present here
-- Default Configs are provided by nvim_lspconfig
local servers = {
-- <server_name> = { <config> },
ts_ls = {},
eslint = {},
lua_ls = {},
jinja_lsp = {
filetypes = { 'jinja', 'rust', 'python' },
},
rust_analyzer = {},
ast_grep = {},
}
---@type lsp.ClientCapabilities
local capabilities = require("cmp_nvim_lsp").default_capabilities()
for server, config in pairs(servers) do
servers[server].capabilities = capabilities
vim.lsp.config(server, config)
vim.lsp.enable(server)
end
vim.api.nvim_create_user_command("LspInfo", "checkhealth vim.lsp", {})
local builtin = require('telescope.builtin');
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local opts = { buffer = args.buf }
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) -- Show type and defintion data (C-w C-w to enter it like any other buffer)
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, opts) -- Show a detailed error description (can be run on lines with any error)
vim.keymap.set("n", "gd", builtin.lsp_definitions, opts) -- Go to definition
vim.keymap.set("n", "<leader>vrn", vim.lsp.buf.rename, opts) -- Rename symbol under cursor project wide through ls
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts) -- Execute a ls code action
-- vim.keymap.set("n", "[d", function() vim.diagnostic.jump({ count = 1, float = true }) end, opts)
-- vim.keymap.set("n", "]d", function() vim.diagnostic.jump({ count = -1, float = true }) end, opts)
end
})
-- Does code completion
local cmp = require("cmp")
cmp.setup({
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
["<C-j>"] = cmp.mapping.select_next_item(), -- Scroll down
["<C-k>"] = cmp.mapping.select_prev_item(), -- Scroll Up
["<CR>"] = cmp.mapping.confirm(), -- Confirm currently suggested code completion
}),
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
}
})
-- Mason is only used for managing Languageserver binaries. Run :MasonInstallAll on first install
require("mason").setup()
local ensure_installed = {
"ast-grep",
"clangd",
"diagnostic-languageserver",
"eslint-lsp",
"jdtls",
"json-lsp",
"lua-language-server",
"python-lsp-server",
"some-sass-language-server",
"tombi",
"rust-analyzer",
"typescript-language-server",
"yaml-language-server",
"jinja-lsp"
}
vim.api.nvim_create_user_command("MasonInstallAll", function()
local packages = table.concat(ensure_installed, " ")
vim.cmd("MasonInstall " .. packages)
end, {})