mirror of
https://github.com/Myzel394/jsonfly.nvim.git
synced 2025-06-18 12:15:25 +02:00
fix: Improve key extractor; Allow more patterns
This commit is contained in:
parent
ca9cbbda24
commit
48503b7a50
@ -142,7 +142,19 @@ function M:extract_key_description(text)
|
|||||||
while index <= #splitted do
|
while index <= #splitted do
|
||||||
local token = splitted[index]
|
local token = splitted[index]
|
||||||
|
|
||||||
if string.sub(token, 1, 1) == "[" then
|
-- Escape
|
||||||
|
if string.sub(token, 1, 1) == "\\" then
|
||||||
|
token = token:sub(2)
|
||||||
|
|
||||||
|
keys[#keys + 1] = {
|
||||||
|
type = "object_wrapper",
|
||||||
|
}
|
||||||
|
keys[#keys + 1] = {
|
||||||
|
key = token,
|
||||||
|
type = "key",
|
||||||
|
}
|
||||||
|
-- Array
|
||||||
|
elseif string.match(token, "%[%d+%]") then
|
||||||
local array_index = tonumber(string.sub(token, 2, -2))
|
local array_index = tonumber(string.sub(token, 2, -2))
|
||||||
|
|
||||||
keys[#keys + 1] = {
|
keys[#keys + 1] = {
|
||||||
@ -152,6 +164,18 @@ function M:extract_key_description(text)
|
|||||||
key = array_index,
|
key = array_index,
|
||||||
type = "array_index",
|
type = "array_index",
|
||||||
}
|
}
|
||||||
|
-- Array
|
||||||
|
elseif string.match(token, "%d+") then
|
||||||
|
local array_index = tonumber(token)
|
||||||
|
|
||||||
|
keys[#keys + 1] = {
|
||||||
|
type = "array_wrapper",
|
||||||
|
}
|
||||||
|
keys[#keys + 1] = {
|
||||||
|
key = array_index,
|
||||||
|
type = "array_index",
|
||||||
|
}
|
||||||
|
-- Object
|
||||||
else
|
else
|
||||||
keys[#keys + 1] = {
|
keys[#keys + 1] = {
|
||||||
type = "object_wrapper",
|
type = "object_wrapper",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user