Dotfiles/site-modules/core/files/vim/plugin/lsp.lua

65 lines
2.5 KiB
Lua
Raw Normal View History

local lspconfig = require "lspconfig"
2022-06-12 19:25:17 +00:00
local servers = {
-- Language servers for the day to day web development, could probably think
-- about loosing the html and css one and living with typescript and emmet
tsserver = {},
html = {},
cssls = {},
emmet_ls = {
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "scss", "eruby" },
},
-- Ruby
solargraph = {},
-- Rust
rust_analyzer = {},
-- Lua for the vim config and plugin dev
sumneko_lua = {
settings = {
Lua = {
runtime = { version = "LuaJIT" },
diagnostics = { globals = { "vim" } },
workspace = { library = vim.api.nvim_get_runtime_file("", true) },
telemetry = { enable = false },
},
},
},
}
local on_attach = function(_, bufnr)
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
2022-06-12 19:25:17 +00:00
local opts = { noremap = true, silent = true }
2022-06-12 19:25:17 +00:00
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
2022-06-12 19:25:17 +00:00
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
2022-06-12 19:25:17 +00:00
end
2022-12-22 20:12:50 +00:00
local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
2022-06-12 19:25:17 +00:00
capabilities.textDocument.completion.completionItem.snippetSupport = true
for lsp, config in pairs(servers) do
config["on_attach"] = on_attach
config["capabilities"] = capabilities
config["init_options"] = { usePlaceholders = true }
2022-06-12 19:25:17 +00:00
lspconfig[lsp].setup(config)
end
2022-06-12 19:25:17 +00:00
-- Change the diagnostic signs
2022-12-22 20:12:50 +00:00
vim.fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint", numhl = "DiagnosticSignHint" })
vim.fn.sign_define("DiagnosticSignInfo", { text = "", texthl = "DiagnosticSignInfo", numhl = "DiagnosticSignInfo" })
vim.fn.sign_define("DiagnosticSignWarn", { text = "", texthl = "DiagnosticSignWarn", numhl = "DiagnosticSignWarn" })
vim.fn.sign_define(
"DiagnosticSignError",
{ text = "", texthl = "DiagnosticSignError", numhl = "DiagnosticSignError" }
2022-12-22 20:12:50 +00:00
)