From 3f0cd7546940beb1283ef1442a944d10c48a8431 Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Wed, 16 Apr 2025 19:32:25 +0200 Subject: [PATCH 01/12] feat: add support for new LSP config API in Neovim 0.11+ --- init.lua | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/init.lua b/init.lua index 776c6873..946ab698 100644 --- a/init.lua +++ b/init.lua @@ -711,20 +711,34 @@ require('lazy').setup({ }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } - require('mason-lspconfig').setup { - ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) - automatic_installation = false, - handlers = { - function(server_name) - local server = servers[server_name] or {} - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for ts_ls) - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - require('lspconfig')[server_name].setup(server) - end, - }, - } + -- Handle lsp setups differently based on Neovim version + -- See :help vim.lsp.config and :help vim.lsp.enable for Neovim 0.11+ + if vim.fn.has 'nvim-0.11' == 1 then + for server, config in pairs(servers) do + -- This handles overriding only values explicitly passed + -- by the server configuration above. Useful when disabling + -- certain features of an LSP (for example, turning off formatting for ts_ls) + config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + vim.lsp.config(name, config) + vim.lsp.enable(name) + end + else + -- For Neovim 0.10 and below, use mason-lspconfig for setup + require('mason-lspconfig').setup { + ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) + automatic_installation = false, + handlers = { + function(server_name) + local server = servers[server_name] or {} + -- This handles overriding only values explicitly passed + -- by the server configuration above. Useful when disabling + -- certain features of an LSP (for example, turning off formatting for ts_ls) + server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + require('lspconfig')[server_name].setup(server) + end, + }, + } + end end, }, From f70dcb337399831a93ec7434dcc23e18491337e3 Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Wed, 16 Apr 2025 19:42:03 +0200 Subject: [PATCH 02/12] Typo fix --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 946ab698..69d3834a 100644 --- a/init.lua +++ b/init.lua @@ -718,7 +718,7 @@ require('lazy').setup({ -- This handles overriding only values explicitly passed -- by the server configuration above. Useful when disabling -- certain features of an LSP (for example, turning off formatting for ts_ls) - config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) + config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {}) vim.lsp.config(name, config) vim.lsp.enable(name) end From 4b819009392786f5c0f76a5846c18964aa0aa967 Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Thu, 17 Apr 2025 17:17:26 +0200 Subject: [PATCH 03/12] fix(lsp): correct variable name in lsp config loop Signed-off-by: Umut Sahin Onder --- init.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index 69d3834a..bdcb9805 100644 --- a/init.lua +++ b/init.lua @@ -290,7 +290,7 @@ require('lazy').setup({ -- Then, because we use the `opts` key (recommended), the configuration runs -- after the plugin has been loaded as `require(MODULE).setup(opts)`. - { -- Useful plugin to show you pending keybinds. + { -- Useful plugin to show you pending keybinds. 'folke/which-key.nvim', event = 'VimEnter', -- Sets the loading event to 'VimEnter' opts = { @@ -371,7 +371,7 @@ require('lazy').setup({ { 'nvim-telescope/telescope-ui-select.nvim' }, -- Useful for getting pretty icons, but requires a Nerd Font. - { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, }, config = function() -- Telescope is a fuzzy finder that comes with a lot of different things that @@ -479,7 +479,7 @@ require('lazy').setup({ 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Useful status updates for LSP. - { 'j-hui/fidget.nvim', opts = {} }, + { 'j-hui/fidget.nvim', opts = {} }, -- Allows extra capabilities provided by blink.cmp 'saghen/blink.cmp', @@ -719,8 +719,8 @@ require('lazy').setup({ -- by the server configuration above. Useful when disabling -- certain features of an LSP (for example, turning off formatting for ts_ls) config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {}) - vim.lsp.config(name, config) - vim.lsp.enable(name) + vim.lsp.config(server, config) + vim.lsp.enable(server) end else -- For Neovim 0.10 and below, use mason-lspconfig for setup From 5502cea3f66d7acd58233e653916cc76b8bde47f Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Thu, 17 Apr 2025 17:22:08 +0200 Subject: [PATCH 04/12] style: format with stylua --- init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index bdcb9805..39839617 100644 --- a/init.lua +++ b/init.lua @@ -290,7 +290,7 @@ require('lazy').setup({ -- Then, because we use the `opts` key (recommended), the configuration runs -- after the plugin has been loaded as `require(MODULE).setup(opts)`. - { -- Useful plugin to show you pending keybinds. + { -- Useful plugin to show you pending keybinds. 'folke/which-key.nvim', event = 'VimEnter', -- Sets the loading event to 'VimEnter' opts = { @@ -371,7 +371,7 @@ require('lazy').setup({ { 'nvim-telescope/telescope-ui-select.nvim' }, -- Useful for getting pretty icons, but requires a Nerd Font. - { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, + { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font }, }, config = function() -- Telescope is a fuzzy finder that comes with a lot of different things that @@ -479,7 +479,7 @@ require('lazy').setup({ 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Useful status updates for LSP. - { 'j-hui/fidget.nvim', opts = {} }, + { 'j-hui/fidget.nvim', opts = {} }, -- Allows extra capabilities provided by blink.cmp 'saghen/blink.cmp', From a590ab6c8812ade054cf0f444ee53c1b0daa98a3 Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Sun, 20 Apr 2025 12:58:24 +0200 Subject: [PATCH 05/12] fix(lsp): Remove backwards compatibility and add comments for lsp setup --- init.lua | 57 ++++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/init.lua b/init.lua index 39839617..bde5d4ff 100644 --- a/init.lua +++ b/init.lua @@ -647,12 +647,6 @@ require('lazy').setup({ }, } - -- LSP servers and clients are able to communicate to each other what features they support. - -- By default, Neovim doesn't support everything that is in the LSP specification. - -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. - -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers. - local capabilities = require('blink.cmp').get_lsp_capabilities() - -- Enable the following language servers -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. -- @@ -711,34 +705,31 @@ require('lazy').setup({ }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } - -- Handle lsp setups differently based on Neovim version - -- See :help vim.lsp.config and :help vim.lsp.enable for Neovim 0.11+ - if vim.fn.has 'nvim-0.11' == 1 then - for server, config in pairs(servers) do - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for ts_ls) - config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {}) - vim.lsp.config(server, config) - vim.lsp.enable(server) - end - else - -- For Neovim 0.10 and below, use mason-lspconfig for setup - require('mason-lspconfig').setup { - ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) - automatic_installation = false, - handlers = { - function(server_name) - local server = servers[server_name] or {} - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for ts_ls) - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - require('lspconfig')[server_name].setup(server) - end, - }, - } + -- Handle LSP setups + -- See :help vim.lsp.enable + for server, config in pairs(servers) do + vim.lsp.config(server, config) + vim.lsp.enable(server) end + -- NOTE: Some servers still require the nvim-lspconfig setup until they are updated + -- Use this template inside the for loop if you encounter issues with an lsp + -- + -- if server == 'example_server' or server == 'example_server2' then + -- -- This handles overriding only values explicitly passed + -- -- by the server configuration above. Useful when disabling + -- -- certain features of an LSP (for example, turning off formatting for ts_ls) + -- local capabilities = require('blink.cmp').get_lsp_capabilities() + -- config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {}) + -- require('mason-lspconfig')[server_name].setup(config) + -- else + -- vim.lsp.config(server, config) + -- vim.lsp.enable(server) + -- end + -- + -- LSP servers and clients are able to communicate to each other what features they support. + -- With nvim-lspconfig setup, Neovim doesn't support everything that is in the LSP specification. + -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. + -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers. end, }, From dac395dac6ae1612c77a61811b41fa95d123fe42 Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Sun, 20 Apr 2025 13:12:00 +0200 Subject: [PATCH 06/12] fix: Typo in comment --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index bde5d4ff..3f09b9ce 100644 --- a/init.lua +++ b/init.lua @@ -720,7 +720,7 @@ require('lazy').setup({ -- -- certain features of an LSP (for example, turning off formatting for ts_ls) -- local capabilities = require('blink.cmp').get_lsp_capabilities() -- config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {}) - -- require('mason-lspconfig')[server_name].setup(config) + -- require('mason-lspconfig')[server].setup(config) -- else -- vim.lsp.config(server, config) -- vim.lsp.enable(server) From 531073d8b258774ed6f05a549ea1846d24451de9 Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Mon, 21 Apr 2025 20:02:43 +0200 Subject: [PATCH 07/12] fix: revert back to original handler logic --- init.lua | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/init.lua b/init.lua index 3f09b9ce..81bc4975 100644 --- a/init.lua +++ b/init.lua @@ -705,14 +705,19 @@ require('lazy').setup({ }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } - -- Handle LSP setups - -- See :help vim.lsp.enable - for server, config in pairs(servers) do - vim.lsp.config(server, config) - vim.lsp.enable(server) - end + require('mason-lspconfig').setup { + ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) + automatic_installation = false, + handlers = { + function(server_name) + local config = servers[server_name] or {} + vim.lsp.config(server_name, config) + vim.lsp.enable(server_name) + end, + }, + } -- NOTE: Some servers still require the nvim-lspconfig setup until they are updated - -- Use this template inside the for loop if you encounter issues with an lsp + -- Add this template inside the handler function after initializing config if you encounter issues with any lsp -- -- if server == 'example_server' or server == 'example_server2' then -- -- This handles overriding only values explicitly passed @@ -721,12 +726,10 @@ require('lazy').setup({ -- local capabilities = require('blink.cmp').get_lsp_capabilities() -- config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {}) -- require('mason-lspconfig')[server].setup(config) - -- else - -- vim.lsp.config(server, config) - -- vim.lsp.enable(server) + -- return -- end -- - -- LSP servers and clients are able to communicate to each other what features they support. + -- LSP servers and clients are able to communicate to each other what features they support. -- With nvim-lspconfig setup, Neovim doesn't support everything that is in the LSP specification. -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers. From 81c5210cb57f2127f323d5f6b2dae44bc74374b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Umut=20=C3=96nder?= <93402298+umutondersu@users.noreply.github.com> Date: Wed, 30 Apr 2025 17:01:57 +0200 Subject: [PATCH 08/12] Fix: correct variables inside comments Co-authored-by: Rory Hendrickson <35480205+roryhen@users.noreply.github.com> --- init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 81bc4975..44199aeb 100644 --- a/init.lua +++ b/init.lua @@ -719,13 +719,13 @@ require('lazy').setup({ -- NOTE: Some servers still require the nvim-lspconfig setup until they are updated -- Add this template inside the handler function after initializing config if you encounter issues with any lsp -- - -- if server == 'example_server' or server == 'example_server2' then + -- if server_name == 'example_server' or server_name == 'example_server2' then -- -- This handles overriding only values explicitly passed -- -- by the server configuration above. Useful when disabling -- -- certain features of an LSP (for example, turning off formatting for ts_ls) -- local capabilities = require('blink.cmp').get_lsp_capabilities() -- config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {}) - -- require('mason-lspconfig')[server].setup(config) + -- require('mason-lspconfig')[server_name].setup(config) -- return -- end -- From 9e0c7b634181070aeffc250c0a4852e37732e5a4 Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Sat, 10 May 2025 17:20:20 +0200 Subject: [PATCH 09/12] fix(deps): pin mason plugin versions to v1.* --- init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 44199aeb..2c1a01c4 100644 --- a/init.lua +++ b/init.lua @@ -474,8 +474,8 @@ require('lazy').setup({ -- Automatically install LSPs and related tools to stdpath for Neovim -- Mason must be loaded before its dependents so we need to set it up here. -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})` - { 'williamboman/mason.nvim', opts = {} }, - 'williamboman/mason-lspconfig.nvim', + { 'williamboman/mason.nvim', version = 'v1.*', opts = {} }, + { 'williamboman/mason-lspconfig.nvim', version = 'v1.*' }, 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Useful status updates for LSP. From 0018683a23d1d8256b590730a46727523fceb03e Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Sun, 11 May 2025 15:18:53 +0200 Subject: [PATCH 10/12] feat(lsp): Update Mason to v2 --- init.lua | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/init.lua b/init.lua index 2c1a01c4..867c6bc9 100644 --- a/init.lua +++ b/init.lua @@ -474,8 +474,8 @@ require('lazy').setup({ -- Automatically install LSPs and related tools to stdpath for Neovim -- Mason must be loaded before its dependents so we need to set it up here. -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})` - { 'williamboman/mason.nvim', version = 'v1.*', opts = {} }, - { 'williamboman/mason-lspconfig.nvim', version = 'v1.*' }, + { 'williamboman/mason.nvim', opts = {} }, + { 'williamboman/mason-lspconfig.nvim', opts = {} }, 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Useful status updates for LSP. @@ -705,34 +705,14 @@ require('lazy').setup({ }) require('mason-tool-installer').setup { ensure_installed = ensure_installed } - require('mason-lspconfig').setup { - ensure_installed = {}, -- explicitly set to an empty table (Kickstart populates installs via mason-tool-installer) - automatic_installation = false, - handlers = { - function(server_name) - local config = servers[server_name] or {} - vim.lsp.config(server_name, config) - vim.lsp.enable(server_name) - end, - }, - } - -- NOTE: Some servers still require the nvim-lspconfig setup until they are updated - -- Add this template inside the handler function after initializing config if you encounter issues with any lsp - -- - -- if server_name == 'example_server' or server_name == 'example_server2' then - -- -- This handles overriding only values explicitly passed - -- -- by the server configuration above. Useful when disabling - -- -- certain features of an LSP (for example, turning off formatting for ts_ls) - -- local capabilities = require('blink.cmp').get_lsp_capabilities() - -- config.capabilities = vim.tbl_deep_extend('force', {}, capabilities, config.capabilities or {}) - -- require('mason-lspconfig')[server_name].setup(config) - -- return - -- end - -- - -- LSP servers and clients are able to communicate to each other what features they support. - -- With nvim-lspconfig setup, Neovim doesn't support everything that is in the LSP specification. - -- When you add blink.cmp, luasnip, etc. Neovim now has *more* capabilities. - -- So, we create new capabilities with blink.cmp, and then broadcast that to the servers. + -- Installed LSPs are configured and enabled automatically with mason-lspconfig + -- The loop below is for overriding the default configuration of LSPs with the ones in the servers table + for server_name, config in pairs(servers) do + vim.lsp.config(server_name, config) + end + + -- NOTE: Some servers may require an old setup until they are updated. For the full list refer here: https://github.com/neovim/nvim-lspconfig/issues/3705 + -- These servers will have to be manually set up with require("lspconfig").server_name.setup{} end, }, From 718c90d2248cbf94060b2991c656942a22acd32a Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Sun, 11 May 2025 16:16:14 +0200 Subject: [PATCH 11/12] fix: mason server name --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 6cb25dd5..6ca67b50 100644 --- a/init.lua +++ b/init.lua @@ -482,7 +482,7 @@ require('lazy').setup({ -- Automatically install LSPs and related tools to stdpath for Neovim -- Mason must be loaded before its dependents so we need to set it up here. -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})` - { 'mason-orgmason.nvim', opts = {} }, + { 'mason-org/mason.nvim', opts = {} }, { 'mason-org/mason-lspconfig.nvim', opts = {} }, 'WhoIsSethDaniel/mason-tool-installer.nvim', From 82949b8a263631fd2884a9f57e01a3390e8084f2 Mon Sep 17 00:00:00 2001 From: Umut Sahin Onder Date: Sat, 17 May 2025 13:56:36 +0200 Subject: [PATCH 12/12] Refactor(lsp): Ensure automatic server enabling --- init.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 6ca67b50..c214f9c2 100644 --- a/init.lua +++ b/init.lua @@ -483,7 +483,7 @@ require('lazy').setup({ -- Mason must be loaded before its dependents so we need to set it up here. -- NOTE: `opts = {}` is the same as calling `require('mason').setup({})` { 'mason-org/mason.nvim', opts = {} }, - { 'mason-org/mason-lspconfig.nvim', opts = {} }, + 'mason-org/mason-lspconfig.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim', -- Useful status updates for LSP. @@ -693,6 +693,11 @@ require('lazy').setup({ }, }, } + ---@type MasonLspconfigSettings + ---@diagnostic disable-next-line: missing-fields + require('mason-lspconfig').setup { + automatic_enable = vim.tbl_keys(servers or {}), + } -- Ensure the servers and tools above are installed --