81 lines
3 KiB
Lua
81 lines
3 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 = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
-- for local configurations
|
|
nlsp_settings.setup({})
|
|
|
|
-------------------------------------------------------------------------------
|
|
-- See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
|
|
--
|
|
|
|
vim.g.markdown_fenced_languages = { "ts=typescript" }
|
|
|
|
-- 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)
|
|
|
|
if name == "eslint" then
|
|
vim.cmd([[
|
|
aug eslint_fix
|
|
au!
|
|
au BufWritePre *.tsx,*.ts,*.jsx,*.js EslintFixAll
|
|
aug END
|
|
]])
|
|
end
|
|
end
|
|
|