summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
Diffstat (limited to 'script/core')
-rw-r--r--script/core/hover/table.lua113
-rw-r--r--script/core/noder.lua14
-rw-r--r--script/core/searcher.lua2
3 files changed, 42 insertions, 87 deletions
diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua
index 35972155..159453e6 100644
--- a/script/core/hover/table.lua
+++ b/script/core/hover/table.lua
@@ -57,95 +57,36 @@ local function buildAsConst(keys, inferMap, literalMap, reachMax)
return table.concat(lines, '\n')
end
-local function clearClasses(classes)
- classes['[nil]'] = nil
- classes['[any]'] = nil
- classes['[string]'] = nil
-end
-
---[[
-return function (source)
- if config.config.hover.previewFields <= 0 then
- return 'table'
- end
- local literals = {}
- local classes = {}
- local clock = os.clock()
- local timeUp
- local mark = {}
- local fields = vm.getFields(source, 0)
- local keyCount = 0
- local reachMax
- for _, src in ipairs(fields) do
- local key = getKey(src)
- if not key then
- goto CONTINUE
- end
- if not classes[key] then
- classes[key] = {}
- keyCount = keyCount + 1
- end
- if not literals[key] then
- literals[key] = {}
- end
- if not TEST and os.clock() - clock > config.config.hover.fieldInfer / 1000.0 then
- timeUp = true
- end
- local class, literal = getField(src, timeUp, mark, key)
- if literal == 'nil' then
- literal = nil
- end
- classes[key][#classes[key]+1] = class
- literals[key][#literals[key]+1] = literal
- if keyCount >= config.config.hover.previewFields then
- reachMax = true
- break
- end
- ::CONTINUE::
- end
-
- clearClasses(classes)
-
- for key, class in pairs(classes) do
- literals[key] = mergeLiteral(literals[key])
- classes[key] = mergeTypes(class)
- end
-
- if not next(classes) then
- return '{}'
- end
-
- local intValue = true
- for key, class in pairs(classes) do
- if class ~= 'integer' or not tonumber(literals[key]) then
- intValue = false
- break
- end
- end
- local result
- if intValue then
- result = buildAsConst(classes, literals, reachMax)
- else
- result = buildAsHash(classes, literals, reachMax)
- end
- if timeUp then
- result = ('\n--%s\n%s'):format(lang.script.HOVER_TABLE_TIME_UP, result)
- end
- return result
-end
---]]
+local typeSorter = {
+ ['string'] = 1,
+ ['number'] = 2,
+ ['boolean'] = 3,
+}
local function getKeyMap(fields)
local keys = {}
local mark = {}
for _, field in ipairs(fields) do
local key = vm.getKeyName(field)
+ local tp = vm.getKeyType(field)
+ if tp == 'number' then
+ key = tonumber(key)
+ elseif tp == 'boolean' then
+ key = key == 'true'
+ end
if key and not mark[key] then
+ mark[key] = true
keys[#keys+1] = key
end
end
table.sort(keys, function (a, b)
- return tostring(a) < tostring(b)
+ local ta = typeSorter[type(a)]
+ local tb = typeSorter[type(b)]
+ if ta == tb then
+ return tostring(a) < tostring(b)
+ else
+ return ta < tb
+ end
end)
return keys
end
@@ -156,8 +97,8 @@ return function (source)
return 'table'
end
- local fields = vm.getRefs(source, '*')
- local keys = getKeyMap(fields)
+ local fields = vm.getRefs(source, '*')
+ local keys = getKeyMap(fields)
if #keys == 0 then
return '{}'
@@ -178,9 +119,17 @@ return function (source)
end
end
+ local result
+
if isConsts then
- return buildAsConst(keys, inferMap, literalMap, reachMax)
+ result = buildAsConst(keys, inferMap, literalMap, reachMax)
else
- return buildAsHash(keys, inferMap, literalMap, reachMax)
+ result = buildAsHash(keys, inferMap, literalMap, reachMax)
end
+
+ --if timeUp then
+ -- result = ('\n--%s\n%s'):format(lang.script.HOVER_TABLE_TIME_UP, result)
+ --end
+
+ return result
end
diff --git a/script/core/noder.lua b/script/core/noder.lua
index 9031dd07..120bf1ad 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -85,9 +85,12 @@ local function getKey(source)
if not index then
return ANY_FIELD_CHAR, source.node
end
- if index.type == 'string' then
+ if index.type == 'string'
+ or index.type == 'boolean'
+ or index.type == 'number' then
return ('%q'):format(index[1] or ''), source.node
- else
+ elseif index.type ~= 'function'
+ and index.type ~= 'table' then
return ANY_FIELD_CHAR, source.node
end
elseif source.type == 'tableindex' then
@@ -95,9 +98,12 @@ local function getKey(source)
if not index then
return ANY_FIELD_CHAR, source.parent
end
- if index.type == 'string' then
+ if index.type == 'string'
+ or index.type == 'boolean'
+ or index.type == 'number' then
return ('%q'):format(index[1] or ''), source.parent
- else
+ elseif index.type ~= 'function'
+ and index.type ~= 'table' then
return ANY_FIELD_CHAR, source.parent
end
elseif source.type == 'table' then
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 61c7c150..7eb11a97 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -559,7 +559,7 @@ function m.searchFields(status, source, mode, field)
getField(status, def, mode)
end
else
- local fullID = id .. noder.SPLIT_CHAR .. field
+ local fullID = ('%s%s%q'):format(id, noder.SPLIT_CHAR, field)
m.searchRefsByID(status, uri, fullID, mode)
end
end