mirror of
https://github.com/Ascyii/nvim.git
synced 2026-01-01 04:04:24 -05:00
Full refactor of codebase and usage of lazyvim opts setting. Also split code in custom plugins
This commit is contained in:
123
lua/plugins/lsp.lua
Normal file
123
lua/plugins/lsp.lua
Normal file
@@ -0,0 +1,123 @@
|
||||
return {
|
||||
{ "stevearc/aerial.nvim", opts = {} },
|
||||
{
|
||||
"nvimdev/lspsaga.nvim",
|
||||
opts = {
|
||||
lightbulb = {
|
||||
enable = false,
|
||||
enable_in_insert = false,
|
||||
sign = false,
|
||||
virtual_text = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
dependencies = {
|
||||
"williamboman/mason.nvim",
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
|
||||
"hrsh7th/nvim-cmp",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"nvimdev/lspsaga.nvim",
|
||||
"hrsh7th/cmp-path",
|
||||
"L3MON4D3/LuaSnip",
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
},
|
||||
config = function()
|
||||
local lspconfig = require("lspconfig")
|
||||
|
||||
-- Declarative important have npm and other tools installed
|
||||
local servers = { "gopls", "pyright", "lua_ls", "rust_analyzer", "clangd" }
|
||||
|
||||
-- Custom overwrites for servers
|
||||
local server_settings = {
|
||||
lua_ls = {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = { globals = { "vim" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
local cmp = require("cmp")
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args) require("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.select_next_item(),
|
||||
["<S-Tab>"] = cmp.mapping.select_prev_item(),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
}, {
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
}),
|
||||
})
|
||||
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
local on_attach = function(_, bufnr)
|
||||
local opts = { buffer = bufnr, noremap = true, silent = true }
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
|
||||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||||
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
|
||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
|
||||
vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, opts)
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, 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)
|
||||
--vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, opts)
|
||||
vim.keymap.set("n", "<leader>lq", vim.diagnostic.setloclist, 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()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, opts)
|
||||
|
||||
vim.keymap.set("n", "<leader>ff", function()
|
||||
vim.lsp.buf.format({ async = true })
|
||||
end, opts)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Setup servers manually
|
||||
for _, server in ipairs(servers) do
|
||||
local config = {
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
}
|
||||
if server_settings[server] then
|
||||
config = vim.tbl_deep_extend("force", config, server_settings[server])
|
||||
end
|
||||
lspconfig[server].setup(config)
|
||||
end
|
||||
|
||||
-- Mason for autoinstall of servers
|
||||
require("mason").setup()
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = servers,
|
||||
automatic_installation = true,
|
||||
})
|
||||
|
||||
-- Add text in diagnostics
|
||||
vim.diagnostic.config({
|
||||
virtual_text = true,
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user