From a7a94c50ac1ae5e791ce88fab455d5c6edee385e Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 15 Sep 2025 11:16:51 +0200 Subject: [PATCH] refactor: remove all <0.11 compat code --- lua/lazyvim/config/init.lua | 2 +- lua/lazyvim/config/keymaps.lua | 10 --- lua/lazyvim/config/options.lua | 14 ++-- lua/lazyvim/health.lua | 9 +-- lua/lazyvim/plugins/extras/editor/navic.lua | 2 +- lua/lazyvim/plugins/extras/lang/ruby.lua | 4 -- lua/lazyvim/plugins/extras/lang/rust.lua | 1 - lua/lazyvim/plugins/extras/lang/svelte.lua | 5 -- .../plugins/extras/lang/typescript.lua | 4 +- lua/lazyvim/plugins/extras/lang/yaml.lua | 10 --- lua/lazyvim/plugins/lsp/init.lua | 64 ++++++++----------- lua/lazyvim/util/lsp.lua | 54 ++-------------- lua/lazyvim/util/ui.lua | 5 -- 13 files changed, 40 insertions(+), 144 deletions(-) diff --git a/lua/lazyvim/config/init.lua b/lua/lazyvim/config/init.lua index d622dfdf..9e0903c2 100644 --- a/lua/lazyvim/config/init.lua +++ b/lua/lazyvim/config/init.lua @@ -353,7 +353,7 @@ function M.get_defaults() { name = "telescope", extra = "editor.telescope" }, }, cmp = { - { name = "blink.cmp", extra = "coding.blink", enabled = vim.fn.has("nvim-0.10") == 1 }, + { name = "blink.cmp", extra = "coding.blink" }, { name = "nvim-cmp", extra = "coding.nvim-cmp" }, }, explorer = { diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index fbc7f5d1..acaf44d9 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -209,13 +209,3 @@ map("n", "", "tabnew", { desc = "New Tab" }) map("n", "]", "tabnext", { desc = "Next Tab" }) map("n", "d", "tabclose", { desc = "Close Tab" }) map("n", "[", "tabprevious", { desc = "Previous Tab" }) - --- native snippets. only needed on < 0.11, as 0.11 creates these by default -if vim.fn.has("nvim-0.11") == 0 then - map("s", "", function() - return vim.snippet.active({ direction = 1 }) and "lua vim.snippet.jump(1)" or "" - end, { expr = true, desc = "Jump Next" }) - map({ "i", "s" }, "", function() - return vim.snippet.active({ direction = -1 }) and "lua vim.snippet.jump(-1)" or "" - end, { expr = true, desc = "Jump Previous" }) -end diff --git a/lua/lazyvim/config/options.lua b/lua/lazyvim/config/options.lua index 0bbaacba..b5d444d0 100644 --- a/lua/lazyvim/config/options.lua +++ b/lua/lazyvim/config/options.lua @@ -68,7 +68,10 @@ opt.fillchars = { diff = "╱", eob = " ", } +opt.foldexpr = "v:lua.require'lazyvim.util'.ui.foldexpr()" opt.foldlevel = 99 +opt.foldmethod = "expr" +opt.foldtext = "" opt.formatexpr = "v:lua.require'lazyvim.util'.format.formatexpr()" opt.formatoptions = "jcroqlnt" -- tcqj opt.grepformat = "%f:%l:%c:%m" @@ -95,6 +98,7 @@ opt.sidescrolloff = 8 -- Columns of context opt.signcolumn = "yes" -- Always show the signcolumn, otherwise it would shift the text each time opt.smartcase = true -- Don't ignore case with capitals opt.smartindent = true -- Insert indents automatically +opt.smoothscroll = true opt.spelllang = { "en" } opt.splitbelow = true -- Put new windows below current opt.splitkeep = "screen" @@ -111,15 +115,5 @@ opt.wildmode = "longest:full,full" -- Command-line completion mode opt.winminwidth = 5 -- Minimum window width opt.wrap = false -- Disable line wrap -if vim.fn.has("nvim-0.10") == 1 then - opt.smoothscroll = true - opt.foldexpr = "v:lua.require'lazyvim.util'.ui.foldexpr()" - opt.foldmethod = "expr" - opt.foldtext = "" -else - opt.foldmethod = "indent" - opt.foldtext = "v:lua.require'lazyvim.util'.ui.foldtext()" -end - -- Fix markdown indentation settings vim.g.markdown_recommended_style = 0 diff --git a/lua/lazyvim/health.lua b/lua/lazyvim/health.lua index 9fdc5a56..716c60a8 100644 --- a/lua/lazyvim/health.lua +++ b/lua/lazyvim/health.lua @@ -8,13 +8,10 @@ local error = vim.health.error or vim.health.report_error function M.check() start("LazyVim") - if vim.fn.has("nvim-0.9.0") == 1 then - ok("Using Neovim >= 0.9.0") - if vim.fn.has("nvim-0.10.0") == 0 then - warn("Use Neovim >= 0.10.0 for the best experience") - end + if vim.fn.has("nvim-0.11.0") == 1 then + ok("Using Neovim >= 0.11.0") else - error("Neovim >= 0.9.0 is required") + error("Neovim >= 0.11.0 is required") end for _, cmd in ipairs({ "git", "rg", { "fd", "fdfind" }, "lazygit", "fzf", "curl" }) do diff --git a/lua/lazyvim/plugins/extras/editor/navic.lua b/lua/lazyvim/plugins/extras/editor/navic.lua index e25d1b51..91ec203c 100644 --- a/lua/lazyvim/plugins/extras/editor/navic.lua +++ b/lua/lazyvim/plugins/extras/editor/navic.lua @@ -8,7 +8,7 @@ return { init = function() vim.g.navic_silence = true LazyVim.lsp.on_attach(function(client, buffer) - if client.supports_method("textDocument/documentSymbol") then + if client:supports_method("textDocument/documentSymbol") then require("nvim-navic").attach(client, buffer) end end) diff --git a/lua/lazyvim/plugins/extras/lang/ruby.lua b/lua/lazyvim/plugins/extras/lang/ruby.lua index 4224e6d8..65620f4e 100644 --- a/lua/lazyvim/plugins/extras/lang/ruby.lua +++ b/lua/lazyvim/plugins/extras/lang/ruby.lua @@ -6,10 +6,6 @@ if lazyvim_docs then end local lsp = vim.g.lazyvim_ruby_lsp or "ruby_lsp" -if vim.fn.has("nvim-0.10") == 0 then - -- ruby_lsp does not work well with Neovim < 0.10 - lsp = vim.g.lazyvim_ruby_lsp or "solargraph" -end local formatter = vim.g.lazyvim_ruby_formatter or "rubocop" return { diff --git a/lua/lazyvim/plugins/extras/lang/rust.lua b/lua/lazyvim/plugins/extras/lang/rust.lua index 0adddf18..eca1b597 100644 --- a/lua/lazyvim/plugins/extras/lang/rust.lua +++ b/lua/lazyvim/plugins/extras/lang/rust.lua @@ -56,7 +56,6 @@ return { { "mrcjkb/rustaceanvim", - version = vim.fn.has("nvim-0.10.0") == 0 and "^4" or false, ft = { "rust" }, opts = { server = { diff --git a/lua/lazyvim/plugins/extras/lang/svelte.lua b/lua/lazyvim/plugins/extras/lang/svelte.lua index 565e50e5..4060e2f3 100644 --- a/lua/lazyvim/plugins/extras/lang/svelte.lua +++ b/lua/lazyvim/plugins/extras/lang/svelte.lua @@ -31,11 +31,6 @@ return { desc = "Organize Imports", }, }, - capabilities = { - workspace = { - didChangeWatchedFiles = vim.fn.has("nvim-0.10") == 0 and { dynamicRegistration = true }, - }, - }, }, }, }, diff --git a/lua/lazyvim/plugins/extras/lang/typescript.lua b/lua/lazyvim/plugins/extras/lang/typescript.lua index f7cc3231..f9132807 100644 --- a/lua/lazyvim/plugins/extras/lang/typescript.lua +++ b/lua/lazyvim/plugins/extras/lang/typescript.lua @@ -137,14 +137,14 @@ return { local action, uri, range = unpack(command.arguments) local function move(newf) - client.request("workspace/executeCommand", { + client:request("workspace/executeCommand", { command = command.command, arguments = { action, uri, range, newf }, }) end local fname = vim.uri_to_fname(uri) - client.request("workspace/executeCommand", { + client:request("workspace/executeCommand", { command = "typescript.tsserverRequest", arguments = { "getMoveToRefactoringFileSuggestions", diff --git a/lua/lazyvim/plugins/extras/lang/yaml.lua b/lua/lazyvim/plugins/extras/lang/yaml.lua index 9a3aadb8..b460f3c5 100644 --- a/lua/lazyvim/plugins/extras/lang/yaml.lua +++ b/lua/lazyvim/plugins/extras/lang/yaml.lua @@ -55,16 +55,6 @@ return { }, }, }, - setup = { - yamlls = function() - -- Neovim < 0.10 does not have dynamic registration for formatting - if vim.fn.has("nvim-0.10") == 0 then - LazyVim.lsp.on_attach(function(client, _) - client.server_capabilities.documentFormattingProvider = true - end, "yamlls") - end - end, - }, }, }, } diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index b5cba5f1..54f410fc 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -125,53 +125,39 @@ return { LazyVim.lsp.setup() LazyVim.lsp.on_dynamic_capability(require("lazyvim.plugins.lsp.keymaps").on_attach) - -- diagnostics signs - if vim.fn.has("nvim-0.10.0") == 0 then - if type(opts.diagnostics.signs) ~= "boolean" then - for severity, icon in pairs(opts.diagnostics.signs.text) do - local name = vim.diagnostic.severity[severity]:lower():gsub("^%l", string.upper) - name = "DiagnosticSign" .. name - vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" }) + -- inlay hints + if opts.inlay_hints.enabled then + LazyVim.lsp.on_supports_method("textDocument/inlayHint", function(client, buffer) + if + vim.api.nvim_buf_is_valid(buffer) + and vim.bo[buffer].buftype == "" + and not vim.tbl_contains(opts.inlay_hints.exclude, vim.bo[buffer].filetype) + then + vim.lsp.inlay_hint.enable(true, { bufnr = buffer }) end - end + end) end - if vim.fn.has("nvim-0.10") == 1 then - -- inlay hints - if opts.inlay_hints.enabled then - LazyVim.lsp.on_supports_method("textDocument/inlayHint", function(client, buffer) - if - vim.api.nvim_buf_is_valid(buffer) - and vim.bo[buffer].buftype == "" - and not vim.tbl_contains(opts.inlay_hints.exclude, vim.bo[buffer].filetype) - then - vim.lsp.inlay_hint.enable(true, { bufnr = buffer }) - end - end) - end - - -- code lens - if opts.codelens.enabled and vim.lsp.codelens then - LazyVim.lsp.on_supports_method("textDocument/codeLens", function(client, buffer) - vim.lsp.codelens.refresh() - vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "InsertLeave" }, { - buffer = buffer, - callback = vim.lsp.codelens.refresh, - }) - end) - end + -- code lens + if opts.codelens.enabled and vim.lsp.codelens then + LazyVim.lsp.on_supports_method("textDocument/codeLens", function(client, buffer) + vim.lsp.codelens.refresh() + vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "InsertLeave" }, { + buffer = buffer, + callback = vim.lsp.codelens.refresh, + }) + end) end if type(opts.diagnostics.virtual_text) == "table" and opts.diagnostics.virtual_text.prefix == "icons" then - opts.diagnostics.virtual_text.prefix = vim.fn.has("nvim-0.10.0") == 0 and "●" - or function(diagnostic) - local icons = LazyVim.config.icons.diagnostics - for d, icon in pairs(icons) do - if diagnostic.severity == vim.diagnostic.severity[d:upper()] then - return icon - end + opts.diagnostics.virtual_text.prefix = function(diagnostic) + local icons = LazyVim.config.icons.diagnostics + for d, icon in pairs(icons) do + if diagnostic.severity == vim.diagnostic.severity[d:upper()] then + return icon end end + end end vim.diagnostic.config(vim.deepcopy(opts.diagnostics)) diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua index 51aa471a..02ab8b6e 100644 --- a/lua/lazyvim/util/lsp.lua +++ b/lua/lazyvim/util/lsp.lua @@ -3,56 +3,10 @@ local M = {} ---@alias lsp.Client.filter {id?: number, bufnr?: number, name?: string, method?: string, filter?:fun(client: vim.lsp.Client):boolean} ---- Neovim 0.11 uses a lua class for clients, while older versions use a table. ---- Wraps older style clients to be compatible with the new style. ----@param client vim.lsp.Client ----@return vim.lsp.Client -local function wrap(client) - local meta = getmetatable(client) - if meta and meta.request then - return client - end - ---@diagnostic disable-next-line: undefined-field - if client.wrapped then - return client - end - local methods = { "request", "supports_method", "cancel_request", "notify" } - -- old style - return setmetatable({ wrapped = true }, { - __index = function(_, k) - if k == "supports_method" then - -- supports_method doesn't support the bufnr argument - return function(_, method) - return client[k](method) - end - end - if vim.tbl_contains(methods, k) then - return function(_, ...) - return client[k](...) - end - end - return client[k] - end, - }) -end - ---@param opts? lsp.Client.filter function M.get_clients(opts) local ret = {} ---@type vim.lsp.Client[] - if vim.lsp.get_clients then - ret = vim.lsp.get_clients(opts) - ret = vim.tbl_map(wrap, ret) - else - ---@diagnostic disable-next-line: deprecated - ret = vim.lsp.get_active_clients(opts) - ret = vim.tbl_map(wrap, ret) - if opts and opts.method then - ---@param client vim.lsp.Client - ret = vim.tbl_filter(function(client) - return client.supports_method(opts.method, { bufnr = opts.bufnr }) - end, ret) - end - end + ret = vim.lsp.get_clients(opts) return opts and opts.filter and vim.tbl_filter(opts.filter, ret) or ret end @@ -64,7 +18,7 @@ function M.on_attach(on_attach, name) local buffer = args.buf ---@type number local client = vim.lsp.get_client_by_id(args.data.client_id) if client and (not name or client.name == name) then - return on_attach(wrap(client), buffer) + return on_attach(client, buffer) end end, }) @@ -204,8 +158,8 @@ function M.formatter(opts) local clients = M.get_clients(LazyVim.merge({}, filter, { bufnr = buf })) ---@param client vim.lsp.Client local ret = vim.tbl_filter(function(client) - return client.supports_method("textDocument/formatting") - or client.supports_method("textDocument/rangeFormatting") + return client:supports_method("textDocument/formatting") + or client:supports_method("textDocument/rangeFormatting") end, clients) ---@param client vim.lsp.Client return vim.tbl_map(function(client) diff --git a/lua/lazyvim/util/ui.lua b/lua/lazyvim/util/ui.lua index 3460b0ab..c8c899d5 100644 --- a/lua/lazyvim/util/ui.lua +++ b/lua/lazyvim/util/ui.lua @@ -1,11 +1,6 @@ ---@class lazyvim.util.ui local M = {} --- foldtext for Neovim < 0.10.0 -function M.foldtext() - return vim.api.nvim_buf_get_lines(0, vim.v.lnum - 1, vim.v.lnum, false)[1] -end - -- optimized treesitter foldexpr for Neovim >= 0.10.0 function M.foldexpr() local buf = vim.api.nvim_get_current_buf()