136 lines
3.9 KiB
Lua
136 lines
3.9 KiB
Lua
-- ~/.config/nvim/lua/plugins/lsp.lua
|
|
return {
|
|
-- Mason (LSP installer)
|
|
{
|
|
"williamboman/mason.nvim",
|
|
build = ":MasonUpdate",
|
|
opts = {},
|
|
},
|
|
|
|
-- Mason LSP config integration
|
|
{
|
|
"williamboman/mason-lspconfig.nvim",
|
|
dependencies = { "mason.nvim" },
|
|
opts = {
|
|
ensure_installed = { "lua_ls", "pyright", "texlab", "bashls", "marksman" },
|
|
},
|
|
},
|
|
|
|
-- LSP configuration
|
|
{
|
|
"neovim/nvim-lspconfig",
|
|
dependencies = {
|
|
"mason.nvim",
|
|
"mason-lspconfig.nvim",
|
|
"hrsh7th/cmp-nvim-lsp",
|
|
},
|
|
config = function()
|
|
local lspconfig = require("lspconfig")
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
-- Configure diagnostics to be hidden by default
|
|
vim.diagnostic.config({
|
|
virtual_text = false,
|
|
signs = false,
|
|
underline = false,
|
|
update_in_insert = false,
|
|
severity_sort = false,
|
|
})
|
|
|
|
-- Set up keymaps for LSP
|
|
vim.api.nvim_create_autocmd("LspAttach", {
|
|
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
|
callback = function(ev)
|
|
local opts = { buffer = ev.buf }
|
|
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', '<leader>rn', vim.lsp.buf.rename, opts)
|
|
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
|
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
|
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
|
|
end,
|
|
})
|
|
|
|
-- Language servers setup with capabilities
|
|
lspconfig.lua_ls.setup({
|
|
capabilities = capabilities,
|
|
})
|
|
lspconfig.pyright.setup({
|
|
capabilities = capabilities,
|
|
})
|
|
lspconfig.texlab.setup({
|
|
capabilities = capabilities,
|
|
})
|
|
lspconfig.bashls.setup({
|
|
capabilities = capabilities,
|
|
})
|
|
lspconfig.marksman.setup({
|
|
capabilities = capabilities,
|
|
})
|
|
end,
|
|
},
|
|
|
|
-- Completion
|
|
{
|
|
"hrsh7th/nvim-cmp",
|
|
dependencies = {
|
|
"hrsh7th/cmp-buffer",
|
|
"hrsh7th/cmp-path",
|
|
"hrsh7th/cmp-nvim-lsp",
|
|
"hrsh7th/cmp-nvim-lua",
|
|
"saadparwaiz1/cmp_luasnip",
|
|
{
|
|
"L3MON4D3/LuaSnip",
|
|
dependencies = { "rafamadriz/friendly-snippets", "evesdropper/luasnip-latex-snippets.nvim" },
|
|
build = "make install_jsregexp",
|
|
},
|
|
},
|
|
config = function()
|
|
local cmp = require("cmp")
|
|
local luasnip = require("luasnip")
|
|
|
|
-- Load snippets
|
|
require("luasnip.loaders.from_vscode").lazy_load()
|
|
require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/lua/snippets" })
|
|
|
|
cmp.setup({
|
|
snippet = {
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end,
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
["<C-Space>"] = cmp.mapping.complete(),
|
|
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
|
["<Tab>"] = cmp.mapping(function(fallback)
|
|
if require("copilot.suggestion").is_visible() then
|
|
require("copilot.suggestion").accept()
|
|
elseif cmp.visible() then
|
|
cmp.select_next_item()
|
|
elseif luasnip.expand_or_jumpable() then
|
|
luasnip.expand_or_jump()
|
|
else
|
|
fallback()
|
|
end
|
|
end, { "i", "s" }),
|
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
|
if cmp.visible() then
|
|
cmp.select_prev_item()
|
|
elseif luasnip.jumpable(-1) then
|
|
luasnip.jump(-1)
|
|
else
|
|
fallback()
|
|
end
|
|
end, { "i", "s" }),
|
|
}),
|
|
sources = cmp.config.sources({
|
|
{ name = "nvim_lsp" },
|
|
{ name = "luasnip" },
|
|
{ name = "buffer" },
|
|
{ name = "path" },
|
|
}),
|
|
})
|
|
end,
|
|
},
|
|
} |