neovim-config/lua/plugins/lsp.lua

132 lines
4.6 KiB
Lua

vim.lsp.handlers["textDocument/codeAction"] = require "lsputil.codeAction".code_action_handler
vim.lsp.handlers["textDocument/references"] = require "lsputil.locations".references_handler
vim.lsp.handlers["textDocument/definition"] = require "lsputil.locations".definition_handler
vim.lsp.handlers["textDocument/declaration"] = require "lsputil.locations".declaration_handler
vim.lsp.handlers["textDocument/typeDefinition"] = require "lsputil.locations".typeDefinition_handler
vim.lsp.handlers["textDocument/implementation"] = require "lsputil.locations".implementation_handler
vim.lsp.handlers["textDocument/documentSymbol"] = require "lsputil.symbols".document_handler
vim.lsp.handlers["workspace/symbol"] = require "lsputil.symbols".workspace_handler
vim.fn.sign_define(
"LspDiagnosticsSignError",
{texthl = "LspDiagnosticsSignError", text = "", numhl = "LspDiagnosticsSignError"}
)
vim.fn.sign_define(
"LspDiagnosticsSignWarning",
{texthl = "LspDiagnosticsSignWarning", text = "", numhl = "LspDiagnosticsSignWarning"}
)
vim.fn.sign_define(
"LspDiagnosticsSignHint",
{texthl = "LspDiagnosticsSignHint", text = "", numhl = "LspDiagnosticsSignHint"}
)
vim.fn.sign_define(
"LspDiagnosticsSignInformation",
{texthl = "LspDiagnosticsSignInformation", text = "", numhl = "LspDiagnosticsSignInformation"}
)
--- Completion Icons
require("lspkind").init({})
--- Languages
require "lspconfig".bashls.setup {}
require "lspconfig".ccls.setup {}
require "lspconfig".clangd.setup {}
require "lspconfig".cssls.setup {}
require "lspconfig".html.setup {}
require "lspconfig".pyright.setup {}
require "lspconfig".tsserver.setup {}
require "lspconfig".vimls.setup {}
require "lspconfig".yamlls.setup {}
--- ESLINT
local eslint = {
lintCommand = "eslint_d -f visualstudio --stdin --stdin-filename ${INPUT}",
lintIgnoreExitCode = true,
lintStdin = true,
lintFormats = {
"%f(%l,%c): %tarning %m",
"%f(%l,%c): %rror %m"
}
}
require "lspconfig".efm.setup {
init_options = {documentFormatting = true},
filetypes = {"javascript", "typescript", "javascriptreact", "typescriptreact"},
init_options = {documentFormatting = true},
settings = {
rootMarkers = {".eslintrc.js", ".git/"},
languages = {
javascript = {eslint},
typescript = {eslint},
typescriptreact = {eslint},
javascriptreact = {eslint}
}
}
}
--- Keybindings
local nvim_lsp = require("lspconfig")
local on_attach = function(client, bufnr)
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
-- Mappings.
local opts = {noremap = true, silent = true}
buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts)
buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
buf_set_keymap("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
buf_set_keymap("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
buf_set_keymap("n", "<space>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<space>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<space>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
-- buf_set_keymap("n", "<leader>t", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
buf_set_keymap("n", "<F2>", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
buf_set_keymap("n", "<leader>a", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
buf_set_keymap("n", "<leader>d", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts)
buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
buf_set_keymap("n", "<space>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
end
require "lspconfig".jsonls.setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150
},
settings = {
json = require "json-schema"
}
}
require "lspconfig".tsserver.setup {
on_attach = function(client, bufnr)
local ts_utils = require("nvim-lsp-ts-utils")
ts_utils.setup {}
ts_utils.setup_client(client)
on_attach(client, bufnr)
end,
flags = {
debounce_text_changes = 150
}
}
local servers = {"pyright", "bashls", "clangd", "cssls"}
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150
}
}
end