From 7fcf86b27f4d8b1c07e32d4a61cd3ec43ca7bf87 Mon Sep 17 00:00:00 2001 From: Jannik Donker Date: Sat, 21 Jun 2025 09:49:38 +0200 Subject: [PATCH] lsp refactor --- lazy-lock.json | 18 ++++----- lua/plugins/lsp-config.lua | 80 +++++++++++++++----------------------- lua/vim-options.lua | 52 ++++++++++++------------- 3 files changed, 66 insertions(+), 84 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index 6b4ddbf..816fd67 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,22 +1,22 @@ { "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, - "LuaSnip": { "branch": "master", "commit": "faf3c94a44508cec1b961406d36cc65113ff3b98" }, - "blink.cmp": { "branch": "main", "commit": "022521a8910a5543b0251b21c9e1a1e989745796" }, + "LuaSnip": { "branch": "master", "commit": "fb525166ccc30296fb3457441eb979113de46b00" }, + "blink.cmp": { "branch": "main", "commit": "9bcb14b43852a6f2bfd5ac9ef29cb5cf09b1b39b" }, "gruvbox": { "branch": "main", "commit": "00e38a379bab3389e187b3953566d67d494dfddd" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, - "lualine.nvim": { "branch": "master", "commit": "0c6cca9f2c63dadeb9225c45bc92bb95a151d4af" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "60eaff7a470b8e78ddff09d847d17a011f560759" }, + "lualine.nvim": { "branch": "master", "commit": "a94fc68960665e54408fe37dcf573193c4ce82c9" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "f54e3c11fc9ebfcfc27e696182b0295b071d0811" }, "mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" }, "neo-tree.nvim": { "branch": "v3.x", "commit": "f481de16a0eb59c985abac8985e3f2e2f75b4875" }, "neoscroll.nvim": { "branch": "master", "commit": "f957373912e88579e26fdaea4735450ff2ef5c9c" }, "none-ls-extras.nvim": { "branch": "main", "commit": "924fe88a9983c7d90dbb31fc4e3129a583ea0a90" }, "none-ls.nvim": { "branch": "main", "commit": "db2a48b79cfcdab8baa5d3f37f21c78b6705c62e" }, - "nui.nvim": { "branch": "main", "commit": "7cd18e73cfbd70e1546931b7268b3eebaeff9391" }, - "nvim-autopairs": { "branch": "master", "commit": "4d74e75913832866aa7de35e4202463ddf6efd1b" }, - "nvim-lspconfig": { "branch": "master", "commit": "03bc581e05e81d33808b42b2d7e76d70adb3b595" }, + "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, + "nvim-autopairs": { "branch": "master", "commit": "2647cce4cb64fb35c212146663384e05ae126bdf" }, + "nvim-lspconfig": { "branch": "master", "commit": "0112e1f77983141e1453bd37d124302f1c876c46" }, "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "0f051e9813a36481f48ca1f833897210dbcfffde" }, - "nvim-web-devicons": { "branch": "master", "commit": "1fb58cca9aebbc4fd32b086cb413548ce132c127" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "89ebe73cd2836db80a22d9748999ace0241917a5" }, + "nvim-web-devicons": { "branch": "master", "commit": "19d6211c78169e78bab372b585b6fb17ad974e82" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, diff --git a/lua/plugins/lsp-config.lua b/lua/plugins/lsp-config.lua index aa597d5..5758144 100644 --- a/lua/plugins/lsp-config.lua +++ b/lua/plugins/lsp-config.lua @@ -7,61 +7,43 @@ return { }, { "williamboman/mason-lspconfig.nvim", - config = function() - require("mason-lspconfig").setup({ - ensure_installed = { "lua_ls", "ts_ls", "svelte", "tailwindcss", "cssls", "tinymist", }, - automatic_enable = true, - }) - end, + opts = { + ensure_installed = { + "lua_ls", + "ts_ls", + "svelte", + "tailwindcss", + "cssls", + "tinymist", + }, + }, }, { "neovim/nvim-lspconfig", + dependencies = { + "williamboman/mason-lspconfig.nvim", + }, config = function() - local original_capabilities = vim.lsp.protocol.make_client_capabilities() - local capabilities = require("blink.cmp").get_lsp_capabilities(original_capabilities) + local capabilities = require("blink.cmp").get_lsp_capabilities(vim.lsp.protocol.make_client_capabilities()) local lspconfig = require("lspconfig") - lspconfig.lua_ls.setup({ - capabilities = capabilities, - }) - lspconfig.ts_ls.setup({ - capabilities = capabilities, - }) - lspconfig.svelte.setup({ - capabilities = capabilities, - }) - lspconfig.tailwindcss.setup({ - capabilities = capabilities, - }) - lspconfig.cssls.setup({ - capabilities = capabilities, - settings = { - css = { - lint = { - unknownAtRules = "ignore", - }, - }, - scss = { - lint = { - unknownAtRules = "ignore", - }, - }, - less = { - lint = { - unknownAtRules = "ignore", - }, - }, - }, - }) - lspconfig.sourcekit.setup({ - capabilities = capabilities, - }) - lspconfig.tinymist.setup({ - capabilities = capabilities, - }) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, {}) - vim.keymap.set("n", "K", vim.lsp.buf.hover, {}) - vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, {}) + local mason_lspconfig = require("mason-lspconfig") + local mason_servers = mason_lspconfig.get_installed_servers() + + local manual_servers = { + "sourcekit", + } + + for _, server in ipairs(vim.tbl_extend("force", mason_servers, manual_servers)) do + lspconfig[server].setup({ + capabilities = capabilities, + }) + end + + local map = vim.keymap.set + map("n", "gd", vim.lsp.buf.definition, {}) + map("n", "K", vim.lsp.buf.hover, {}) + map({ "n", "v" }, "ca", vim.lsp.buf.code_action, {}) vim.diagnostic.config({ virtual_text = true, diff --git a/lua/vim-options.lua b/lua/vim-options.lua index a603947..67685a2 100644 --- a/lua/vim-options.lua +++ b/lua/vim-options.lua @@ -15,32 +15,32 @@ vim.keymap.set("n", "k", "gk", { noremap = true, silent = true }) vim.keymap.set("v", "j", "gj", { noremap = true, silent = true }) vim.keymap.set("v", "k", "gk", { noremap = true, silent = true }) --- Spellchecker -vim.api.nvim_create_autocmd("FileType", { - callback = function() - local buftype = vim.api.nvim_buf_get_option(0, "buftype") - local filetype = vim.api.nvim_buf_get_option(0, "filetype") - - local skip_buftypes = { "nofile", "prompt", "terminal" } - local skip_filetypes = { "cmp_menu", "cmp_doc", "TelescopePrompt", "NvimTree" } - - -- If current buffer is in skip list, do nothing - for _, bt in ipairs(skip_buftypes) do - if buftype == bt then - return - end - end - for _, ft in ipairs(skip_filetypes) do - if filetype == ft then - return - end - end - - -- Else, enable spellcheck - vim.opt_local.spell = true - vim.opt_local.spelllang = "en" - end, -}) +-- -- Spellchecker +-- vim.api.nvim_create_autocmd("FileType", { +-- callback = function() +-- local buftype = vim.api.nvim_buf_get_option(0, "buftype") +-- local filetype = vim.api.nvim_buf_get_option(0, "filetype") +-- +-- local skip_buftypes = { "nofile", "prompt", "terminal" } +-- local skip_filetypes = { "cmp_menu", "cmp_doc", "TelescopePrompt", "NvimTree" } +-- +-- -- If current buffer is in skip list, do nothing +-- for _, bt in ipairs(skip_buftypes) do +-- if buftype == bt then +-- return +-- end +-- end +-- for _, ft in ipairs(skip_filetypes) do +-- if filetype == ft then +-- return +-- end +-- end +-- +-- -- Else, enable spellcheck +-- vim.opt_local.spell = true +-- vim.opt_local.spelllang = "en" +-- end, +-- }) -- Toggle spell check with sc vim.keymap.set("n", "sc", function()