summaryrefslogtreecommitdiff
path: root/script-beta/vm/getInfer.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-08-17 17:55:12 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-08-17 17:55:12 +0800
commit1ad4e66d410ac0bbca7ebdd4ab1ec5f7dc47af1c (patch)
tree17a98ded980d958c6e7e31979bd28e106f158812 /script-beta/vm/getInfer.lua
parentfaab8b0541b7eb3a955dfc231f91364f78d0fcb6 (diff)
downloadlua-language-server-1ad4e66d410ac0bbca7ebdd4ab1ec5f7dc47af1c.zip
整理 hover 的代码
Diffstat (limited to 'script-beta/vm/getInfer.lua')
-rw-r--r--script-beta/vm/getInfer.lua22
1 files changed, 18 insertions, 4 deletions
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