summaryrefslogtreecommitdiff
path: root/script-beta/core/hover
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-10-30 15:32:11 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-10-30 15:32:11 +0800
commitaca5d65499c3af0fe0d73cd7ce69e7de2248b1e8 (patch)
tree19c2e6d7cb9e699aaa3e1438c4e12c44d430dbe3 /script-beta/core/hover
parent705e882703b837e44b1c6689d1fd90c7778f2c0f (diff)
downloadlua-language-server-aca5d65499c3af0fe0d73cd7ce69e7de2248b1e8.zip
优化 table 的hover性能
Diffstat (limited to 'script-beta/core/hover')
-rw-r--r--script-beta/core/hover/label.lua8
-rw-r--r--script-beta/core/hover/name.lua4
-rw-r--r--script-beta/core/hover/table.lua75
3 files changed, 50 insertions, 37 deletions
diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua
index 2c0bdcd1..be73eec2 100644
--- a/script-beta/core/hover/label.lua
+++ b/script-beta/core/hover/label.lua
@@ -31,10 +31,10 @@ end
local function asValue(source, title)
local name = buildName(source)
- local infers = vm.getInfers(source)
- local type = vm.getInferType(source)
- local class = vm.getClass(source)
- local literal = vm.getInferLiteral(source)
+ local infers = vm.getInfers(source, 'deep')
+ local type = vm.getInferType(source, 'deep')
+ local class = vm.getClass(source, 'deep')
+ local literal = vm.getInferLiteral(source, 'deep')
local cont
if vm.hasInferType(source, 'table', 'deep') then
cont = buildTable(source)
diff --git a/script-beta/core/hover/name.lua b/script-beta/core/hover/name.lua
index c30cf554..4d5b015c 100644
--- a/script-beta/core/hover/name.lua
+++ b/script-beta/core/hover/name.lua
@@ -17,14 +17,14 @@ local function asLocal(source)
end
local function asMethod(source)
- local class = vm.getClass(source.node)
+ local class = vm.getClass(source.node, 'deep')
local node = class or guide.getName(source.node) or '?'
local method = guide.getName(source)
return ('%s:%s'):format(node, method)
end
local function asField(source)
- local class = vm.getClass(source.node)
+ local class = vm.getClass(source.node, 'deep')
local node = class or guide.getName(source.node) or '?'
local method = guide.getName(source)
return ('%s.%s'):format(node, method)
diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua
index fbe765b2..87c3b3e1 100644
--- a/script-beta/core/hover/table.lua
+++ b/script-beta/core/hover/table.lua
@@ -36,20 +36,7 @@ local function getKey(src)
return ('[%s]'):format(key)
end
-local function getField(src, marker)
- if src.type == 'table'
- or src.type == 'function' then
- return nil
- end
- if src.parent then
- if src.parent.type == 'tableindex'
- or src.parent.type == 'setindex'
- or src.parent.type == 'getindex' then
- if src.parent.index == src then
- src = src.parent
- end
- end
- end
+local function getFieldFast(src)
local value = guide.getObjectValue(src) or src
if not value then
return 'any'
@@ -81,16 +68,48 @@ local function getField(src, marker)
end
return value.type, util.viewLiteral(literal)
end
- marker()
- local tp = vm.getInferType(value)
- local class = vm.getClass(value)
- local literal = vm.getInferLiteral(value)
+end
+
+local function getFieldFull(src)
+ local tp = vm.getInferType(src)
+ local class = vm.getClass(src)
+ local literal = vm.getInferLiteral(src)
if type(literal) == 'string' and #literal >= 50 then
literal = literal:sub(1, 47) .. '...'
end
return class or tp, literal
end
+local function getField(src, timeUp, mark, key)
+ if src.type == 'table'
+ or src.type == 'function' then
+ return nil
+ end
+ if src.parent then
+ if src.parent.type == 'tableindex'
+ or src.parent.type == 'setindex'
+ or src.parent.type == 'getindex' then
+ if src.parent.index == src then
+ src = src.parent
+ end
+ end
+ end
+ local tp, literal
+ tp, literal = getFieldFast(src)
+ if tp then
+ return tp, literal
+ end
+ if timeUp or mark[key] then
+ return nil
+ end
+ mark[key] = true
+ tp, literal = getFieldFull(src)
+ if tp then
+ return tp, literal
+ end
+ return nil
+end
+
local function buildAsHash(classes, literals)
local keys = {}
for k in pairs(classes) do
@@ -213,27 +232,21 @@ return function (source)
if not key then
goto CONTINUE
end
- if mark[key] then
- goto CONTINUE
- end
if not classes[key] then
classes[key] = {}
end
if not literals[key] then
literals[key] = {}
end
- if TEST or os.clock() - clock <= 5 then
- local class, literal = getField(src, function ()
- mark[key] = true
- end)
- if literal == 'nil' then
- literal = nil
- end
- classes[key][#classes[key]+1] = class
- literals[key][#literals[key]+1] = literal
- else
+ if not TEST and os.clock() - clock > 5 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
::CONTINUE::
end