This repository has been archived on 2024-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
neovim/plugins/lsp/lspconfig.lua

88 lines
3.2 KiB
Lua

local lsp_config = require("lspconfig")
local saga = require("lspsaga")
-- See: https://github.com/glepnir/lspsaga.nvim#configuration
saga.init_lsp_saga({
border_style = "rounded",
code_action_lightbulb = { enable = false },
code_action_keys = { quit = "<Esc>" },
definition_action_keys = { quit = "<Esc>" },
rename_action_quit = "<Esc>",
})
-- always show signcolumns
vim.opt.signcolumn = "yes"
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap = true, silent = true }
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, opts)
vim.keymap.set("n", "[c", "<Cmd>Lspsaga diagnostic_jump_prev<CR>", opts)
vim.keymap.set("n", "]c", "<Cmd>Lspsaga diagnostic_jump_next<CR>", opts)
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, opts)
-- Only jump to error
vim.keymap.set("n", "[e", function()
require("lspsaga.diagnostic").goto_prev({ severity = vim.diagnostic.severity.ERROR })
end, opts)
vim.keymap.set("n", "]e", function()
require("lspsaga.diagnostic").goto_next({ severity = vim.diagnostic.severity.ERROR })
end, opts)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
-- vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, bufopts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)
vim.keymap.set("n", "gy", vim.lsp.buf.type_definition, bufopts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts)
-- vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
-- vim.keymap.set("n", "<localleader>f", vim.lsp.buf.formatting, bufopts)
vim.keymap.set("n", "<localleader>n", "<Cmd>Lspsaga rename<CR>", bufopts)
vim.keymap.set({ "n", "v" }, "<localleader>a", "<Cmd>Lspsaga code_action<CR>", bufopts)
vim.keymap.set("n", "K", "<Cmd>Lspsaga hover_doc<CR>", bufopts)
vim.keymap.set("n", "co", "<Cmd>LSoutlineToggle<CR>", bufopts)
end
-- nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
-------------------------------------------------------------------------------
-- See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
--
-- Override the default configuration to be applied to all servers
lsp_config.util.default_config = vim.tbl_extend("force", lsp_config.util.default_config, {
on_attach = on_attach,
capabilities = capabilities,
})
-- nix
lsp_config.nil_ls.setup({})
-- js,ts
lsp_config.tsserver.setup({})
lsp_config.eslint.setup({})
-- rust
lsp_config.rust_analyzer.setup({
-- Server-specific settings...
settings = {
["rust-analyzer"] = {
["server.path"] = "rust-analyzer",
["updates.prompt"] = false,
["updates.checkOnStartup"] = false,
["checkOnSave.enable"] = true,
["checkOnSave.command"] = "clippy",
["cargo.autoreload"] = true,
},
},
})