refactor(nvim): refactor lsp configuration

This commit is contained in:
Oliver Davies 2021-12-24 00:21:35 +00:00
parent eab1a43ecd
commit 4bc2eaa8ff
7 changed files with 103 additions and 57 deletions

View file

@ -4,7 +4,7 @@ require("opdavies.completion")
require("opdavies.floaterm")
require("opdavies.gitsigns")
require("opdavies.indent-blankline")
require("opdavies.lspconfig")
require("opdavies.lsp")
require("opdavies.options")
require("opdavies.plugins")
require("opdavies.seiya")

View file

@ -0,0 +1,47 @@
local M = {}
M.setup = function()
local config = {
virtual_text = false,
update_in_insert = true,
underline = true,
severity_sort = true,
float = {
focusable = false,
style = "minimal",
source = "always",
header = "",
prefix = "",
}
}
vim.diagnostic.config(config)
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
if not status_ok then
return
end
local function lsp_keymaps()
local opts = { noremap = true, silent = true }
local keymap = vim.api.nvim_buf_set_keymap
keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
keymap(bufnr, "n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
end
M.on_attach = function()
lsp_keymaps(bufnr)
end
M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities)
return M

View file

@ -0,0 +1,40 @@
local status_ok, lspconfig = pcall(require, "lspconfig")
if not status_ok then
return
end
local opts = {
on_attach = require("opdavies.lsp.handlers").on_attach,
capabilities = require("opdavies.lsp.handlers").capabilities,
}
local servers = {
"ansiblels",
"bashls",
"cssls",
"html",
"tsserver",
"vuels",
"yamlls",
}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup(opts)
end
local intelephense_opts = require("opdavies.lsp.settings.intelephense")
lspconfig.intelephense.setup {
vim.tbl_deep_extend("force", intelephense_opts, opts)
}
local sumneko_lua_opts = require("opdavies.lsp.settings.sumneko_lua")
lspconfig.sumneko_lua.setup(
vim.tbl_deep_extend("force", sumneko_lua_opts, opts)
)
local tailwindcss_opts = require("opdavies.lsp.settings.tailwindcss")
lspconfig.tailwindcss.setup {
vim.tbl_deep_extend("force", tailwindcss_opts, opts)
}
require("opdavies.lsp.handlers").setup()

View file

@ -0,0 +1,3 @@
return {
filetypes = { "php", "module", "test", "inc" }
}

View file

@ -0,0 +1,9 @@
return {
settings = {
Lua = {
diagnostics = {
globals = { "vim" }
},
},
},
}

View file

@ -0,0 +1,3 @@
return {
filetypes = { "html", "html.twig", "lua" }
}

View file

@ -1,56 +0,0 @@
local status_ok, lspconfig = pcall(require, "lspconfig")
if not status_ok then
return
end
local function config(_config)
return vim.tbl_deep_extend("force", {
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
}, _config or {})
end
lspconfig.ansiblels.setup(config())
lspconfig.bashls.setup(config())
lspconfig.cssls.setup(config())
lspconfig.html.setup(config())
lspconfig.intelephense.setup(config({
filetypes = { "php", "test", "theme" }
}))
lspconfig.tsserver.setup(config())
lspconfig.vuels.setup(config())
lspconfig.yamlls.setup(config())
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
underline = true,
virtual_text = true,
signs = true,
update_in_insert = true,
}
)
local map = vim.api.nvim_set_keymap
local options = {
noremap = true,
silent = true,
}
map('n', '<leader>vb', ':lua require"telescope.builtin".buffers()<CR>', options)
map('n', '<leader>vca', ':lua vim.lsp.buf.code_action()<CR>', options)
map('n', '<leader>vd', ':lua vim.lsp.buf.definition()<CR>', options)
map('n', '<leader>vh', ':lua vim.lsp.buf.hover()<CR>', options)
map('n', '<leader>vi', ':lua vim.lsp.buf.implementation()<CR>', options)
map('n', '<leader>vn', ':lua vim.lsp.diagnostic.goto_next()<CR>', options)
map('n', '<leader>vrn', ':lua vim.lsp.buf.rename()<CR>', options)
map('n', '<leader>vrr', ':lua vim.lsp.buf.references()<CR>', options)
map('n', '<leader>vs', ':lua require"telescope.builtin".live_grep()<CR>', options)
map('n', '<leader>vsd', ':lua vim.lsp.diagnostic.show_line_diagnostics(); vim.lsp.util.show_line_diagnostics()<CR>', options)
map('n', '<leader>vsh', ':lua vim.lsp.buf.signature_help()<CR>', options)