From b440f907433b5ac4cd8bcd6351baafb449f074ce Mon Sep 17 00:00:00 2001 From: lopy <70210066+lopi-py@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:46:20 -0500 Subject: [PATCH] test: create intermediate directories for storage --- lua/luau-lsp/init.lua | 6 ++---- lua/luau-lsp/util.lua | 2 +- spec/json_spec.lua | 29 +++++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lua/luau-lsp/init.lua b/lua/luau-lsp/init.lua index 342f136..521d7ab 100644 --- a/lua/luau-lsp/init.lua +++ b/lua/luau-lsp/init.lua @@ -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 diff --git a/lua/luau-lsp/util.lua b/lua/luau-lsp/util.lua index 0e6d6f4..87e063d 100644 --- a/lua/luau-lsp/util.lua +++ b/lua/luau-lsp/util.lua @@ -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 diff --git a/spec/json_spec.lua b/spec/json_spec.lua index d24fa5a..4ff7ad9 100644 --- a/spec/json_spec.lua +++ b/spec/json_spec.lua @@ -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 @@ -14,7 +14,7 @@ describe("json5 decoder", function() ]] ) - assert.is_true(success) + assert.is_true(ok) assert.same({ foo = "foo", bar = "bar", @@ -22,7 +22,7 @@ describe("json5 decoder", function() end) it("should decode with trailing commas", function() - local success, contents = pcall( + local ok, contents = pcall( json.decode, [[ { @@ -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)