adjust lsp
This commit is contained in:
+67
-65
@@ -1,24 +1,44 @@
|
||||
local lsp = require("lsp-zero")
|
||||
|
||||
lsp.preset("recommended")
|
||||
|
||||
require("mason").setup({})
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = {
|
||||
"ts_ls",
|
||||
"eslint",
|
||||
"lua_ls",
|
||||
"rust_analyzer",
|
||||
"ast_grep"
|
||||
},
|
||||
handlers = {
|
||||
function(server_name)
|
||||
require("lspconfig")[server_name].setup({})
|
||||
end,
|
||||
}
|
||||
vim.diagnostic.config({
|
||||
virtual_text = true,
|
||||
signs = true,
|
||||
underline = true,
|
||||
})
|
||||
|
||||
local cmp = require('cmp')
|
||||
local servers = {
|
||||
ts_ls = {},
|
||||
eslint = {},
|
||||
lua_ls = {
|
||||
cmd = { "lua-language-server" },
|
||||
filetypes = { "lua" }
|
||||
},
|
||||
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_autocmd("LspAttach", {
|
||||
callback = function(args)
|
||||
local opts = { buffer = args.buf }
|
||||
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.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", "[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)
|
||||
vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
|
||||
end
|
||||
})
|
||||
|
||||
local cmp = require("cmp")
|
||||
|
||||
cmp.setup({
|
||||
window = {
|
||||
@@ -26,53 +46,35 @@ cmp.setup({
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-k>'] = cmp.mapping.select_prev_item(),
|
||||
['<C-j>'] = cmp.mapping.select_next_item(),
|
||||
['<C-y>'] = cmp.mapping.confirm({ select = true }),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-j>"] = cmp.mapping.select_next_item(),
|
||||
["<C-k>"] = cmp.mapping.select_prev_item(),
|
||||
["<CR>"] = cmp.mapping.confirm(),
|
||||
}),
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
sources = {
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
}
|
||||
})
|
||||
|
||||
lsp.extend_lspconfig()
|
||||
require("mason").setup()
|
||||
|
||||
lsp.set_preferences({
|
||||
sign_icons = {}
|
||||
})
|
||||
|
||||
local builtin = require('telescope.builtin')
|
||||
vim.keymap.set("n", "gd", builtin.lsp_definitions, {})
|
||||
|
||||
lsp.on_attach(function(client, bufnr)
|
||||
lsp.default_keymaps({ buffer = bufnr })
|
||||
|
||||
local opts = { buffer = bufnr, remap = false }
|
||||
|
||||
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
|
||||
vim.keymap.set("n", "<leader>gd", builtin.lsp_definitions, {})
|
||||
vim.keymap.set('n', '<leader>cf', builtin.lsp_incoming_calls)
|
||||
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
|
||||
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
|
||||
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
|
||||
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
|
||||
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
|
||||
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
|
||||
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
|
||||
end)
|
||||
|
||||
lsp.setup()
|
||||
|
||||
-- Function to restart all active LSP clients
|
||||
local function restart_lsp()
|
||||
for _, client in pairs(vim.lsp.get_active_clients()) do
|
||||
client.stop()
|
||||
end
|
||||
vim.cmd("edit") -- Reload the current buffer to reattach the LSP clients
|
||||
end
|
||||
|
||||
-- Create a Neovim command to restart LSP
|
||||
vim.api.nvim_create_user_command('LspRestart', restart_lsp, {})
|
||||
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, {})
|
||||
|
||||
Reference in New Issue
Block a user