summaryrefslogtreecommitdiff
path: root/script-beta/core
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta/core')
-rw-r--r--script-beta/core/hover/class.lua27
-rw-r--r--script-beta/core/hover/label.lua51
-rw-r--r--script-beta/core/hover/name.lua33
3 files changed, 53 insertions, 58 deletions
diff --git a/script-beta/core/hover/class.lua b/script-beta/core/hover/class.lua
new file mode 100644
index 00000000..6d28ee8a
--- /dev/null
+++ b/script-beta/core/hover/class.lua
@@ -0,0 +1,27 @@
+local vm = require 'vm'
+
+local function getClass(source, deep)
+ if deep > 3 then
+ return nil
+ end
+ local class = 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
+ return info.value[1]
+ end
+ end
+ end)
+ if class then
+ return class
+ end
+ return vm.eachMeta(source, function (meta)
+ local cl = getClass(meta, deep + 1)
+ if cl then
+ return cl
+ end
+ end)
+end
+
+return function (source)
+ return getClass(source, 1)
+end
diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua
index 774ca231..765b01c2 100644
--- a/script-beta/core/hover/label.lua
+++ b/script-beta/core/hover/label.lua
@@ -2,6 +2,7 @@ local buildName = require 'core.hover.name'
local buildArg = require 'core.hover.arg'
local buildReturn = require 'core.hover.return'
local buildTable = require 'core.hover.table'
+local getClass = require 'core.hover.class'
local vm = require 'vm'
local util = require 'utility'
@@ -15,32 +16,36 @@ local function asFunction(source)
return table.concat(lines, '\n')
end
-local function asLocal(source)
+local function asValue(source, title)
local name = buildName(source)
+ local class = getClass(source)
local type = vm.getType(source)
local literal = vm.getLiteral(source)
+ local cont
if type == 'table' then
- type = buildTable(source)
+ cont = buildTable(source)
+ type = nil
end
- if literal == nil then
- return ('local %s: %s'):format(name, type)
- else
- return ('local %s: %s = %s'):format(name, type, util.viewLiteral(literal))
+ local pack = {}
+ pack[#pack+1] = title
+ pack[#pack+1] = name .. ':'
+ pack[#pack+1] = class or type
+ if literal then
+ pack[#pack+1] = '='
+ pack[#pack+1] = util.viewLiteral(literal)
+ end
+ if cont then
+ pack[#pack+1] = cont
end
+ return table.concat(pack, ' ')
+end
+
+local function asLocal(source)
+ return asValue(source, 'local')
end
local function asGlobal(source)
- local name = buildName(source)
- local type = vm.getType(source)
- local literal = vm.getLiteral(source)
- if type == 'table' then
- type = buildTable(source)
- end
- if literal == nil then
- return ('global %s: %s'):format(name, type)
- else
- return ('global %s: %s = %s'):format(name, type, util.viewLiteral(literal))
- end
+ return asValue(source, 'global')
end
local function isGlobalField(source)
@@ -74,17 +79,7 @@ local function asField(source)
if isGlobalField(source) then
return asGlobal(source)
end
- local name = buildName(source)
- local type = vm.getType(source)
- local literal = vm.getLiteral(source)
- if type == 'table' then
- type = buildTable(source)
- end
- if literal == nil then
- return ('field %s: %s'):format(name, type)
- else
- return ('field %s: %s = %s'):format(name, type, util.viewLiteral(literal))
- end
+ return asValue(source, 'field')
end
return function (source)
diff --git a/script-beta/core/hover/name.lua b/script-beta/core/hover/name.lua
index 7fe5b194..0d5f65ad 100644
--- a/script-beta/core/hover/name.lua
+++ b/script-beta/core/hover/name.lua
@@ -1,35 +1,8 @@
-local guide = require 'parser.guide'
-local vm = require 'vm'
-
-local function getClass(source, deep)
- if deep and deep > 3 then
- return nil
- end
- local class = 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
- return info.value[1]
- end
- end
- end)
- if class then
- return class
- end
- return vm.eachMeta(source, function (meta)
- local cl = getClass(meta, deep and (deep + 1) or 1)
- if cl then
- return cl
- end
- end)
-end
+local guide = require 'parser.guide'
+local getClass = require 'core.hover.class'
local function asLocal(source)
- local class = getClass(source)
- if class then
- return ('%s: %s'):format(guide.getName(source), class)
- else
- return guide.getName(source)
- end
+ return guide.getName(source)
end
local function asMethod(source)