neovim/plugins/lsp/lspconfig.lua

100 lines
3.5 KiB
Lua

local lsp_config = require("lspconfig")
local saga = require("lspsaga")
local nlsp_settings = require("nlspsettings")
-- See: https://github.com/glepnir/lspsaga.nvim#configuration
saga.init_lsp_saga(@lspSagaSettings@)
-- 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", "[d", "<Cmd>Lspsaga diagnostic_jump_prev<CR>", opts)
vim.keymap.set("n", "]d", "<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)
-- for local configurations
nlsp_settings.setup({})
-------------------------------------------------------------------------------
-- 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,
})
local root_pattern = lsp_config.util.root_pattern
for name, settings in pairs(@lspConfigServers@) do
lsp_config[name].setup(settings)
end
--[[
-- js,ts
lsp_config.tsserver.setup({})
lsp_config.eslint.setup({})
-- deno
-- To appropriately highlight codefences returned from denols
vim.g.markdown_fenced_languages = { "ts=typescript" }
lsp_config.denols.setup({
root_dir = lsp_config.util.root_pattern("deno.json", "deno.jsonc"),
})
-- 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,
},
},
})
]]--