fix: added compatibility with Neovim >= 0.9.4

This commit is contained in:
Folke Lemaitre 2024-11-09 15:38:40 +01:00
parent 18686a41ff
commit 4f99818b0a
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
7 changed files with 39 additions and 23 deletions

View file

@ -6,6 +6,8 @@ local M = setmetatable({}, {
end,
})
local uv = vim.uv or vim.loop
-- Show a notification with a pretty printed dump of the object(s)
-- with lua treesitter highlighting and the location of the caller
function M.inspect(...)
@ -52,14 +54,14 @@ end
---@param opts? {count?: number, flush?: boolean}
function M.profile(fn, opts)
opts = vim.tbl_extend("force", { count = 100, flush = true }, opts or {})
local start = vim.uv.hrtime()
local start = uv.hrtime()
for _ = 1, opts.count, 1 do
if opts.flush then
jit.flush(fn, true)
end
fn()
end
Snacks.notify(((vim.uv.hrtime() - start) / 1e6 / opts.count) .. "ms")
Snacks.notify(((uv.hrtime() - start) / 1e6 / opts.count) .. "ms")
end
-- Log a message to the file `./debug.log`.

View file

@ -6,6 +6,8 @@ local M = setmetatable({}, {
end,
})
local uv = vim.uv or vim.loop
---@class snacks.gitbrowse.Config
local defaults = {
-- Handler to open the url in a browser
@ -74,12 +76,12 @@ end
---@param cmd string[]
---@param err string
local function system(cmd, err)
local proc = vim.system(cmd, { text = true }):wait()
if proc.code ~= 0 then
Snacks.notify.error({ err, proc.stderr, proc.stdout }, { title = "Git Browse" })
local proc = vim.fn.system(cmd)
if vim.v.shell_error ~= 0 then
Snacks.notify.error({ err, proc }, { title = "Git Browse" })
error(err)
end
return vim.split(vim.trim(proc.stdout), "\n")
return vim.split(vim.trim(proc), "\n")
end
---@param opts? snacks.gitbrowse.Config
@ -91,7 +93,7 @@ end
function M._open(opts)
opts = Snacks.config.get("gitbrowse", defaults, opts)
local file = vim.api.nvim_buf_get_name(0) ---@type string?
file = file and (vim.uv.fs_stat(file) or {}).type == "file" and vim.fs.normalize(file) or nil
file = file and (uv.fs_stat(file) or {}).type == "file" and vim.fs.normalize(file) or nil
local cwd = file and vim.fn.fnamemodify(file, ":h") or vim.fn.getcwd()
local fields = {
branch = system({ "git", "-C", cwd, "rev-parse", "--abbrev-ref", "HEAD" }, "Failed to get current branch")[1],

View file

@ -82,6 +82,10 @@ end
function M.setup(opts)
config = vim.tbl_deep_extend("force", config, opts or {})
if vim.fn.has("nvim-0.9.4") ~= 1 then
return vim.notify("snacks.nvim requires Neovim >= 0.9.4", vim.log.levels.ERROR, { title = "snacks.nvim" })
end
local group = vim.api.nvim_create_augroup("snacks", { clear = true })
local events = {

View file

@ -6,6 +6,8 @@ local M = setmetatable({}, {
end,
})
local uv = vim.uv or vim.loop
---@alias snacks.lazygit.Color {fg?:string, bg?:string, bold?:boolean}
---@class snacks.lazygit.Theme: table<number, snacks.lazygit.Color>
@ -62,14 +64,14 @@ vim.api.nvim_create_autocmd("ColorScheme", {
---@param opts snacks.lazygit.Config
local function env(opts)
if not config_dir then
local proc = vim.system({ "lazygit", "-cd" }, { text = true }):wait()
local lines = vim.split(proc.stdout, "\n", { plain = true })
local out = vim.fn.system({ "lazygit", "-cd" })
local lines = vim.split(out, "\n", { plain = true })
if proc.code == 0 then
if vim.v.shell_error == 0 and #lines > 1 then
config_dir = vim.split(lines[1], "\n", { plain = true })[1]
vim.env.LG_CONFIG_FILE = vim.fs.normalize(config_dir .. "/config.yml" .. "," .. opts.theme_path)
local custom_config = vim.fs.normalize(config_dir .. "/custom.yml")
if vim.uv.fs_stat(custom_config) and vim.uv.fs_stat(custom_config).type == "file" then
if uv.fs_stat(custom_config) and uv.fs_stat(custom_config).type == "file" then
vim.env.LG_CONFIG_FILE = vim.env.LG_CONFIG_FILE .. "," .. custom_config
end
else
@ -78,7 +80,7 @@ local function env(opts)
"Will not apply **lazygit** config.",
"",
"# Error:",
vim.trim(proc.stdout .. "\n" .. proc.stderr),
vim.trim(out),
}
Snacks.notify.error(msg, { title = "lazygit" })
end

View file

@ -6,6 +6,8 @@ local M = setmetatable({}, {
end,
})
local uv = vim.uv or vim.loop
--- Render styles:
--- * compact: use border for icon and title
--- * minimal: no border, only icon and message
@ -226,8 +228,12 @@ local function normlevel(level)
end
local function ts()
local ret = assert(vim.uv.clock_gettime("realtime"))
return ret.sec + ret.nsec / 1e9
if uv.clock_gettime then
local ret = assert(uv.clock_gettime("realtime"))
return ret.sec + ret.nsec / 1e9
end
local sec, usec = uv.gettimeofday()
return sec + usec / 1e6
end
local _id = 0
@ -281,7 +287,7 @@ function N:init()
end
function N:start()
vim.uv.new_timer():start(
uv.new_timer():start(
100,
100,
vim.schedule_wrap(function()
@ -293,6 +299,7 @@ function N:start()
self:layout()
end, function(err)
local trace = debug.traceback(err, 2)
print(err)
vim.api.nvim_err_writeln(
("Snacks notifier failed. Dropping queue. Error:\n%s\n\nTrace:\n%s"):format(error, trace)
)

View file

@ -50,7 +50,7 @@ function M.on_rename_file(from, to, rename)
newUri = vim.uri_from_fname(to),
} } }
local clients = vim.lsp.get_clients()
local clients = (vim.lsp.get_clients or vim.lsp.get_active_clients)()
for _, client in ipairs(clients) do
if client.supports_method("workspace/willRenameFiles") then
local resp = client.request_sync("workspace/willRenameFiles", changes, 1000, 0)

View file

@ -61,17 +61,16 @@ end
---@param buf number?
function M.is_enabled(buf)
buf = buf or vim.api.nvim_get_current_buf()
local mode = vim.api.nvim_get_mode().mode:lower()
mode = mode:gsub("\22", "v"):gsub("\19", "s")
mode = mode:sub(1, 2) == "no" and "o" or mode
mode = mode:sub(1, 1):match("[ncitsvo]") or "n"
return config.enabled
and vim.tbl_contains(config.modes, mode)
and #vim.lsp.get_clients({
method = vim.lsp.protocol.Methods.textDocument_documentHighlight,
bufnr = buf or 0,
})
> 0
local clients = (vim.lsp.get_clients or vim.lsp.get_active_clients)({ bufnr = buf })
clients = vim.tbl_filter(function(client)
return client.supports_method("textDocument/documentHighlight", { bufnr = buf })
end, clients)
return config.enabled and vim.tbl_contains(config.modes, mode) and #clients > 0
end
---@private