Skip to content

Commit f82f986

Browse files
phanenibhagwan
authored andcommitted
fix: Unable to stat file after cwd change
1 parent d8144cd commit f82f986

14 files changed

+89
-13
lines changed

lua/fzf-lua/path.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,9 @@ function M.entry_to_file(entry, opts, force_uri)
425425
stripped = M.tilde_to_HOME(stripped)
426426
-- Prepend cwd unless entry is already a URI (e.g. nvim-jdtls "jdt://...")
427427
local isURI = stripped:match("^%a+://")
428-
if opts.cwd and #opts.cwd > 0 and not isURI and not M.is_absolute(stripped) then
429-
stripped = M.join({ opts.cwd, stripped })
428+
local cwd = opts.cwd or opts._cwd
429+
if cwd and #cwd > 0 and not isURI and not M.is_absolute(stripped) then
430+
stripped = M.join({ cwd, stripped })
430431
end
431432
--Force LSP jumps using `vim.lsp.util.show_document` so that LSP entries are
432433
--added to the tag stack (see `:help gettagstack`)

tests/file/ui_spec.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,20 @@ T["files()"]["executable"] = new_set({ parametrize = { { "fd" }, { "rg" }, { "fi
170170
end,
171171
})
172172

173+
T["files()"]["preview should work after chdir #1864"] = function()
174+
-- Ignore last "-- TERMINAL --" line and "[DEBUG]" line containing the cmd
175+
local screen_opts = { ignore_lines = { 6, 28 }, normalize_paths = helpers.IS_WIN() }
176+
eq(child.lua_get([[_G._fzf_lua_on_create]]), vim.NIL)
177+
child.lua([[FzfLua.files {
178+
cwd_prompt = false,
179+
previewer = 'builtin',
180+
winopts = { preview = { hidden = false } }
181+
}]])
182+
child.wait_until(function() return child.lua_get([[_G._fzf_load_called]]) == true end)
183+
child.lua([[vim.cmd.cd("./tests")]])
184+
child.type_keys([[<c-n>]])
185+
sleep(100)
186+
child.expect_screen_lines(screen_opts)
187+
end
188+
173189
return T

tests/screenshots/tests-file-ui_spec.lua---files()---executable---1-+-args-{-'fd'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭─────────────────── Files h ────────────────────╮
5-
04|~ │> 110/110 (0) │
5+
04|~ │> 111/111 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] fd --hidden --color=never --type f -··││
88
07|~ │ .editorconfig ││

tests/screenshots/tests-file-ui_spec.lua---files()---executable---1-+-args-{-'find-dir'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 110/110 (0) │
5+
04|~ │> 111/111 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] find . -type f -not -path '*/\.git/*··││
88
07|~ │ .editorconfig ││

tests/screenshots/tests-file-ui_spec.lua---files()---executable---1-+-args-{-'rg'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭─────────────────── Files h ────────────────────╮
5-
04|~ │> 110/110 (0) │
5+
04|~ │> 111/111 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] rg --hidden --files -g "!.git" --sor··││
88
07|~ │ .editorconfig ││

tests/screenshots/tests-file-ui_spec.lua---files()---icons---defaults---1-+-args-{-'devicons',-'+attrs'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 98/98 (0) │
5+
04|~ │> 99/99 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌  LICENSE ││
88
07|~ │  Makefile ││

tests/screenshots/tests-file-ui_spec.lua---files()---icons---defaults---1-+-args-{-'devicons',-'-attrs'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 98/98 (0) │
5+
04|~ │> 99/99 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌  LICENSE ││
88
07|~ │  Makefile ││

tests/screenshots/tests-file-ui_spec.lua---files()---icons---defaults---1-+-args-{-'mini',-'+attrs'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 98/98 (0) │
5+
04|~ │> 99/99 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌  LICENSE ││
88
07|~ │ 󱁤 Makefile ││

tests/screenshots/tests-file-ui_spec.lua---files()---icons---defaults---1-+-args-{-'mini',-'-attrs'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 98/98 (0) │
5+
04|~ │> 99/99 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌  LICENSE ││
88
07|~ │ 󱁤 Makefile ││
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--|---------|---------|---------|---------|---------|---------|----
2+
01|
3+
02|~
4+
03|~ ╭─────────────────── Files h ────────────────────╮
5+
04|~ │> 110/110 (0) │
6+
05|~ │──────────────────────────────────────────────── │
7+
06|~ │ .editorconfig ││
8+
07|~ │▌ .github/ISSUE_TEMPLATE/bug.yaml │
9+
08|~ │ .github/ISSUE_TEMPLATE/config.yml │
10+
09|~ │ .github/ISSUE_TEMPLATE/feature.yaml │
11+
10|~ │ .github/workflows/ci.yaml │
12+
11|~ │ .github/workflows/luarocks-release.yaml │
13+
12|~ │ .github/workflows/sync_remote.yaml │
14+
13|~ ╰─────────────────────────────────────────────────╯
15+
14|~ ╭─────────────────── bug.yaml ────────────────────╮
16+
15|~ │ 1 name: 🐞 Bug Report
17+
16|~ │ 2 description: File a bug/issue │
18+
17|~ │ 3 labels: [bug] │
19+
18|~ │ 4 title: "Bug: " │
20+
19|~ │ 5 body: │
21+
20|~ │ 6 - type: markdown │
22+
21|~ │ 7 attributes: │
23+
22|~ ╰─────────────────────────────────────────────────╯
24+
23|~
25+
24|[No Name] 0,0-1 All
26+
25|
27+
26|
28+
27|
29+
28|-- TERMINAL -- 1,3 All
30+
31+
--|-
32+
01|
33+
02|
34+
03|
35+
04|
36+
05|
37+
06|
38+
07|
39+
08|
40+
09|
41+
10|
42+
11|
43+
12|
44+
13|
45+
14|
46+
15|
47+
16|
48+
17|
49+
18|
50+
19|
51+
20|
52+
21|
53+
22|
54+
23|
55+
24|
56+
25|
57+
26|
58+
27|
59+
28|

tests/screenshots/tests-file-ui_spec.lua---files()---previewer---1-+-args-{-'builtin'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 98/98 (0) │
5+
04|~ │> 99/99 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ LICENSE ││
88
07|~ │ Makefile │

tests/screenshots/tests-file-ui_spec.lua---files()---previewer---1-+-args-{-'ci'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 98/98 (0) │
5+
04|~ │> 99/99 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ LICENSE ││
88
07|~ │ Makefile │

tests/screenshots/tests-file-ui_spec.lua---files()---start-and-abort---1-+-args-{-'-c-c-'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 98/98 (0) │
5+
04|~ │> 99/99 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ LICENSE ││
88
07|~ │ Makefile ││

tests/screenshots/tests-file-ui_spec.lua---files()---start-and-abort---1-+-args-{-'-esc-'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 98/98 (0) │
5+
04|~ │> 99/99 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ LICENSE ││
88
07|~ │ Makefile ││

0 commit comments

Comments
 (0)