Skip to content

Commit

Permalink
test: create intermediate directories for storage
Browse files Browse the repository at this point in the history
  • Loading branch information
lopi-py committed Aug 30, 2024
1 parent b9ea154 commit b440f90
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
6 changes: 2 additions & 4 deletions lua/luau-lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ function M.aliases(paths)
return
end

local success, contents = pcall(json.decode, luaurc:read "a")
if not success then
local ok, contents = pcall(json.decode, luaurc:read "a")
if not ok then
log.error("Failed to read '.luaurc': %s", contents)
return
end

local aliases = vim.empty_dict()

for alias, value in pairs(contents.aliases or {}) do
aliases["@" .. alias] = value
end

return aliases
end

Expand Down
2 changes: 1 addition & 1 deletion lua/luau-lsp/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end
function M.storage_file(key)
local path = M.joinpath(vim.fn.stdpath "data", "luau-lsp")
if not M.is_dir(path) then
vim.uv.fs_mkdir(path, 448)
vim.fn.mkdir(path, "p")
end
return M.joinpath(path, key)
end
Expand Down
29 changes: 25 additions & 4 deletions spec/json_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local json = require "luau-lsp.json"

describe("json5 decoder", function()
it("should decode with comments", function()
local success, contents = pcall(
local ok, contents = pcall(
json.decode,
[[
// .luaurc
Expand All @@ -14,15 +14,15 @@ describe("json5 decoder", function()
]]
)

assert.is_true(success)
assert.is_true(ok)
assert.same({
foo = "foo",
bar = "bar",
}, contents)
end)

it("should decode with trailing commas", function()
local success, contents = pcall(
local ok, contents = pcall(
json.decode,
[[
{
Expand All @@ -32,10 +32,31 @@ describe("json5 decoder", function()
]]
)

assert.is_true(success)
assert.is_true(ok)
assert.same({
foo = "foo",
bar = "bar",
}, contents)
end)

it("should decode nesting fields", function()
local ok, contents = pcall(
json.decode,
[[
{
// nested
"foo": {
"bar": "baz",
},
},
]]
)

assert.is_true(ok)
assert.same({
foo = {
bar = "baz",
},
}, contents)
end)
end)

0 comments on commit b440f90

Please sign in to comment.