Skip to content

Commit 5d013f0

Browse files
committed
Relativize edited paths.
1 parent 13f903e commit 5d013f0

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

autoload/node/lib.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function! node#lib#find(name, from)
2323
endif
2424

2525
let l:path = s:resolve(s:absolutize(a:name, a:from))
26-
if !empty(path) | return resolve(path) | endif
26+
if !empty(path) | return fnamemodify(resolve(path), ":.") | endif
2727
endfunction
2828

2929
function! node#lib#version()

test/autoload/lib_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
include WithTemporaryDirectory
66

77
before do
8+
# Some tests may change the working directory, so reset it to a known good.
9+
$vim.command "cd #{Dir.getwd}"
810
Dir.mkdir File.join(@dir, "node_modules")
911
end
1012

test/autoload_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@
156156
$vim.echo(%(bufname("%"))).must_equal target
157157
end
158158

159+
it "must relativize paths" do
160+
touch File.join(@dir, "index.js"), %(require("root/foo"))
161+
target = touch File.join(@dir, "foo.js")
162+
FileUtils.mkpath File.join(@dir, "node_modules")
163+
File.symlink "..", File.join(@dir, "node_modules", "root")
164+
165+
$vim.edit File.join(@dir, "index.js")
166+
$vim.command %(:cd %:h)
167+
$vim.feedkeys "$hhgf"
168+
$vim.echo(%(bufname("%"))).must_equal File.basename(target)
169+
end
170+
159171
it "must not show an error when searching for nothing" do
160172
touch File.join(@dir, "index.js"), %("")
161173

0 commit comments

Comments
 (0)