diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index 44a4aa7..521a6a0 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -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") diff --git a/nvim/.config/nvim/lua/opdavies/lsp/handlers.lua b/nvim/.config/nvim/lua/opdavies/lsp/handlers.lua new file mode 100644 index 0000000..e7abaf2 --- /dev/null +++ b/nvim/.config/nvim/lua/opdavies/lsp/handlers.lua @@ -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", "lua vim.lsp.buf.declaration()", opts) + keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) + keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) + keymap(bufnr, "n", "", "lua vim.lsp.buf.signature_help()", opts) + keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) +end + +M.on_attach = function() + lsp_keymaps(bufnr) +end + +M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities) + +return M diff --git a/nvim/.config/nvim/lua/opdavies/lsp/init.lua b/nvim/.config/nvim/lua/opdavies/lsp/init.lua new file mode 100644 index 0000000..2168246 --- /dev/null +++ b/nvim/.config/nvim/lua/opdavies/lsp/init.lua @@ -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() diff --git a/nvim/.config/nvim/lua/opdavies/lsp/settings/intelephense.lua b/nvim/.config/nvim/lua/opdavies/lsp/settings/intelephense.lua new file mode 100644 index 0000000..33f156d --- /dev/null +++ b/nvim/.config/nvim/lua/opdavies/lsp/settings/intelephense.lua @@ -0,0 +1,3 @@ +return { + filetypes = { "php", "module", "test", "inc" } +} diff --git a/nvim/.config/nvim/lua/opdavies/lsp/settings/sumneko_lua.lua b/nvim/.config/nvim/lua/opdavies/lsp/settings/sumneko_lua.lua new file mode 100644 index 0000000..3f900d0 --- /dev/null +++ b/nvim/.config/nvim/lua/opdavies/lsp/settings/sumneko_lua.lua @@ -0,0 +1,9 @@ +return { + settings = { + Lua = { + diagnostics = { + globals = { "vim" } + }, + }, + }, +} diff --git a/nvim/.config/nvim/lua/opdavies/lsp/settings/tailwindcss.lua b/nvim/.config/nvim/lua/opdavies/lsp/settings/tailwindcss.lua new file mode 100644 index 0000000..5a647ab --- /dev/null +++ b/nvim/.config/nvim/lua/opdavies/lsp/settings/tailwindcss.lua @@ -0,0 +1,3 @@ +return { + filetypes = { "html", "html.twig", "lua" } +} diff --git a/nvim/.config/nvim/lua/opdavies/lspconfig.lua b/nvim/.config/nvim/lua/opdavies/lspconfig.lua deleted file mode 100644 index 447108e..0000000 --- a/nvim/.config/nvim/lua/opdavies/lspconfig.lua +++ /dev/null @@ -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', 'vb', ':lua require"telescope.builtin".buffers()', options) -map('n', 'vca', ':lua vim.lsp.buf.code_action()', options) -map('n', 'vd', ':lua vim.lsp.buf.definition()', options) -map('n', 'vh', ':lua vim.lsp.buf.hover()', options) -map('n', 'vi', ':lua vim.lsp.buf.implementation()', options) -map('n', 'vn', ':lua vim.lsp.diagnostic.goto_next()', options) -map('n', 'vrn', ':lua vim.lsp.buf.rename()', options) -map('n', 'vrr', ':lua vim.lsp.buf.references()', options) -map('n', 'vs', ':lua require"telescope.builtin".live_grep()', options) -map('n', 'vsd', ':lua vim.lsp.diagnostic.show_line_diagnostics(); vim.lsp.util.show_line_diagnostics()', options) -map('n', 'vsh', ':lua vim.lsp.buf.signature_help()', options)