Skip to content

Commit 13f903e

Browse files
committed
Resolve symlinks before editing.
1 parent 5c72035 commit 13f903e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
- Updates URLs to use <https://github.com/nodejs/node> instead of the previous
1111
Joyent repo.
1212
Thanks, [Jacky Alciné](https://jacky.wtf), for the help!
13+
- Resolves symlinks in paths before editing a file.
14+
Shows correct paths when using the relative symlink trick in `node_modules` (`ln -s .. node_modules/root`) and using `gf` on `require("root/lib/foo")`.
1315

1416
## 0.8.1 (Apr 15, 2014)
1517
- Updates the URL from which Node.vim downloads Node core module source files.

autoload/node/lib.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function! node#lib#find(name, from)
2222
return s:CORE_URL_PREFIX ."/". l:version ."/". l:dir ."/". a:name .".js"
2323
endif
2424

25-
return s:resolve(s:absolutize(a:name, a:from))
25+
let l:path = s:resolve(s:absolutize(a:name, a:from))
26+
if !empty(path) | return resolve(path) | endif
2627
endfunction
2728

2829
function! node#lib#version()

test/autoload_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@
145145
$vim.echo(%(bufname("%"))).must_equal target
146146
end
147147

148+
it "must edit ./foo.js given root/foo with root as symlink" do
149+
touch File.join(@dir, "index.js"), %(require("root/foo"))
150+
target = touch File.join(@dir, "foo.js")
151+
FileUtils.mkpath File.join(@dir, "node_modules")
152+
File.symlink "..", File.join(@dir, "node_modules", "root")
153+
154+
$vim.edit File.join(@dir, "index.js")
155+
$vim.feedkeys "$hhgf"
156+
$vim.echo(%(bufname("%"))).must_equal target
157+
end
158+
148159
it "must not show an error when searching for nothing" do
149160
touch File.join(@dir, "index.js"), %("")
150161

0 commit comments

Comments
 (0)