diff --git a/doc/snacks-bufdelete.txt b/doc/snacks-bufdelete.txt index ef634052..146d94c2 100644 --- a/doc/snacks-bufdelete.txt +++ b/doc/snacks-bufdelete.txt @@ -21,6 +21,7 @@ discard. >lua ---@class snacks.bufdelete.Opts ---@field buf? number Buffer to delete. Defaults to the current buffer + ---@field file? string Delete buffer by file name. If provided, `buf` is ignored ---@field force? boolean Delete the buffer even if it is modified ---@field filter? fun(buf: number): boolean Filter buffers to delete ---@field wipe? boolean Wipe the buffer instead of deleting it (see `:h :bwipeout`) diff --git a/doc/snacks-image.txt b/doc/snacks-image.txt index e8e1a98d..053c15be 100644 --- a/doc/snacks-image.txt +++ b/doc/snacks-image.txt @@ -158,7 +158,7 @@ In case of issues, make sure to run `:checkhealth snacks`. font_size = "Large", -- see https://www.sascha-frank.com/latex-font-size.html -- for latex documents, the doc packages are included automatically, -- but you can add more packages here. Useful for markdown documents. - packages = { "amsmath", "amssymb", "amsfonts", "amscd", "mathtools", "physics", "siunitx", "mhchem" }, + packages = { "amsmath", "amssymb", "amsfonts", "amscd", "mathtools" }, }, ---@type snacks.image.args mermaid = function() diff --git a/doc/snacks-lazygit.txt b/doc/snacks-lazygit.txt index 570d1b6d..78f5b478 100644 --- a/doc/snacks-lazygit.txt +++ b/doc/snacks-lazygit.txt @@ -58,7 +58,7 @@ colorscheme and integrate edit with the current neovim instance. nerdFontsVersion = "3", }, }, - theme_path = vim.fs.normalize(vim.fn.stdpath("cache") .. "/lazygit-theme.yml"), + theme_path = svim.fs.normalize(vim.fn.stdpath("cache") .. "/lazygit-theme.yml"), -- Theme for lazygit theme = { [241] = { fg = "Special" }, diff --git a/doc/snacks-picker.txt b/doc/snacks-picker.txt index f40c6b3f..9fb7f0f1 100644 --- a/doc/snacks-picker.txt +++ b/doc/snacks-picker.txt @@ -93,6 +93,7 @@ Table of Contents *snacks-picker-table-of-contents* - vscode |snacks-picker-layouts-vscode| 10. snacks.picker.actions |snacks-picker-snacks.picker.actions| - Snacks.picker.actions.bufdelete()|snacks-picker-snacks.picker.actions-snacks.picker.actions.bufdelete()| + - Snacks.picker.actions.cancel()|snacks-picker-snacks.picker.actions-snacks.picker.actions.cancel()| - Snacks.picker.actions.cd()|snacks-picker-snacks.picker.actions-snacks.picker.actions.cd()| - Snacks.picker.actions.close()|snacks-picker-snacks.picker.actions-snacks.picker.actions.close()| - Snacks.picker.actions.cmd()|snacks-picker-snacks.picker.actions-snacks.picker.actions.cmd()| @@ -387,11 +388,11 @@ below. ["/"] = "toggle_focus", [""] = { "history_forward", mode = { "i", "n" } }, [""] = { "history_back", mode = { "i", "n" } }, - [""] = { "close", mode = "i" }, + [""] = { "cancel", mode = "i" }, [""] = { "", mode = { "i" }, expr = true, desc = "delete word" }, [""] = { "confirm", mode = { "n", "i" } }, [""] = { "list_down", mode = { "i", "n" } }, - [""] = "close", + [""] = "cancel", [""] = { { "pick_win", "jump" }, mode = { "n", "i" } }, [""] = { "select_and_prev", mode = { "i", "n" } }, [""] = { "select_and_next", mode = { "i", "n" } }, @@ -439,7 +440,7 @@ below. ["<2-LeftMouse>"] = "confirm", [""] = "confirm", [""] = "list_down", - [""] = "close", + [""] = "cancel", [""] = { { "pick_win", "jump" } }, [""] = { "select_and_prev", mode = { "n", "x" } }, [""] = { "select_and_next", mode = { "n", "x" } }, @@ -487,7 +488,7 @@ below. -- preview window preview = { keys = { - [""] = "close", + [""] = "cancel", ["q"] = "close", ["i"] = "focus_input", [""] = "list_scroll_wheel_down", @@ -797,23 +798,6 @@ TROUBLE *snacks-picker-examples-trouble* ---@field notify? boolean < ->lua - ---@alias snacks.Picker.ref (fun():snacks.Picker?)|{value?: snacks.Picker} -< - ->lua - ---@class snacks.picker.Last - ---@field cursor number - ---@field topline number - ---@field opts? snacks.picker.Config - ---@field selected snacks.picker.Item[] - ---@field filter snacks.picker.Filter -< - ->lua - ---@alias snacks.picker.history.Record {pattern: string, search: string, live?: boolean} -< - >lua ---@alias snacks.picker.Extmark vim.api.keyset.set_extmark|{col:number, row?:number, field?:string} ---@alias snacks.picker.Text {[1]:string, [2]:string?, virtual?:boolean, field?:string} @@ -892,6 +876,23 @@ that shows a preview based on the item data. ---@field preview? snacks.win.Config|{} preview window config < +>lua + ---@alias snacks.Picker.ref (fun():snacks.Picker?)|{value?: snacks.Picker} +< + +>lua + ---@class snacks.picker.Last + ---@field cursor number + ---@field topline number + ---@field opts? snacks.picker.Config + ---@field selected snacks.picker.Item[] + ---@field filter snacks.picker.Filter +< + +>lua + ---@alias snacks.picker.history.Record {pattern: string, search: string, live?: boolean} +< + ============================================================================== 7. Module *snacks-picker-module* @@ -2630,6 +2631,13 @@ SNACKS.PICKER.ACTIONS.BUFDELETE()*snacks-picker-snacks.picker.actions-snacks.pic < +SNACKS.PICKER.ACTIONS.CANCEL()*snacks-picker-snacks.picker.actions-snacks.picker.actions.cancel()* + +>lua + Snacks.picker.actions.cancel(picker) +< + + SNACKS.PICKER.ACTIONS.CD()*snacks-picker-snacks.picker.actions-snacks.picker.actions.cd()* >lua diff --git a/doc/snacks-rename.txt b/doc/snacks-rename.txt index da6eb8e7..21c2a291 100644 --- a/doc/snacks-rename.txt +++ b/doc/snacks-rename.txt @@ -107,10 +107,11 @@ Lets LSP clients know that a file has been renamed `Snacks.rename.rename_file()` *Snacks.rename.rename_file()* -Prompt for the new filename, do the rename, and trigger LSP handlers +Renames the provided file, or the current buffer’s file. Prompt for the new +filename if `to` is not provided. do the rename, and trigger LSP handlers >lua - ---@param opts? {file?: string, on_rename?: fun(new:string, old:string)} + ---@param opts? {from?: string, to?:string, on_rename?: fun(to:string, from:string, ok:boolean)} Snacks.rename.rename_file(opts) < diff --git a/docs/lazygit.md b/docs/lazygit.md index ab4ce30b..1e3980e4 100644 --- a/docs/lazygit.md +++ b/docs/lazygit.md @@ -44,7 +44,7 @@ and integrate edit with the current neovim instance. nerdFontsVersion = "3", }, }, - theme_path = vim.fs.normalize(vim.fn.stdpath("cache") .. "/lazygit-theme.yml"), + theme_path = svim.fs.normalize(vim.fn.stdpath("cache") .. "/lazygit-theme.yml"), -- Theme for lazygit theme = { [241] = { fg = "Special" }, diff --git a/lua/snacks/compat.lua b/lua/snacks/compat.lua new file mode 100644 index 00000000..739649f6 --- /dev/null +++ b/lua/snacks/compat.lua @@ -0,0 +1,32 @@ +---@generic T +---@param t T +---@return T +local function wrap(t) + return setmetatable({}, { __index = t }) +end + +local M = wrap(vim) + +M.meta = { + desc = "Neovim compatibility layer", + hide = true, +} + +local is_win = jit.os:find("Windows") + +M.islist = vim.islist or vim.tbl_islist +M.uv = vim.uv or vim.loop + +if vim.fn.has("nvim-0.11") == 0 then + M.fs = wrap(vim.fs) + + ---@param path (string) Path to normalize + ---@param opts? vim.fs.normalize.Opts + ---@return (string) : Normalized path + function M.normalize(path, opts) + local ret = svim.fs.normalize(path, opts) + return is_win and ret:gsub("^%a:", string.upper) or ret + end +end + +return M diff --git a/lua/snacks/dashboard.lua b/lua/snacks/dashboard.lua index bcad8473..45ecdf96 100644 --- a/lua/snacks/dashboard.lua +++ b/lua/snacks/dashboard.lua @@ -792,14 +792,14 @@ function M.oldfiles(opts) local filter = {} ---@type {path:string, want:boolean}[] for path, want in pairs(opts.filter or {}) do - table.insert(filter, { path = vim.fs.normalize(path), want = want }) + table.insert(filter, { path = svim.fs.normalize(path), want = want }) end local done = {} ---@type table local i = 1 local oldfiles = vim.v.oldfiles return function() while oldfiles[i] do - local file = vim.fs.normalize(oldfiles[i], { _fast = true, expand_env = false }) + local file = svim.fs.normalize(oldfiles[i], { _fast = true, expand_env = false }) local want = not done[file] if want then done[file] = true @@ -850,7 +850,7 @@ function M.sections.recent_files(opts) return function() opts = opts or {} local limit = opts.limit or 5 - local root = opts.cwd and vim.fs.normalize(opts.cwd == true and vim.fn.getcwd() or opts.cwd) or "" + local root = opts.cwd and svim.fs.normalize(opts.cwd == true and vim.fn.getcwd() or opts.cwd) or "" local ret = {} ---@type snacks.dashboard.Section for file in M.oldfiles({ filter = { [root] = true } }) do if not opts.filter or opts.filter(file) then diff --git a/lua/snacks/explorer/actions.lua b/lua/snacks/explorer/actions.lua index b5544ab3..71d92dab 100644 --- a/lua/snacks/explorer/actions.lua +++ b/lua/snacks/explorer/actions.lua @@ -160,7 +160,7 @@ function M.actions.explorer_add(picker) if not value or value:find("^%s$") then return end - local path = vim.fs.normalize(picker:dir() .. "/" .. value) + local path = svim.fs.normalize(picker:dir() .. "/" .. value) local is_file = value:sub(-1) ~= "/" local dir = is_file and vim.fs.dirname(path) or path if is_file and uv.fs_stat(path) then @@ -237,7 +237,7 @@ function M.actions.explorer_copy(picker, item) return end local dir = vim.fs.dirname(item.file) - local to = vim.fs.normalize(dir .. "/" .. value) + local to = svim.fs.normalize(dir .. "/" .. value) if uv.fs_stat(to) then Snacks.notify.warn("File already exists:\n- `" .. to .. "`") return diff --git a/lua/snacks/explorer/diagnostics.lua b/lua/snacks/explorer/diagnostics.lua index 0f73e0e9..3a1df33d 100644 --- a/lua/snacks/explorer/diagnostics.lua +++ b/lua/snacks/explorer/diagnostics.lua @@ -22,7 +22,7 @@ function M.update(cwd) for _, diag in ipairs(diags) do local path = diag.bufnr and vim.api.nvim_buf_get_name(diag.bufnr) - path = path and path ~= "" and vim.fs.normalize(path) or nil + path = path and path ~= "" and svim.fs.normalize(path) or nil if path then add(path, diag) add(cwd, diag) diff --git a/lua/snacks/explorer/init.lua b/lua/snacks/explorer/init.lua index b8c59060..fd754e1e 100644 --- a/lua/snacks/explorer/init.lua +++ b/lua/snacks/explorer/init.lua @@ -80,7 +80,7 @@ function M.reveal(opts) local Actions = require("snacks.explorer.actions") local Tree = require("snacks.explorer.tree") opts = opts or {} - local file = vim.fs.normalize(opts.file or vim.api.nvim_buf_get_name(opts.buf or 0)) + local file = svim.fs.normalize(opts.file or vim.api.nvim_buf_get_name(opts.buf or 0)) local explorer = Snacks.picker.get({ source = "explorer" })[1] or M.open() local cwd = explorer:cwd() if not Tree:in_cwd(cwd, file) then diff --git a/lua/snacks/explorer/tree.lua b/lua/snacks/explorer/tree.lua index 5e796978..d31796f3 100644 --- a/lua/snacks/explorer/tree.lua +++ b/lua/snacks/explorer/tree.lua @@ -24,7 +24,7 @@ local uv = vim.uv or vim.loop local function norm(path) - return vim.fs.normalize(path) + return svim.fs.normalize(path) end local function assert_dir(path) diff --git a/lua/snacks/git.lua b/lua/snacks/git.lua index 222dc4f7..cacf0bdd 100644 --- a/lua/snacks/git.lua +++ b/lua/snacks/git.lua @@ -29,7 +29,7 @@ end function M.get_root(path) path = path or 0 path = type(path) == "number" and vim.api.nvim_buf_get_name(path) or path --[[@as string]] - path = vim.fs.normalize(path) + path = svim.fs.normalize(path) path = path == "" and (vim.uv or vim.loop).cwd() or path local todo = { path } ---@type string[] @@ -40,13 +40,13 @@ function M.get_root(path) -- check cache first for _, dir in ipairs(todo) do if git_cache[dir] then - return vim.fs.normalize(dir) or nil + return svim.fs.normalize(dir) or nil end end for _, dir in ipairs(todo) do if is_git_root(dir) then - return vim.fs.normalize(dir) or nil + return svim.fs.normalize(dir) or nil end end diff --git a/lua/snacks/gitbrowse.lua b/lua/snacks/gitbrowse.lua index 2bff0458..65f89a1c 100644 --- a/lua/snacks/gitbrowse.lua +++ b/lua/snacks/gitbrowse.lua @@ -149,7 +149,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 (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 svim.fs.normalize(file) or nil local cwd = file and vim.fn.fnamemodify(file, ":h") or vim.fn.getcwd() ---@type snacks.gitbrowse.Fields diff --git a/lua/snacks/image/convert.lua b/lua/snacks/image/convert.lua index c313d8a0..bccfbfa7 100644 --- a/lua/snacks/image/convert.lua +++ b/lua/snacks/image/convert.lua @@ -420,7 +420,7 @@ function M.norm(src) src = vim.uri_to_fname(src) end if not M.is_uri(src) then - src = vim.fs.normalize(vim.fn.fnamemodify(src, ":p")) + src = svim.fs.normalize(vim.fn.fnamemodify(src, ":p")) end return src end diff --git a/lua/snacks/image/doc.lua b/lua/snacks/image/doc.lua index 67cbc858..fb954996 100644 --- a/lua/snacks/image/doc.lua +++ b/lua/snacks/image/doc.lua @@ -107,7 +107,7 @@ end ---@param src string function M.resolve(buf, src) src = M.url_decode(src) - local file = vim.fs.normalize(vim.api.nvim_buf_get_name(buf)) + local file = svim.fs.normalize(vim.api.nvim_buf_get_name(buf)) local s = Snacks.image.config.resolve and Snacks.image.config.resolve(file, src) or nil if s then return s @@ -130,7 +130,7 @@ function M.resolve(buf, src) break end end - src = vim.fs.normalize(src) + src = svim.fs.normalize(src) end return src end diff --git a/lua/snacks/image/util.lua b/lua/snacks/image/util.lua index 00e1db24..a814ae3e 100644 --- a/lua/snacks/image/util.lua +++ b/lua/snacks/image/util.lua @@ -7,7 +7,7 @@ local dims = {} ---@type table ---@param file string ---@return snacks.image.Size function M.dim(file) - file = vim.fs.normalize(file) + file = svim.fs.normalize(file) if dims[file] then return dims[file] end diff --git a/lua/snacks/init.lua b/lua/snacks/init.lua index 9efa49e8..a55dd6a8 100644 --- a/lua/snacks/init.lua +++ b/lua/snacks/init.lua @@ -10,6 +10,7 @@ setmetatable(M, { }) _G.Snacks = M +_G.svim = vim.fn.has("nvim-0.11") and vim or require("snacks.compat") ---@class snacks.Config.base ---@field example? string diff --git a/lua/snacks/lazygit.lua b/lua/snacks/lazygit.lua index c9d5df79..3fc166a6 100644 --- a/lua/snacks/lazygit.lua +++ b/lua/snacks/lazygit.lua @@ -40,7 +40,7 @@ local defaults = { nerdFontsVersion = "3", }, }, - theme_path = vim.fs.normalize(vim.fn.stdpath("cache") .. "/lazygit-theme.yml"), + theme_path = svim.fs.normalize(vim.fn.stdpath("cache") .. "/lazygit-theme.yml"), -- Theme for lazygit -- stylua: ignore theme = { @@ -89,7 +89,7 @@ local function env(opts) -- add the default config file if it's not already there if #config_files == 0 then - config_files[1] = vim.fs.normalize(config_dir .. "/config.yml") + config_files[1] = svim.fs.normalize(config_dir .. "/config.yml") end -- add the theme file if it's not already there diff --git a/lua/snacks/meta/init.lua b/lua/snacks/meta/init.lua index c8c17f12..6ca86fae 100644 --- a/lua/snacks/meta/init.lua +++ b/lua/snacks/meta/init.lua @@ -26,7 +26,7 @@ M.meta = { M.root = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h") function M.file(name) - return vim.fs.normalize(("%s/%s"):format(M.root, name)) + return svim.fs.normalize(("%s/%s"):format(M.root, name)) end --- Get the metadata for all snacks plugins diff --git a/lua/snacks/picker/config/init.lua b/lua/snacks/picker/config/init.lua index 65b98a9d..db5f370a 100644 --- a/lua/snacks/picker/config/init.lua +++ b/lua/snacks/picker/config/init.lua @@ -80,7 +80,7 @@ function M.get(opts) if opts.cwd == true or opts.cwd == "" then opts.cwd = nil elseif opts.cwd then - opts.cwd = vim.fs.normalize(vim.fn.fnamemodify(opts.cwd, ":p")) + opts.cwd = svim.fs.normalize(vim.fn.fnamemodify(opts.cwd, ":p")) end for _, t in ipairs(todo) do if t.config then diff --git a/lua/snacks/picker/core/filter.lua b/lua/snacks/picker/core/filter.lua index 750da7ee..b1723957 100644 --- a/lua/snacks/picker/core/filter.lua +++ b/lua/snacks/picker/core/filter.lua @@ -39,13 +39,13 @@ function M:init(opts) self.paths = {} local cwd = self.opts and self.opts.cwd self.cwd = type(cwd) == "string" and cwd or opts.cwd or uv.cwd() or "." - self.cwd = vim.fs.normalize(self.cwd --[[@as string]], { _fast = true }) + self.cwd = svim.fs.normalize(self.cwd --[[@as string]], { _fast = true }) if not self.all and self.opts then self.buf = self.opts.buf == true and 0 or self.opts.buf --[[@as number?]] self.buf = self.buf == 0 and M.current_buf or self.buf - self.file = self.buf and vim.fs.normalize(vim.api.nvim_buf_get_name(self.buf), { _fast = true }) or nil + self.file = self.buf and svim.fs.normalize(vim.api.nvim_buf_get_name(self.buf), { _fast = true }) or nil for path, want in pairs(self.opts.paths or {}) do - table.insert(self.paths, { path = vim.fs.normalize(path), want = want }) + table.insert(self.paths, { path = svim.fs.normalize(path), want = want }) end end return self @@ -58,7 +58,7 @@ end ---@param cwd string function M:set_cwd(cwd) self.cwd = cwd - self.cwd = vim.fs.normalize(self.cwd --[[@as string]], { _fast = true }) + self.cwd = svim.fs.normalize(self.cwd --[[@as string]], { _fast = true }) end ---@param opts? {trim?:boolean} diff --git a/lua/snacks/picker/core/matcher.lua b/lua/snacks/picker/core/matcher.lua index 6f41c2e1..caa59d96 100644 --- a/lua/snacks/picker/core/matcher.lua +++ b/lua/snacks/picker/core/matcher.lua @@ -85,7 +85,7 @@ function M:run(picker) self.task:abort() picker.list:clear() - self.cwd = vim.fs.normalize(picker.opts.cwd or (vim.uv or vim.loop).cwd() or ".") + self.cwd = svim.fs.normalize(picker.opts.cwd or (vim.uv or vim.loop).cwd() or ".") self.sorting = not self:empty() or picker.opts.matcher.sort_empty -- PERF: fast path for empty pattern diff --git a/lua/snacks/picker/source/diagnostics.lua b/lua/snacks/picker/source/diagnostics.lua index 5acda5f4..5104d4fc 100644 --- a/lua/snacks/picker/source/diagnostics.lua +++ b/lua/snacks/picker/source/diagnostics.lua @@ -6,11 +6,11 @@ local uv = vim.uv or vim.loop function M.diagnostics(opts, ctx) local items = {} ---@type snacks.picker.finder.Item[] local current_buf = vim.api.nvim_get_current_buf() - local cwd = vim.fs.normalize(uv.cwd() or ".") + local cwd = svim.fs.normalize(uv.cwd() or ".") for _, diag in ipairs(vim.diagnostic.get(ctx.filter.buf, { severity = opts.severity })) do local buf = diag.bufnr if buf and vim.api.nvim_buf_is_valid(buf) then - local file = vim.fs.normalize(vim.api.nvim_buf_get_name(buf), { _fast = true }) + local file = svim.fs.normalize(vim.api.nvim_buf_get_name(buf), { _fast = true }) local severity = diag.severity severity = type(severity) == "number" and vim.diagnostic.severity[severity] or severity ---@cast severity string? diff --git a/lua/snacks/picker/source/explorer.lua b/lua/snacks/picker/source/explorer.lua index 155866db..847c1fbb 100644 --- a/lua/snacks/picker/source/explorer.lua +++ b/lua/snacks/picker/source/explorer.lua @@ -19,7 +19,7 @@ local uv = vim.uv or vim.loop ---@field status? string local function norm(path) - return vim.fs.normalize(path) + return svim.fs.normalize(path) end ---@class snacks.picker.explorer.State @@ -40,7 +40,7 @@ function State.new(picker) Tree:refresh(picker:cwd()) local buf = vim.api.nvim_win_get_buf(picker.main) - local buf_file = vim.fs.normalize(vim.api.nvim_buf_get_name(buf)) + local buf_file = svim.fs.normalize(vim.api.nvim_buf_get_name(buf)) if uv.fs_stat(buf_file) then Tree:open(buf_file) end @@ -66,7 +66,7 @@ function State.new(picker) picker.list.win:on("DirChanged", function(_, ev) local p = ref() if p then - p:set_cwd(vim.fs.normalize(ev.file)) + p:set_cwd(svim.fs.normalize(ev.file)) p:find() end end) diff --git a/lua/snacks/picker/source/files.lua b/lua/snacks/picker/source/files.lua index b9c618a3..faec299b 100644 --- a/lua/snacks/picker/source/files.lua +++ b/lua/snacks/picker/source/files.lua @@ -133,7 +133,7 @@ local function get_cmd(opts, filter) vim.list_extend(dirs, Snacks.picker.util.rtp()) end if #dirs > 0 then - dirs = vim.tbl_map(vim.fs.normalize, dirs) ---@type string[] + dirs = vim.tbl_map(svim.fs.normalize, dirs) ---@type string[] if is_fd and not pattern then args[#args + 1] = "." end @@ -154,7 +154,7 @@ end ---@type snacks.picker.finder function M.files(opts, ctx) local cwd = not (opts.rtp or (opts.dirs and #opts.dirs > 0)) - and vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") + and svim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil local cmd, args = get_cmd(opts, ctx.filter) if not cmd then diff --git a/lua/snacks/picker/source/git.lua b/lua/snacks/picker/source/git.lua index fabd1392..74894ada 100644 --- a/lua/snacks/picker/source/git.lua +++ b/lua/snacks/picker/source/git.lua @@ -27,7 +27,7 @@ function M.files(opts, ctx) opts.cwd = Snacks.git.get_root() or uv.cwd() or "." ctx.picker:set_cwd(opts.cwd) end - local cwd = vim.fs.normalize(opts.cwd) or nil + local cwd = svim.fs.normalize(opts.cwd) or nil return require("snacks.picker.source.proc").proc({ opts, { @@ -59,7 +59,7 @@ function M.grep(opts, ctx) opts.cwd = Snacks.git.get_root() or uv.cwd() or "." ctx.picker:set_cwd(opts.cwd) end - local cwd = vim.fs.normalize(opts.cwd) or nil + local cwd = svim.fs.normalize(opts.cwd) or nil return require("snacks.picker.source.proc").proc({ opts, { @@ -121,9 +121,9 @@ function M.log(opts, ctx) end local Proc = require("snacks.picker.source.proc") - file = file and vim.fs.normalize(file) or nil + file = file and svim.fs.normalize(file) or nil - local cwd = vim.fs.normalize(file and vim.fn.fnamemodify(file, ":h") or opts and opts.cwd or uv.cwd() or ".") or nil + local cwd = svim.fs.normalize(file and vim.fn.fnamemodify(file, ":h") or opts and opts.cwd or uv.cwd() or ".") or nil cwd = Snacks.git.get_root(cwd) or cwd local renames = { file } ---@type string[] @@ -180,7 +180,7 @@ function M.status(opts, ctx) table.insert(args, "--ignored=matching") end - local cwd = vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil + local cwd = svim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil cwd = Snacks.git.get_root(cwd) local prev ---@type snacks.picker.finder.Item? return require("snacks.picker.source.proc").proc({ @@ -266,7 +266,7 @@ end ---@type snacks.picker.finder function M.branches(opts, ctx) local args = git_args(opts.args, "--no-pager", "branch", "--no-color", "-vvl") - local cwd = vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil + local cwd = svim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil cwd = Snacks.git.get_root(cwd) local patterns = { @@ -310,7 +310,7 @@ end ---@type snacks.picker.finder function M.stash(opts, ctx) local args = git_args(opts.args, "--no-pager", "stash", "list") - local cwd = vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil + local cwd = svim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil cwd = Snacks.git.get_root(cwd) return require("snacks.picker.source.proc").proc({ diff --git a/lua/snacks/picker/source/grep.lua b/lua/snacks/picker/source/grep.lua index 8e830e53..98c1a427 100644 --- a/lua/snacks/picker/source/grep.lua +++ b/lua/snacks/picker/source/grep.lua @@ -88,7 +88,7 @@ local function get_cmd(opts, filter) -- dirs if #paths > 0 then - paths = vim.tbl_map(vim.fs.normalize, paths) ---@type string[] + paths = vim.tbl_map(svim.fs.normalize, paths) ---@type string[] vim.list_extend(args, paths) end @@ -102,7 +102,7 @@ function M.grep(opts, ctx) return function() end end local absolute = (opts.dirs and #opts.dirs > 0) or opts.buffers or opts.rtp - local cwd = not absolute and vim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil + local cwd = not absolute and svim.fs.normalize(opts and opts.cwd or uv.cwd() or ".") or nil local cmd, args = get_cmd(opts, ctx.filter) if opts.debug.grep then Snacks.notify.info("grep: " .. cmd .. " " .. table.concat(args, " ")) diff --git a/lua/snacks/picker/source/lsp/config.lua b/lua/snacks/picker/source/lsp/config.lua index 700d0232..0a39e711 100644 --- a/lua/snacks/picker/source/lsp/config.lua +++ b/lua/snacks/picker/source/lsp/config.lua @@ -84,7 +84,7 @@ function M.find(opts, ctx) if type(cmd) == "table" and #cmd > 0 then ---@type string[] cmd = vim.deepcopy(cmd) - cmd[1] = vim.fs.normalize(cmd[1]) + cmd[1] = svim.fs.normalize(cmd[1]) if cmd[1]:find("/") then installed = vim.fn.filereadable(cmd[1]) == 1 bin = cmd[1] diff --git a/lua/snacks/picker/source/lsp/init.lua b/lua/snacks/picker/source/lsp/init.lua index c82acf08..9e6f1235 100644 --- a/lua/snacks/picker/source/lsp/init.lua +++ b/lua/snacks/picker/source/lsp/init.lua @@ -180,7 +180,7 @@ function M.get_locations(method, opts, filter) local win = filter.current_win local buf = filter.current_buf local fname = vim.api.nvim_buf_get_name(buf) - fname = vim.fs.normalize(fname) + fname = svim.fs.normalize(fname) local cursor = vim.api.nvim_win_get_cursor(win) local bufmap = M.bufmap() @@ -203,7 +203,7 @@ function M.get_locations(method, opts, filter) if not opts.include_current then ---@param item vim.quickfix.entry items = vim.tbl_filter(function(item) - if vim.fs.normalize(item.filename) ~= fname then + if svim.fs.normalize(item.filename) ~= fname then return true end if not item.lnum then diff --git a/lua/snacks/picker/source/proc.lua b/lua/snacks/picker/source/proc.lua index 077a8de4..39555450 100644 --- a/lua/snacks/picker/source/proc.lua +++ b/lua/snacks/picker/source/proc.lua @@ -54,7 +54,7 @@ function M.proc(opts, ctx) local spawn_opts = { args = opts.args, stdio = { nil, stdout, nil }, - cwd = opts.cwd and vim.fs.normalize(opts.cwd) or nil, + cwd = opts.cwd and svim.fs.normalize(opts.cwd) or nil, env = opts.env, hide = true, } @@ -174,7 +174,7 @@ function M.debug(opts) end Snacks.notify.info( ("- **cwd**: `%s`\n```sh\n%s\n```"):format( - vim.fn.fnamemodify(vim.fs.normalize(opts.cwd or uv.cwd() or "."), ":~"), + vim.fn.fnamemodify(svim.fs.normalize(opts.cwd or uv.cwd() or "."), ":~"), table.concat(lines, "\n") ), { id = "snacks.picker.proc." .. id, title = "Snacks Proc" } diff --git a/lua/snacks/picker/source/recent.lua b/lua/snacks/picker/source/recent.lua index 0d4f1fff..73f201e6 100644 --- a/lua/snacks/picker/source/recent.lua +++ b/lua/snacks/picker/source/recent.lua @@ -14,7 +14,7 @@ local function oldfiles(filter, extra) for f = i + 1, #files do i = f local file = files[f] - file = vim.fs.normalize(file, { _fast = true, expand_env = false }) + file = svim.fs.normalize(file, { _fast = true, expand_env = false }) local want = not done[file] and filter:match({ file = file, text = "" }) done[file] = true if want and uv.fs_stat(file) then @@ -29,7 +29,7 @@ end ---@param opts snacks.picker.recent.Config ---@type snacks.picker.finder function M.files(opts, ctx) - local current_file = vim.fs.normalize(vim.api.nvim_buf_get_name(0), { _fast = true }) + local current_file = svim.fs.normalize(vim.api.nvim_buf_get_name(0), { _fast = true }) ---@type number[] local bufs = vim.tbl_filter(function(b) return vim.api.nvim_buf_get_name(b) ~= "" and vim.bo[b].buftype == "" and vim.bo[b].buflisted @@ -76,7 +76,7 @@ function M.projects(opts, ctx) vim.list_extend(args, { "-g", "{" .. table.concat(opts.patterns or {}, ",") .. "}" }) local dev = type(opts.dev) == "string" and { opts.dev } or opts.dev or {} ---@cast dev string[] - vim.list_extend(args, vim.tbl_map(vim.fs.normalize, dev)) + vim.list_extend(args, vim.tbl_map(svim.fs.normalize, dev)) local fd = require("snacks.picker.source.files").get_fd() if not fd then Snacks.notify.warn("`fd` or `fdfind` is required for projects") diff --git a/lua/snacks/picker/util/init.lua b/lua/snacks/picker/util/init.lua index c2a7d1bd..830c713b 100644 --- a/lua/snacks/picker/util/init.lua +++ b/lua/snacks/picker/util/init.lua @@ -10,7 +10,7 @@ function M.path(item) return end item._path = item._path - or vim.fs.normalize(item.cwd and item.cwd .. "/" .. item.file or item.file, { _fast = true, expand_env = false }) + or svim.fs.normalize(item.cwd and item.cwd .. "/" .. item.file or item.file, { _fast = true, expand_env = false }) return item._path end @@ -18,9 +18,9 @@ end ---@param len? number ---@param opts? {cwd?: string} function M.truncpath(path, len, opts) - local cwd = vim.fs.normalize(opts and opts.cwd or vim.fn.getcwd(), { _fast = true, expand_env = false }) - local home = vim.fs.normalize("~") - path = vim.fs.normalize(path, { _fast = true, expand_env = false }) + local cwd = svim.fs.normalize(opts and opts.cwd or vim.fn.getcwd(), { _fast = true, expand_env = false }) + local home = svim.fs.normalize("~") + path = svim.fs.normalize(path, { _fast = true, expand_env = false }) if path:find(cwd .. "/", 1, true) == 1 and #path > #cwd then path = path:sub(#cwd + 2) @@ -440,15 +440,15 @@ end function M.dir(item) local path = type(item) == "table" and M.path(item) or item ---@cast path string - path = vim.fs.normalize(path) + path = svim.fs.normalize(path) return vim.fn.isdirectory(path) == 1 and path or vim.fs.dirname(path) end ---@param paths string[] ---@param dir string function M.copy(paths, dir) - dir = vim.fs.normalize(dir) - paths = vim.tbl_map(vim.fs.normalize, paths) ---@type string[] + dir = svim.fs.normalize(dir) + paths = vim.tbl_map(svim.fs.normalize, paths) ---@type string[] for _, path in ipairs(paths) do local name = vim.fn.fnamemodify(path, ":t") local to = dir .. "/" .. name @@ -539,7 +539,7 @@ function M.get_bins() local path = vim.split(os.getenv("PATH") or "", is_win and ";" or ":", { plain = true }) local bins = {} ---@type table for _, p in ipairs(path) do - p = vim.fs.normalize(p) + p = svim.fs.normalize(p) for file, t in vim.fs.dir(p) do if t ~= "directory" then local fpath = p .. "/" .. file diff --git a/lua/snacks/profiler/loc.lua b/lua/snacks/profiler/loc.lua index 2ed8cbfd..50036a77 100644 --- a/lua/snacks/profiler/loc.lua +++ b/lua/snacks/profiler/loc.lua @@ -35,8 +35,8 @@ function M.realpath(path) if path_cache[path] then return path_cache[path] end - path = vim.fs.normalize(path, { expand_env = false }) - path_cache[path] = vim.fs.normalize(vim.uv.fs_realpath(path) or path, { expand_env = false, _fast = true }) + path = svim.fs.normalize(path, { expand_env = false }) + path_cache[path] = svim.fs.normalize(vim.uv.fs_realpath(path) or path, { expand_env = false, _fast = true }) return path_cache[path] end diff --git a/lua/snacks/rename.lua b/lua/snacks/rename.lua index 771c484a..7639bb53 100644 --- a/lua/snacks/rename.lua +++ b/lua/snacks/rename.lua @@ -44,7 +44,7 @@ function M.rename_file(opts) if not value or value == "" or value == extra then return end - to = vim.fs.normalize(root .. "/" .. value) + to = svim.fs.normalize(root .. "/" .. value) rename() end) end diff --git a/lua/snacks/scratch.lua b/lua/snacks/scratch.lua index a759f62e..2c3ed786 100644 --- a/lua/snacks/scratch.lua +++ b/lua/snacks/scratch.lua @@ -101,7 +101,7 @@ function M.list() local decoded = Snacks.util.file_decode(file) local count, icon, name, cwd, branch, ft = decoded:match("^(%d*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)%.([^|]*)$") if count and icon and name and cwd and branch and ft then - file = vim.fs.normalize(root .. "/" .. file) + file = svim.fs.normalize(root .. "/" .. file) table.insert(ret, { file = file, stat = uv.fs_stat(file), @@ -182,7 +182,7 @@ function M.open(opts) opts.filekey.count and tostring(vim.v.count1) or "", opts.icon or "", opts.name:gsub("|", " "), - opts.filekey.cwd and vim.fs.normalize(assert(uv.cwd())) or "", + opts.filekey.cwd and svim.fs.normalize(assert(uv.cwd())) or "", branch, } @@ -190,7 +190,7 @@ function M.open(opts) local fname = Snacks.util.file_encode(table.concat(filekey, "|") .. "." .. ft) file = opts.root .. "/" .. fname end - file = vim.fs.normalize(file) + file = svim.fs.normalize(file) local icon, icon_hl = unpack(type(opts.icon) == "table" and opts.icon or { opts.icon, nil }) ---@cast icon string diff --git a/queries/lua/highlights.scm b/queries/lua/highlights.scm index 88a1e68a..b2c38b9e 100644 --- a/queries/lua/highlights.scm +++ b/queries/lua/highlights.scm @@ -1,4 +1,4 @@ ;; extends ((identifier) @namespace.builtin - (#eq? @namespace.builtin "Snacks")) + (#any-of? @namespace.builtin "Snacks" "svim"))