Skip to content

Commit

Permalink
chore: deprecate vim.loop for vim.uv
Browse files Browse the repository at this point in the history
fix(keymaps): formatter conflict with `path.filename_first`
  • Loading branch information
ibhagwan committed May 7, 2024
1 parent 6865ff4 commit b99b4fd
Show file tree
Hide file tree
Showing 23 changed files with 94 additions and 74 deletions.
9 changes: 5 additions & 4 deletions lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.uv or vim.loop
local utils = require "fzf-lua.utils"
local path = require "fzf-lua.path"

Expand Down Expand Up @@ -105,7 +106,7 @@ M.vimcmd_file = function(vimcmd, selected, opts, pcall_vimcmd)
entry.ctag = opts._ctag and path.entry_to_ctag(selected[i])
local fullpath = entry.path or entry.uri and entry.uri:match("^%a+://(.*)")
if not path.is_absolute(fullpath) then
fullpath = path.join({ opts.cwd or opts._cwd or vim.loop.cwd(), fullpath })
fullpath = path.join({ opts.cwd or opts._cwd or uv.cwd(), fullpath })
end
if vimcmd == "e"
and curbuf ~= fullpath
Expand All @@ -128,7 +129,7 @@ M.vimcmd_file = function(vimcmd, selected, opts, pcall_vimcmd)
if vimcmd ~= "e" or not path.equals(curbuf, fullpath) then
if entry.path then
-- do not run ':<cmd> <file>' for uri entries (#341)
local relpath = path.relative_to(entry.path, vim.loop.cwd())
local relpath = path.relative_to(entry.path, uv.cwd())
if vim.o.autochdir then
-- force full paths when `autochdir=true` (#882)
relpath = fullpath
Expand Down Expand Up @@ -254,7 +255,7 @@ M.file_switch = function(selected, opts)
local entry = path.entry_to_file(selected[1])
local fullpath = entry.path
if not path.is_absolute(fullpath) then
fullpath = path.join({ opts.cwd or vim.loop.cwd(), fullpath })
fullpath = path.join({ opts.cwd or uv.cwd(), fullpath })
end
for _, b in ipairs(vim.api.nvim_list_bufs()) do
local bname = vim.api.nvim_buf_get_name(b)
Expand Down Expand Up @@ -488,7 +489,7 @@ M.goto_jump = function(selected, opts)
else
filepath = res
end
if not filepath or not vim.loop.fs_stat(filepath) then
if not filepath or not uv.fs_stat(filepath) then
-- no accessible file
-- jump is in current
filepath = vim.api.nvim_buf_get_name(0)
Expand Down
7 changes: 4 additions & 3 deletions lua/fzf-lua/complete.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.uv or vim.loop
local core = require "fzf-lua.core"
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"
Expand All @@ -16,7 +17,7 @@ local function find_toplevel_cwd(maybe_cwd, postfix, orig_cwd)
-- E5108: Error executing lua Vim:E220: Missing }.
local ok, _ = pcall(vim.fn.expand, maybe_cwd)
if not maybe_cwd or #maybe_cwd == 0 or not ok then
return nil, vim.loop.cwd(), nil
return nil, uv.cwd(), nil
end
if not orig_cwd then
orig_cwd = maybe_cwd
Expand All @@ -25,14 +26,14 @@ local function find_toplevel_cwd(maybe_cwd, postfix, orig_cwd)
local disp_cwd, cwd = maybe_cwd, vim.fn.expand(maybe_cwd)
-- returned cwd must be full path
if path.has_cwd_prefix(cwd) then
cwd = vim.loop.cwd() .. (#cwd > 1 and cwd:sub(2) or "")
cwd = uv.cwd() .. (#cwd > 1 and cwd:sub(2) or "")
-- inject "./" only if original path started with it
-- otherwise ignore the "." retval from fnamemodify
if #orig_cwd > 0 and orig_cwd:sub(1, 1) ~= "." then
disp_cwd = nil
end
elseif not path.is_absolute(cwd) then
cwd = path.join({ vim.loop.cwd(), cwd })
cwd = path.join({ uv.cwd(), cwd })
end
return disp_cwd, cwd, postfix
end
Expand Down
7 changes: 4 additions & 3 deletions lua/fzf-lua/config.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.uv or vim.loop
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"
local actions = require "fzf-lua.actions"
Expand Down Expand Up @@ -407,22 +408,22 @@ function M.normalize_opts(opts, globals, __resume_key)
-- use `_cwd` to not interfere with supplied users' options
-- as this can have unintended effects (e.g. in "buffers")
if vim.o.autochdir and not opts.cwd then
opts._cwd = vim.loop.cwd()
opts._cwd = uv.cwd()
end

if opts.cwd and #opts.cwd > 0 then
-- NOTE: on Windows, `expand` will replace all backslashes with forward slashes
-- i.e. C:/Users -> c:\Users
opts.cwd = vim.fn.expand(opts.cwd)
if not vim.loop.fs_stat(opts.cwd) then
if not uv.fs_stat(opts.cwd) then
utils.warn(("Unable to access '%s', removing 'cwd' option."):format(opts.cwd))
opts.cwd = nil
else
if not path.is_absolute(opts.cwd) then
-- relative paths in cwd are inaccessible when using multiprocess
-- as the external process have no awareness of our current working
-- directory so we must convert to full path (#375)
opts.cwd = path.join({ vim.loop.cwd(), opts.cwd })
opts.cwd = path.join({ uv.cwd(), opts.cwd })
elseif utils.__IS_WINDOWS and opts.cwd:sub(2) == ":" then
-- TODO: upstream bug? on Windoows: starting jobs with `cwd = C:` (without separator)
-- ignores the cwd argument and starts the job in the current working directory
Expand Down
11 changes: 6 additions & 5 deletions lua/fzf-lua/core.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.uv or vim.loop
local fzf = require "fzf-lua.fzf"
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"
Expand Down Expand Up @@ -786,18 +787,18 @@ end

M.set_header = function(opts, hdr_tbl)
local function normalize_cwd(cwd)
if path.is_absolute(cwd) and not path.equals(cwd, vim.loop.cwd()) then
if path.is_absolute(cwd) and not path.equals(cwd, uv.cwd()) then
-- since we're always converting cwd to full path
-- try to convert it back to relative for display
cwd = path.relative_to(cwd, vim.loop.cwd())
cwd = path.relative_to(cwd, uv.cwd())
end
-- make our home dir path look pretty
return path.HOME_to_tilde(cwd)
end

if not opts then opts = {} end
if opts.cwd_prompt then
opts.prompt = normalize_cwd(opts.cwd or vim.loop.cwd())
opts.prompt = normalize_cwd(opts.cwd or uv.cwd())
if tonumber(opts.cwd_prompt_shorten_len) and
#opts.prompt >= tonumber(opts.cwd_prompt_shorten_len) then
opts.prompt = path.shorten(opts.prompt, tonumber(opts.cwd_prompt_shorten_val) or 1)
Expand All @@ -821,10 +822,10 @@ M.set_header = function(opts, hdr_tbl)
if opts.cwd_header == false or
opts.cwd_prompt and opts.cwd_header == nil or
opts.cwd_header == nil and
(not opts.cwd or path.equals(opts.cwd, vim.loop.cwd())) then
(not opts.cwd or path.equals(opts.cwd, uv.cwd())) then
return
end
return normalize_cwd(opts.cwd or vim.loop.cwd())
return normalize_cwd(opts.cwd or uv.cwd())
end
},
search = {
Expand Down
3 changes: 2 additions & 1 deletion lua/fzf-lua/devicons.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.uv or vim.loop
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"

Expand Down Expand Up @@ -240,7 +241,7 @@ M.load = function(opts)
-- Load custom overrides before loading icons
if vim.g.fzf_lua_is_headless
---@diagnostic disable-next-line: undefined-field
and _G._devicons_setup and vim.loop.fs_stat(_G._devicons_setup) then
and _G._devicons_setup and uv.fs_stat(_G._devicons_setup) then
---@diagnostic disable-next-line: undefined-field
local file = loadfile(_G._devicons_setup)
if file then pcall(file) end
Expand Down
3 changes: 2 additions & 1 deletion lua/fzf-lua/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
-- require("fzf-lua") from test specs (which also run headless)
vim.g.fzf_lua_directory = ""

local uv = vim.uv or vim.loop
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"

do
local function source_vimL(path_parts)
local vimL_file = path.join(path_parts)
if vim.loop.fs_stat(vimL_file) then
if uv.fs_stat(vimL_file) then
vim.cmd("source " .. vimL_file)
-- print(string.format("loaded '%s'", vimL_file))
end
Expand Down
4 changes: 2 additions & 2 deletions lua/fzf-lua/libuv.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local uv = vim.loop
local uv = vim.uv or vim.loop

local _has_nvim_010 = vim.fn.has("nvim-0.10") == 1
local _is_win = vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1
Expand Down Expand Up @@ -379,7 +379,7 @@ M.spawn_stdio = function(opts, fn_transform_str, fn_preprocess_str)
-- redirect 'stderr' to 'stdout' on Macs by default
-- only takes effect if 'opts.stderr' was not set
if opts.stderr_to_stdout == nil and
vim.loop.os_uname().sysname == "Darwin" then
uv.os_uname().sysname == "Darwin" then
opts.stderr_to_stdout = true
end

Expand Down
5 changes: 3 additions & 2 deletions lua/fzf-lua/make_entry.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local M = {}

local uv = vim.uv or vim.loop
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"
local libuv = require "fzf-lua.libuv"
Expand Down Expand Up @@ -230,7 +231,7 @@ M.preprocess = function(opts)
end

if opts.cwd_only and not opts.cwd then
opts.cwd = vim.loop.cwd()
opts.cwd = uv.cwd()
end

if opts.file_icons then
Expand Down Expand Up @@ -317,7 +318,7 @@ M.file = function(x, opts)
if path.is_absolute(filepath) then
-- filter for cwd only
if opts.cwd_only then
local cwd = opts.cwd or vim.loop.cwd()
local cwd = opts.cwd or uv.cwd()
if not path.is_relative_to(filepath, cwd) then
return nil
end
Expand Down
3 changes: 2 additions & 1 deletion lua/fzf-lua/path.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.uv or vim.loop
local utils = require "fzf-lua.utils"
local libuv = require "fzf-lua.libuv"
local string_sub = string.sub
Expand Down Expand Up @@ -429,7 +430,7 @@ function M.entry_to_file(entry, opts, force_uri)
local newfile = file
for i = 2, #s do
newfile = ("%s:%s"):format(newfile, s[i])
if vim.loop.fs_stat(newfile) then
if uv.fs_stat(newfile) then
file = newfile
line = s[i + 1]
col = s[i + 2]
Expand Down
14 changes: 7 additions & 7 deletions lua/fzf-lua/previewer/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ local utils = require "fzf-lua.utils"
local libuv = require "fzf-lua.libuv"
local Object = require "fzf-lua.class"

local uv = vim.uv or vim.loop
local api = vim.api
local uv = vim.loop
local fn = vim.fn

local Previewer = {}
Expand Down Expand Up @@ -595,7 +595,7 @@ function Previewer.buffer_or_file:populate_preview_buf(entry_str)
-- buffer is not loaded, can happen when calling "lines" with `set nohidden`
-- or when starting nvim with an arglist, fix entry.path since it contains
-- filename only
entry.path = path.relative_to(vim.api.nvim_buf_get_name(entry.bufnr), vim.loop.cwd())
entry.path = path.relative_to(vim.api.nvim_buf_get_name(entry.bufnr), uv.cwd())
end
if not self:should_load_buffer(entry) then
-- same file/buffer as previous entry
Expand Down Expand Up @@ -663,7 +663,7 @@ function Previewer.buffer_or_file:populate_preview_buf(entry_str)
do
local lines = nil
-- make sure the file is readable (or bad entry.path)
local fs_stat = vim.loop.fs_stat(entry.path)
local fs_stat = uv.fs_stat(entry.path)
if not entry.path or not fs_stat then
lines = { string.format("Unable to stat file %s", entry.path) }
elseif fs_stat.size > 0 and utils.perl_file_is_binary(entry.path) then
Expand Down Expand Up @@ -1036,7 +1036,7 @@ function Previewer.marks:parse_entry(entry_str)
else
filepath = res
end
filepath = path.relative_to(filepath, vim.loop.cwd())
filepath = path.relative_to(filepath, uv.cwd())
end
return {
bufnr = bufnr,
Expand All @@ -1059,9 +1059,9 @@ function Previewer.jumps:parse_entry(entry_str)
if filepath then
local ok, res = pcall(vim.fn.expand, filepath)
if ok then
filepath = path.relative_to(res, vim.loop.cwd())
filepath = path.relative_to(res, uv.cwd())
end
if not vim.loop.fs_stat(filepath) then
if not uv.fs_stat(filepath) then
-- file is not accessible,
-- text is a string from current buffer
bufnr = self.win.src_bufnr
Expand Down Expand Up @@ -1228,7 +1228,7 @@ function Previewer.quickfix:populate_preview_buf(entry_str)
for _, e in ipairs(qf_list.items) do
table.insert(lines, string.format("%s|%d col %d|%s",
path.HOME_to_tilde(path.relative_to(
vim.api.nvim_buf_get_name(e.bufnr), vim.loop.cwd())),
vim.api.nvim_buf_get_name(e.bufnr), uv.cwd())),
e.lnum, e.col, e.text))
end
self.tmpbuf = self:get_tmp_buffer()
Expand Down
7 changes: 4 additions & 3 deletions lua/fzf-lua/previewer/fzf.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.uv or vim.loop
local path = require "fzf-lua.path"
local shell = require "fzf-lua.shell"
local utils = require "fzf-lua.utils"
Expand Down Expand Up @@ -178,7 +179,7 @@ end
function Previewer.cmd_async:parse_entry_and_verify(entrystr)
local entry = path.entry_to_file(entrystr, self.opts)
-- make relative for bat's header display
local filepath = path.relative_to(entry.bufname or entry.path or "", vim.loop.cwd())
local filepath = path.relative_to(entry.bufname or entry.path or "", uv.cwd())
if self.opts._ctag then
entry.ctag = path.entry_to_ctag(entry.stripped, true)
if entry.line <= 1 then
Expand All @@ -193,7 +194,7 @@ function Previewer.cmd_async:parse_entry_and_verify(entrystr)
end
local errcmd = nil
-- verify the file exists on disk and is accessible
if #filepath == 0 or not vim.loop.fs_stat(filepath) then
if #filepath == 0 or not uv.fs_stat(filepath) then
errcmd = "echo " .. libuv.shellescape(
string.format("'%s: NO SUCH FILE OR ACCESS DENIED",
filepath and #filepath > 0 and filepath or "<null>"))
Expand Down Expand Up @@ -329,7 +330,7 @@ function Previewer.git_diff:cmdline(o)
elseif is_deleted then
cmd = self.cmd_deleted
elseif is_untracked then
local stat = vim.loop.fs_stat(file.path)
local stat = uv.fs_stat(file.path)
if stat and stat.type == "directory" then
cmd = utils._if_win({ "dir" }, { "ls", "-la" })
else
Expand Down
7 changes: 4 additions & 3 deletions lua/fzf-lua/providers/buffers.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.uv or vim.loop
local core = require "fzf-lua.core"
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"
Expand Down Expand Up @@ -36,7 +37,7 @@ local filter_buffers = function(opts, unfiltered)
excluded[b] = true
elseif opts.no_term_buffers and utils.is_term_buffer(b) then
excluded[b] = true
elseif opts.cwd_only and not path.is_relative_to(vim.api.nvim_buf_get_name(b), vim.loop.cwd()) then
elseif opts.cwd_only and not path.is_relative_to(vim.api.nvim_buf_get_name(b), uv.cwd()) then
excluded[b] = true
elseif opts.cwd and not path.is_relative_to(vim.api.nvim_buf_get_name(b), opts.cwd) then
excluded[b] = true
Expand Down Expand Up @@ -130,7 +131,7 @@ local function gen_buffer_entry(opts, buf, max_bufnr, cwd)
bname = make_entry.lcol({ filename = bname, lnum = buf.info.lnum }, opts):gsub(":$", "")
return make_entry.file(bname, vim.tbl_extend("force", opts,
-- No support for git_icons, file_icons are added later
{ cwd = cwd or opts.cwd or vim.loop.cwd(), file_icons = false, git_icons = false }))
{ cwd = cwd or opts.cwd or uv.cwd(), file_icons = false, git_icons = false }))
end
end)()
if buf.flag == "%" then
Expand Down Expand Up @@ -368,7 +369,7 @@ M.tabs = function(opts)
local title, fn_title_hl = opt_hl("tab_title",
function(s)
return string.format("%s%s#%d%s", s, utils.nbsp, t,
(vim.loop.cwd() == tab_cwd and ""
(uv.cwd() == tab_cwd and ""
or string.format(": %s", tab_cwd_tilde)))
end,
utils.ansi_codes[opts.hls.tab_title])
Expand Down
3 changes: 2 additions & 1 deletion lua/fzf-lua/providers/dap.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.uv or vim.loop
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"
local shell = require "fzf-lua.shell"
Expand Down Expand Up @@ -90,7 +91,7 @@ M.breakpoints = function(opts)
end

-- display relative paths by default
if opts.cwd == nil then opts.cwd = vim.loop.cwd() end
if opts.cwd == nil then opts.cwd = uv.cwd() end

-- set parent_idx base for `formatter=path.filename_first`
opts._parent_idx = 3
Expand Down
3 changes: 2 additions & 1 deletion lua/fzf-lua/providers/diagnostic.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local uv = vim.uv or vim.loop
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"
Expand Down Expand Up @@ -36,7 +37,7 @@ M.diagnostics = function(opts)

-- required for relative paths presentation
if not opts.cwd or #opts.cwd == 0 then
opts.cwd = vim.loop.cwd()
opts.cwd = uv.cwd()
else
opts.cwd_only = true
end
Expand Down
Loading

0 comments on commit b99b4fd

Please sign in to comment.