95 lines
3.0 KiB
Lua
95 lines
3.0 KiB
Lua
local lspconfig = require("lspconfig")
|
|
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
lspconfig.lua_ls.setup({
|
|
root_dir = function()
|
|
return vim.fs.root(0, ".git")
|
|
end,
|
|
capabilities = capabilities,
|
|
})
|
|
lspconfig.ts_ls.setup({
|
|
root_dir = function()
|
|
return vim.fs.root(0, ".git")
|
|
end,
|
|
capabilities = capabilities,
|
|
})
|
|
lspconfig.eslint.setup({
|
|
root_dir = function()
|
|
return vim.fs.root(0, ".git")
|
|
end,
|
|
capabilities = capabilities,
|
|
})
|
|
lspconfig.angularls.setup({
|
|
root_dir = function()
|
|
return vim.fs.root(0, ".git")
|
|
end,
|
|
capabilities = capabilities,
|
|
})
|
|
lspconfig.ccls.setup({
|
|
root_dir = function()
|
|
return vim.fs.root(0, ".git")
|
|
end,
|
|
capabilities = capabilities,
|
|
})
|
|
lspconfig.nixd.setup({
|
|
root_dir = function()
|
|
return vim.fs.root(0, ".git")
|
|
end,
|
|
capabilities = capabilities,
|
|
})
|
|
|
|
-- Global mappings.
|
|
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
|
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, {
|
|
desc = "Open LSP diagnostics",
|
|
})
|
|
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, {
|
|
desc = "Go to previous LSP diagnostic",
|
|
})
|
|
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, {
|
|
desc = "Go to next LSP diagnostic",
|
|
})
|
|
|
|
-- Use LspAttach autocommand to only map the following keys
|
|
-- after the language server attaches to the current buffer
|
|
vim.api.nvim_create_autocmd("LspAttach", {
|
|
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
|
callback = function(ev)
|
|
local buffer_options = vim.bo[ev.buf]
|
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
buffer_options.omnifunc = "v:lua.vim.lsp.omnifunc"
|
|
|
|
-- Buffer local mappings.
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
local opts = function(desc)
|
|
return { buffer = ev.buf, desc = desc }
|
|
end
|
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts("Go to declaration"))
|
|
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts("Go to definition"))
|
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts("Show LSP info"))
|
|
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts("Go to implementation"))
|
|
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts("Show function signature"))
|
|
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts("Add workspace folder"))
|
|
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts("Remove workspace folder"))
|
|
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts("Go to type definition"))
|
|
vim.keymap.set("n", "<space>r", vim.lsp.buf.rename, opts("Rename symbol"))
|
|
vim.keymap.set({ "n", "v" }, "<space>x", vim.lsp.buf.code_action, opts("Execute code action"))
|
|
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts("Go to references"))
|
|
end,
|
|
})
|
|
|
|
local rt = require("rust-tools")
|
|
|
|
rt.setup({
|
|
server = {
|
|
on_attach = function(_, bufnr)
|
|
-- Hover actions
|
|
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
|
|
-- Code action groups
|
|
vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
|
|
end,
|
|
},
|
|
})
|