mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-21 20:11:06 +00:00
refactor: remove all <0.11 compat code
This commit is contained in:
parent
3516ae736a
commit
a7a94c50ac
13 changed files with 40 additions and 144 deletions
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -209,13 +209,3 @@ map("n", "<leader><tab><tab>", "<cmd>tabnew<cr>", { desc = "New Tab" })
|
|||
map("n", "<leader><tab>]", "<cmd>tabnext<cr>", { desc = "Next Tab" })
|
||||
map("n", "<leader><tab>d", "<cmd>tabclose<cr>", { desc = "Close Tab" })
|
||||
map("n", "<leader><tab>[", "<cmd>tabprevious<cr>", { 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", "<Tab>", function()
|
||||
return vim.snippet.active({ direction = 1 }) and "<cmd>lua vim.snippet.jump(1)<cr>" or "<Tab>"
|
||||
end, { expr = true, desc = "Jump Next" })
|
||||
map({ "i", "s" }, "<S-Tab>", function()
|
||||
return vim.snippet.active({ direction = -1 }) and "<cmd>lua vim.snippet.jump(-1)<cr>" or "<S-Tab>"
|
||||
end, { expr = true, desc = "Jump Previous" })
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ return {
|
|||
|
||||
{
|
||||
"mrcjkb/rustaceanvim",
|
||||
version = vim.fn.has("nvim-0.10.0") == 0 and "^4" or false,
|
||||
ft = { "rust" },
|
||||
opts = {
|
||||
server = {
|
||||
|
|
|
|||
|
|
@ -31,11 +31,6 @@ return {
|
|||
desc = "Organize Imports",
|
||||
},
|
||||
},
|
||||
capabilities = {
|
||||
workspace = {
|
||||
didChangeWatchedFiles = vim.fn.has("nvim-0.10") == 0 and { dynamicRegistration = true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue