mirror of
https://github.com/L3MON4D3/LuaSnip
synced 2024-09-16 21:54:03 +02:00
vscode-loader: correctly handle symlinked package.json (close #1170).
This commit is contained in:
parent
b152822e1a
commit
2b7395217e
7 changed files with 54 additions and 8 deletions
|
@ -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(
|
||||
|
|
|
@ -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.
|
||||
|
|
8
tests/data/symlink-vscode/abcde-all.json
Normal file
8
tests/data/symlink-vscode/abcde-all.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"snip1": {
|
||||
"prefix": "all1",
|
||||
"body": [
|
||||
"expands? jumps? !"
|
||||
]
|
||||
}
|
||||
}
|
13
tests/data/symlink-vscode/abcde-package.json
Normal file
13
tests/data/symlink-vscode/abcde-package.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "example-snippets",
|
||||
"contributes": {
|
||||
"snippets": [
|
||||
{
|
||||
"language": [
|
||||
"all"
|
||||
],
|
||||
"path": "./all.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
1
tests/data/symlink-vscode/snippets/all.json
Symbolic link
1
tests/data/symlink-vscode/snippets/all.json
Symbolic link
|
@ -0,0 +1 @@
|
|||
../abcde-all.json
|
1
tests/data/symlink-vscode/snippets/package.json
Symbolic link
1
tests/data/symlink-vscode/snippets/package.json
Symbolic link
|
@ -0,0 +1 @@
|
|||
../abcde-package.json
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue