summaryrefslogtreecommitdiff
path: root/script-beta/core/completion.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-19 17:54:57 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-19 17:54:57 +0800
commit027d4fc5c0c2dd0457365852a4666c75c535fad3 (patch)
treeb7cf7f552ea13c214a86ef5dad8e56a4644bdc0b /script-beta/core/completion.lua
parent59779a81ea496761270393d354743c04f925682f (diff)
downloadlua-language-server-027d4fc5c0c2dd0457365852a4666c75c535fad3.zip
优化性能
Diffstat (limited to 'script-beta/core/completion.lua')
-rw-r--r--script-beta/core/completion.lua12
1 files changed, 7 insertions, 5 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index 11bc4117..95143173 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -411,8 +411,9 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul
}
end
-local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results, locals)
+local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results, locals, isGlobal)
local fields = {}
+ local count = 0
for _, src in ipairs(refs) do
if src.type == 'library' then
if src.name:sub(1, 1) == '@' then
@@ -426,7 +427,7 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res
if isSameSource(ast, src, start) then
-- 由于fastGlobal的优化,全局变量只会找出一个值,有可能找出自己
-- 所以遇到自己的时候重新找一下有没有其他定义
- if not guide.isGlobal(src) then
+ if not isGlobal then
goto CONTINUE
end
if #vm.getGlobals(key) <= 1 then
@@ -439,12 +440,13 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res
if locals and locals[name] then
goto CONTINUE
end
- if not matchKey(word, name) then
+ if not matchKey(word, name, count >= 100) then
goto CONTINUE
end
local last = fields[name]
if not last then
fields[name] = src
+ count = count + 1
goto CONTINUE
end
if src.type == 'tablefield'
@@ -470,8 +472,8 @@ end
local function checkGlobal(ast, word, start, offset, parent, oop, results)
local locals = guide.getVisibleLocals(ast.ast, offset)
- local refs = vm.getFields(parent, 'deep')
- checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results, locals)
+ local refs = vm.getGlobalSets '*'
+ checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results, locals, 'global')
end
local function checkTableField(ast, word, start, results)