summaryrefslogtreecommitdiff
path: root/script-beta/core/hover/table.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta/core/hover/table.lua')
-rw-r--r--script-beta/core/hover/table.lua48
1 files changed, 32 insertions, 16 deletions
diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua
index 9ed86692..9292d183 100644
--- a/script-beta/core/hover/table.lua
+++ b/script-beta/core/hover/table.lua
@@ -1,35 +1,51 @@
-local vm = require 'vm'
+local vm = require 'vm'
+local util = require 'utility'
+local getClass = require 'core.hover.class'
-local function checkClass(source)
+local function getKey(info)
+ local ktype = info.key:sub(1, 2)
+ if ktype == 's|' then
+ return info.key:sub(3)
+ end
+ return ('[%s]'):format(info.key:sub(3))
+end
+
+local function getField(info)
+ local type = vm.getType(info.source)
+ local class = getClass(info.source)
+ local literal = vm.getLiteral(info.source)
+ local key = getKey(info)
+ local label
+ if literal then
+ label = ('%s: %s = %s'):format(key, class or type, util.viewLiteral(literal))
+ else
+ label = ('%s: %s'):format(key, class or type)
+ end
+ return label, key
end
return function (source)
local fields = {}
- local class
+ local keys = {}
vm.eachField(source, function (info)
- if info.key == 's|type' or info.key == 's|__name' or info.key == 's|name' then
- if info.value and info.value.type == 'string' then
- class = info.value[1]
- end
- end
- local type = vm.getType(info.source)
- fields[#fields+1] = ('%s'):format(type)
+ local field, key = getField(info)
+ fields[#fields+1] = field
+ keys[field] = key
end)
local fieldsBuf
if #fields == 0 then
fieldsBuf = '{}'
else
+ table.sort(fields, function (a, b)
+ return keys[a] < keys[b]
+ end)
local lines = {}
lines[#lines+1] = '{'
for _, field in ipairs(fields) do
- lines[#lines+1] = ' ' .. field
+ lines[#lines+1] = ' ' .. field .. ','
end
lines[#lines+1] = '}'
fieldsBuf = table.concat(lines, '\n')
end
- if class then
- return ('%s %s'):format(class, fieldsBuf)
- else
- return fieldsBuf
- end
+ return fieldsBuf
end