From 1c1f869b16ae257d499c179800f33821cb1bf56d Mon Sep 17 00:00:00 2001 From: Devin Haska Date: Sat, 27 Apr 2024 18:09:47 -0700 Subject: [PATCH] feat: move all LSP config to `lsp.lua` --- lua/plugins/lsp-config.lua | 52 --------------------------------- lua/plugins/lsp.lua | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 52 deletions(-) delete mode 100644 lua/plugins/lsp-config.lua create mode 100644 lua/plugins/lsp.lua diff --git a/lua/plugins/lsp-config.lua b/lua/plugins/lsp-config.lua deleted file mode 100644 index a831f96..0000000 --- a/lua/plugins/lsp-config.lua +++ /dev/null @@ -1,52 +0,0 @@ -return { - { - "williamboman/mason.nvim", - config = function() - require("mason").setup() - end, - }, - { - "williamboman/mason-lspconfig.nvim", - config = function() - require("mason-lspconfig").setup({ - ensure_installed = { "lua_ls", "tsserver", "html" }, - }) - end, - }, - { - "neovim/nvim-lspconfig", - config = function() - local lspconfig = require("lspconfig") - local capabilities = require("cmp_nvim_lsp").default_capabilities() - - lspconfig.lua_ls.setup({ - capabilities = capabilities, - }) - - lspconfig.tsserver.setup({ - capabilities = capabilities, - }) - - vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Go to definition" }) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { desc = "Go to implementation" }) - vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Show signature" }) - vim.keymap.set("n", "f", vim.lsp.buf.format, { desc = "Format buffer" }) - vim.keymap.set("n", "ca", vim.lsp.buf.code_action, { desc = "View code actions" }) - end, - }, - { - "WhoIsSethDaniel/mason-tool-installer.nvim", - config = function() - local mason_tool_installer = require("mason-tool-installer") - - mason_tool_installer.setup({ - ensure_installed = { - "djlint", - "prettierd", - "eslint_d", - }, - automatic_installation = true, - }) - end, - }, -} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..bad9c77 --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,60 @@ +return { + { + "williamboman/mason.nvim", + opts = {}, + }, + { + "williamboman/mason-lspconfig.nvim", + opts = { + ensure_installed = { + "lua_ls", + "tsserver", + "html", + } + } + }, + { + "WhoIsSethDaniel/mason-tool-installer.nvim", + opts = { + ensure_installed = { + "djlint", + "eslint_d", + "prettierd", + "stylua", + }, + automatic_installation = true, + } + }, + -- lspconfig should be the last step. + { + "neovim/nvim-lspconfig", + event = "VeryLazy", + dependencies = { + "mason.nvim", + "williamboman/mason-lspconfig.nvim", + }, + opts = { + servers = { + tsserver = {}, + lua_ls = {} + } + }, + config = function(_, opts) + local lspconfig = require("lspconfig") + local capabilities = require("cmp_nvim_lsp").default_capabilities() + + local servers = opts.servers + + for server, server_opts in pairs(servers) do + local sopts = vim.tbl_deep_extend("force", server_opts, capabilities) + lspconfig[server].setup(sopts) + end + + vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Go to definition" }) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { desc = "Go to implementation" }) + vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Show signature" }) + vim.keymap.set("n", "f", vim.lsp.buf.format, { desc = "Format buffer" }) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, { desc = "View code actions" }) + end, + }, +}