summaryrefslogtreecommitdiff
path: root/script/json-edit.lua
diff options
context:
space:
mode:
authorAndreas <andreas.matthias@gmail.com>2024-02-26 12:56:38 +0100
committerAndreas <andreas.matthias@gmail.com>2024-02-26 12:56:38 +0100
commit8d31712f38a48dc814657d00b7e63d083bd888dc (patch)
tree849fb5f80548b333a67c43cf70c62dd6fd93c6e8 /script/json-edit.lua
parent96a11fb83ccbd388fd420403969f0a575238c6a2 (diff)
parentc156377201f70db009d8bcfcf664370ea3f0eec2 (diff)
downloadlua-language-server-8d31712f38a48dc814657d00b7e63d083bd888dc.zip
Merge branch 'master' into doc-update
Diffstat (limited to 'script/json-edit.lua')
-rw-r--r--script/json-edit.lua13
1 files changed, 11 insertions, 2 deletions
diff --git a/script/json-edit.lua b/script/json-edit.lua
index 30a55250..efa1216f 100644
--- a/script/json-edit.lua
+++ b/script/json-edit.lua
@@ -384,6 +384,7 @@ end
local JsonEmpty = function () end
+---@return {s: integer, d:integer, f:integer, v: any}
local function decode_ast(str)
if type(str) ~= "string" then
error("expected argument of type string, got " .. type(str))
@@ -607,7 +608,11 @@ function OP.add(str, option, path, value)
end
local ast = decode_ast(str)
if ast.v == JsonEmpty then
- local pathlst = split_path(path)
+ local pathlst, err = split_path(path)
+ if not pathlst then
+ error(err)
+ return
+ end
value = add_prefix(value, pathlst)
return json.beautify(value, option)
end
@@ -674,7 +679,11 @@ function OP.replace(str, option, path, value)
end
local ast = decode_ast(str)
if ast.v == JsonEmpty then
- local pathlst = split_path(path)
+ local pathlst, err = split_path(path)
+ if not pathlst then
+ error(err)
+ return
+ end
value = add_prefix(value, pathlst)
return json.beautify(value, option)
end