vscode-loader: correctly handle symlinked package.json (close #1170).

This commit is contained in:
L3MON4D3 2024-05-14 12:19:32 +02:00
parent b152822e1a
commit 2b7395217e
7 changed files with 54 additions and 8 deletions

View file

@ -434,14 +434,13 @@ local function get_manifests(paths)
-- Get path to package.json/package.jsonc, or continue if it does not exist.
for _, dir in ipairs(paths) do
local tentative_manifest_path =
Path.expand(Path.join(dir, "package.json"))
-- expand returns nil for paths that don't exist.
if tentative_manifest_path then
Path.expand_keep_symlink(Path.join(dir, "package.json"))
if Path.exists(tentative_manifest_path) then
table.insert(manifest_paths, tentative_manifest_path)
else
tentative_manifest_path =
Path.expand(Path.join(dir, "package.jsonc"))
if tentative_manifest_path then
Path.expand_keep_symlink(Path.join(dir, "package.jsonc"))
if Path.exists(tentative_manifest_path) then
table.insert(manifest_paths, tentative_manifest_path)
else
log.warn(

View file

@ -63,11 +63,16 @@ else
MYCONFIG_ROOT = vim.fn.getcwd()
end
function Path.expand(filepath)
local expanded = filepath
-- sometimes we don't want to resolve symlinks, but handle ~/ and ./
function Path.expand_keep_symlink(filepath)
-- omit second return-value of :gsub
local res = filepath
:gsub("^~", vim.env.HOME)
:gsub("^[.][/\\]", MYCONFIG_ROOT .. sep)
return uv.fs_realpath(expanded)
return res
end
function Path.expand(filepath)
return uv.fs_realpath(Path.expand_keep_symlink(filepath))
end
-- do our best at normalizing a non-existing path.

View file

@ -0,0 +1,8 @@
{
"snip1": {
"prefix": "all1",
"body": [
"expands? jumps? !"
]
}
}

View file

@ -0,0 +1,13 @@
{
"name": "example-snippets",
"contributes": {
"snippets": [
{
"language": [
"all"
],
"path": "./all.json"
}
]
}
}

View file

@ -0,0 +1 @@
../abcde-all.json

View file

@ -0,0 +1 @@
../abcde-package.json

View file

@ -1109,4 +1109,23 @@ describe("loaders:", function()
{2:-- INSERT --} |]],
})
end)
it("vscode correctly loads files if package.json is symlinked.", function()
exec_lua(
string.format(
[[ require("luasnip.loaders.from_vscode").load({ paths={"%s"} }) ]],
os.getenv("LUASNIP_SOURCE") .. "/tests/data/symlink-vscode/snippets"
)
)
feed("iall1")
exec_lua("ls.expand()")
screen:expect({
grid = [[
expands? jumps? !^ |
{0:~ }|
{0:~ }|
{0:~ }|
{2:-- INSERT --} |]]
})
end)
end)