summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/hover/label.lua35
-rw-r--r--script-beta/core/hover/return.lua19
-rw-r--r--script-beta/core/hover/table.lua2
-rw-r--r--script-beta/parser/guide.lua5
-rw-r--r--script-beta/vm/getInfer.lua22
5 files changed, 42 insertions, 41 deletions
diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua
index 12c175cd..57b2ee8e 100644
--- a/script-beta/core/hover/label.lua
+++ b/script-beta/core/hover/label.lua
@@ -19,36 +19,15 @@ end
local function asValue(source, title)
local name = buildName(source)
local class = 'any'
- local type = 'any'
- local literal = ''
- local cont
local infers = vm.getInfers(source)
- if infers then
- for _, value in ipairs(infers) do
- local src = value.source
- local tp = value.type
- class = guide.mergeTypes {class, vm.getClass(src)}
- type = guide.mergeTypes {type, tp}
- local sl = guide.getLiteral(src)
- if sl then
- literal = guide.mergeTypes {literal, util.viewLiteral(sl)}
- end
- if tp == 'table' then
- cont = buildTable(src)
- end
- end
+ local type = vm.getType(source)
+ local literal = vm.getLiteral(source)
+ local cont
+ if vm.hasType(source, 'table') then
+ cont = buildTable(source)
end
- vm.eachDef(source, function (src)
- class = guide.mergeTypes {class, vm.getClass(src)}
- type = guide.mergeTypes {type, vm.getType(src)}
- local sl = guide.getLiteral(src)
- if sl then
- literal = guide.mergeTypes {literal, util.viewLiteral(sl)}
- end
- if type == 'table' then
- cont = buildTable(src)
- end
- end)
+ --vm.eachDef(source, function (src)
+ --end)
local pack = {}
pack[#pack+1] = title
pack[#pack+1] = name .. ':'
diff --git a/script-beta/core/hover/return.lua b/script-beta/core/hover/return.lua
index f67a961f..be8b0e1e 100644
--- a/script-beta/core/hover/return.lua
+++ b/script-beta/core/hover/return.lua
@@ -1,6 +1,17 @@
local guide = require 'parser.guide'
local vm = require 'vm'
+local function mergeTypes(returns)
+ if type(returns) == 'string' then
+ return returns
+ end
+ local types = {}
+ for _, rtn in ipairs(returns) do
+ types[#types+1] = rtn.type
+ end
+ return guide.mergeTypes(types)
+end
+
local function asLibrary(source)
if not source.returns then
return nil
@@ -21,9 +32,9 @@ local function asLibrary(source)
local lines = {}
for i = 1, #returns do
if i == 1 then
- lines[i] = (' -> %s'):format(guide.viewInfer(returns[i]))
+ lines[i] = (' -> %s'):format(mergeTypes(returns[i]))
else
- lines[i] = ('% 3d. %s'):format(i, guide.viewInfer(returns[i]))
+ lines[i] = ('% 3d. %s'):format(i, mergeTypes(returns[i]))
end
end
return table.concat(lines, '\n')
@@ -47,9 +58,9 @@ local function asFunction(source)
local lines = {}
for i = 1, #returns do
if i == 1 then
- lines[i] = (' -> %s'):format(guide.viewInfer(returns[i]))
+ lines[i] = (' -> %s'):format(mergeTypes(returns[i]))
else
- lines[i] = ('% 3d. %s'):format(i, guide.viewInfer(returns[i]))
+ lines[i] = ('% 3d. %s'):format(i, mergeTypes(returns[i]))
end
end
return table.concat(lines, '\n')
diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua
index b9ae4940..5b086cd6 100644
--- a/script-beta/core/hover/table.lua
+++ b/script-beta/core/hover/table.lua
@@ -38,7 +38,7 @@ local function getField(src)
end
local tp = vm.getType(src)
local class = vm.getClass(src)
- local literal = guide.getLiteral(src)
+ local literal = vm.getLiteral(src)
local key = getKey(src)
if type(literal) == 'string' and #literal >= 50 then
literal = literal:sub(1, 47) .. '...'
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 4a627217..824c7c6d 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -1899,13 +1899,10 @@ function m.mergeTypes(infers)
return tableConcat(types, '|')
end
-function m.viewInfer(infers)
+function m.viewInferType(infers)
if not infers then
return 'any'
end
- if type(infers) ~= 'table' then
- return infers or 'any'
- end
local mark = {}
local types = {}
for i = 1, #infers do
diff --git a/script-beta/vm/getInfer.lua b/script-beta/vm/getInfer.lua
index 0352e9d2..c27fc6d2 100644
--- a/script-beta/vm/getInfer.lua
+++ b/script-beta/vm/getInfer.lua
@@ -18,7 +18,22 @@ end
function vm.getType(source)
local infers = vm.getInfers(source)
- return guide.viewInfer(infers)
+ return guide.viewInferType(infers)
+end
+
+function vm.getLiteral(source)
+ local infers = vm.getInfers(source)
+ local literals = {}
+ local mark = {}
+ for _, infer in ipairs(infers) do
+ local value = infer.value
+ if value and not mark[value] then
+ mark[value] = true
+ literals[#literals+1] = util.viewLiteral(value)
+ end
+ end
+ table.sort(literals)
+ return table.concat(literals, '|')
end
--- 获取对象的值
@@ -29,9 +44,8 @@ function vm.getInfers(source)
end
local clock = os.clock()
local infers = guide.requestInfer(source, vm.interface)
- local passed = os.clock() - clock
- if passed > 0.1 then
- log.warn(('Request infer takes [%.3f]sec! %s'):format(passed, util.dump(source, { deep = 1 })))
+ if os.clock() - clock > 0.1 then
+ log.warn(('Request infer takes [%.3f]sec! %s %s'):format(os.clock() - clock, guide.getRoot(source).uri, util.dump(source, { deep = 1 })))
end
return infers
end