Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Support [WIP] #1001

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 28 additions & 36 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
{
"runtime.version": "LuaJIT",
"diagnostics": {
"enable": true,
"globals": [
"vim",
"describe",
"pending",
"it",
"before_each",
"after_each",
],
"neededFileStatus": {
"codestyle-check": "Any"
},
"disable": [
"need-check-nil",
"missing-parameter",
"cast-local-type",
],
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
"runtime.version": "LuaJIT",
"diagnostics": {
"enable": true,
"globals": ["vim"],
"neededFileStatus": {
"codestyle-check": "Any"
},
"workspace": {
"library": [
"$VIMRUNTIME/lua",
],
"checkThirdParty": false,
"maxPreload": 2000,
"preloadFileSize": 1000,
"ignoreDir": [
"tests/",
],
},
"type": {
"weakNilCheck": true,
"weakUnionCheck": true,
"castNumberToInteger": true,
},
"telemetry.enable": false
"disable": ["need-check-nil", "missing-parameter", "cast-local-type"]
},
"workspace": {
"library": [
"lua",
"$VIMRUNTIME/lua",
"${3rd}/luv/library",
"$XDG_DATA_HOME/nvim/lazy/plenary.nvim/lua",
"$LOCALAPPDATA/nvim-data/lazy/plenary.nvim/lua"
],
"checkThirdParty": false,
"maxPreload": 2000,
"preloadFileSize": 1000,
"ignoreDir": ["tests/"]
},
"type": {
"weakNilCheck": true,
"weakUnionCheck": true,
"castNumberToInteger": true
},
"telemetry.enable": false
}
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,6 @@ require'fzf-lua'.setup {
.. " %(subject) %(color:blue)%(taggername)%(color:reset)' refs/tags",
preview = "git log --graph --color --pretty=format:'%C(yellow)%h%Creset "
.. "%Cgreen(%><(12)%cr%><|(12))%Creset %s %C(blue)<%an>%Creset' {1}",
fzf_opts = { ["--no-multi"] = "" },
actions = { ["default"] = actions.git_checkout },
},
stash = {
Expand All @@ -888,10 +887,6 @@ require'fzf-lua'.setup {
["default"] = actions.git_stash_apply,
["ctrl-x"] = { fn = actions.git_stash_drop, reload = true },
},
fzf_opts = {
["--no-multi"] = '',
['--delimiter'] = "'[:]'",
},
},
icons = {
["M"] = { icon = "M", color = "yellow" },
Expand Down Expand Up @@ -1341,3 +1336,4 @@ I missed your name feel free to contact me and I'll add it below:
- [@kevinhwang91](https://github.com/kevinhwang91) for using his previewer
code as baseline for the builtin previewer and his must have plugin
[nvim-bqf](https://github.com/kevinhwang91/nvim-bqf)

7 changes: 1 addition & 6 deletions doc/fzf-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,6 @@ open an issue and I'll be more than happy to help.**
.. " %(subject) %(color:blue)%(taggername)%(color:reset)' refs/tags",
preview = "git log --graph --color --pretty=format:'%C(yellow)%h%Creset "
.. "%Cgreen(%><(12)%cr%><|(12))%Creset %s %C(blue)<%an>%Creset' {1}",
fzf_opts = { ["--no-multi"] = "" },
actions = { ["default"] = actions.git_checkout },
},
stash = {
Expand All @@ -981,10 +980,6 @@ open an issue and I'll be more than happy to help.**
["default"] = actions.git_stash_apply,
["ctrl-x"] = { fn = actions.git_stash_drop, reload = true },
},
fzf_opts = {
["--no-multi"] = '',
['--delimiter'] = "'[:]'",
},
},
icons = {
["M"] = { icon = "M", color = "yellow" },
Expand Down Expand Up @@ -1438,4 +1433,4 @@ I missed your name feel free to contact me and I'll add it below:
as baseline for the builtin previewer and his must have plugin nvim-bqf
<https://github.com/kevinhwang91/nvim-bqf>

vim:tw=78:ts=8:ft=help:norl:
vim:tw=78:ts=8:ft=help:norl:
20 changes: 12 additions & 8 deletions lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ M.expect = function(actions)
end
end
if #keys > 0 then
return string.format("--expect=%s", table.concat(keys, ","))
return table.concat(keys, ",")
end
return nil
end
Expand Down Expand Up @@ -104,7 +104,7 @@ M.vimcmd_file = function(vimcmd, selected, opts)
if entry.path == "<none>" then goto continue end
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.starts_with_separator(fullpath) then
if not path.is_absolute(fullpath) then
fullpath = path.join({ opts.cwd or opts._cwd or vim.loop.cwd(), fullpath })
end
if vimcmd == "e"
Expand All @@ -128,7 +128,7 @@ M.vimcmd_file = function(vimcmd, selected, opts)
if vimcmd ~= "e" or curbuf ~= fullpath then
if entry.path then
-- do not run ':<cmd> <file>' for uri entries (#341)
local relpath = path.relative(entry.path, vim.loop.cwd())
local relpath = path.relative_to(entry.path, vim.loop.cwd())
if vim.o.autochdir then
-- force full paths when `autochdir=true` (#882)
relpath = fullpath
Expand Down Expand Up @@ -245,7 +245,7 @@ M.file_switch = function(selected, opts)
local bufnr = nil
local entry = path.entry_to_file(selected[1])
local fullpath = entry.path
if not path.starts_with_separator(fullpath) then
if not path.is_absolute(fullpath) then
fullpath = path.join({ opts.cwd or vim.loop.cwd(), fullpath })
end
for _, b in ipairs(vim.api.nvim_list_bufs()) do
Expand Down Expand Up @@ -629,7 +629,7 @@ end
local git_exec = function(selected, opts, cmd, silent)
local success
for _, e in ipairs(selected) do
local file = path.relative(path.entry_to_file(e, opts).path, opts.cwd)
local file = path.relative_to(path.entry_to_file(e, opts).path, opts.cwd)
local _cmd = vim.deepcopy(cmd)
table.insert(_cmd, file)
local output, rc = utils.io_systemlist(_cmd)
Expand Down Expand Up @@ -706,7 +706,7 @@ M.git_buf_edit = function(selected, opts)
local git_root = path.git_root(opts, true)
local win = vim.api.nvim_get_current_win()
local buffer_filetype = vim.bo.filetype
local file = path.relative(vim.fn.expand("%:p"), git_root)
local file = path.relative_to(vim.fn.expand("%:p"), git_root)
local commit_hash = match_commit_hash(selected[1], opts)
table.insert(cmd, commit_hash .. ":" .. file)
local git_file_contents = utils.io_systemlist(cmd)
Expand Down Expand Up @@ -812,9 +812,13 @@ M.set_qflist = function(selected, opts)
vim.cmd(opts._is_loclist and "lopen" or "copen")
end

---@param selected string[]
---@param opts table
M.apply_profile = function(selected, opts)
local fname = selected[1]:match("[^:]+")
local profile = selected[1]:match(":([^%s]+)")
local entry = path.entry_to_file(selected[1])
local fname = entry.path
local profile = entry.stripped:sub(#fname + 2):match("[^%s]+")
print(profile, fname)
local ok = utils.load_profile(fname, profile, opts.silent)
if ok then
vim.cmd(string.format([[lua require("fzf-lua").setup({"%s"})]], profile))
Expand Down
10 changes: 4 additions & 6 deletions lua/fzf-lua/complete.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ local function find_toplevel_cwd(maybe_cwd, postfix, orig_cwd)
if vim.fn.isdirectory(vim.fn.expand(maybe_cwd)) == 1 then
local disp_cwd, cwd = maybe_cwd, vim.fn.expand(maybe_cwd)
-- returned cwd must be full path
if cwd:sub(1, 1) == "." and cwd:sub(2, 2) == path.SEPARATOR then
if path.has_cwd_prefix(cwd) then
cwd = vim.loop.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.starts_with_separator(cwd) then
elseif not path.is_absolute(cwd) then
cwd = path.join({ vim.loop.cwd(), cwd })
end
return disp_cwd, cwd, postfix
Expand Down Expand Up @@ -60,15 +60,13 @@ local set_cmp_opts_path = function(opts)
if not opts.prompt then
opts.prompt = "."
end
if not path.ends_with_separator(opts.prompt) then
opts.prompt = opts.prompt .. path.SEPARATOR
end
opts.prompt = path.add_trailing(opts.prompt)
-- completion function rebuilds the line with the full path
opts.complete = function(selected, o, l, _)
-- query fuzzy matching is empty
if #selected == 0 then return end
local replace_at = col - #before
local relpath = path.relative(path.entry_to_file(selected[1], o).path, opts.cwd)
local relpath = path.relative_to(path.entry_to_file(selected[1], o).path, opts.cwd)
local before_path = replace_at > 1 and l:sub(1, replace_at - 1) or ""
local rest_of_line = #l >= (col + #after) and l:sub(col + #after) or ""
local resolved_path = opts._cwd and path.join({ opts._cwd, relpath }) or relpath
Expand Down
11 changes: 9 additions & 2 deletions lua/fzf-lua/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if utils.__HAS_DEVICONS then

-- get the devicons module path
M._devicons_path = M._has_devicons and M._devicons and M._devicons.setup
and debug.getinfo(M._devicons.setup, "S").source:gsub("^@", "")
and path.normalize(debug.getinfo(M._devicons.setup, "S").source:gsub("^@", ""))
end

M._diricon_escseq = function()
Expand Down Expand Up @@ -120,6 +120,8 @@ M.resume_set = function(what, val, opts)
-- _G.dump("resume_set", key1, utils.map_get(M, key1))
end

---@param opts {resume: boolean, __call_opts: table}
---@return table
function M.resume_opts(opts)
assert(opts.resume and opts.__call_opts)
local __call_opts = M.resume_get(nil, opts)
Expand Down Expand Up @@ -191,6 +193,9 @@ do
m.globals = M.globals
end

---@param opts table<string, unknown>|fun():table?
---@param globals string|table?
---@param __resume_key string?
function M.normalize_opts(opts, globals, __resume_key)
if not opts then opts = {} end

Expand Down Expand Up @@ -235,6 +240,8 @@ function M.normalize_opts(opts, globals, __resume_key)
end

-- normalize all binds as lowercase or we can have duplicate keys (#654)
---@param m {fzf: table<string, unknown>, builtin: table<string, unknown>}
---@return {fzf: table<string, unknown>, builtin: table<string, unknown>}?
local keymap_tolower = function(m)
return m and {
fzf = utils.map_tolower(m.fzf),
Expand Down Expand Up @@ -420,7 +427,7 @@ function M.normalize_opts(opts, globals, __resume_key)
-- 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)
if not path.starts_with_separator(opts.cwd) then
if not path.is_absolute(opts.cwd) then
opts.cwd = path.join({ vim.loop.cwd(), opts.cwd })
end
end
Expand Down
Loading