diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-19 17:54:57 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-19 17:54:57 +0800 |
commit | 027d4fc5c0c2dd0457365852a4666c75c535fad3 (patch) | |
tree | b7cf7f552ea13c214a86ef5dad8e56a4644bdc0b /script-beta | |
parent | 59779a81ea496761270393d354743c04f925682f (diff) | |
download | lua-language-server-027d4fc5c0c2dd0457365852a4666c75c535fad3.zip |
优化性能
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/completion.lua | 12 | ||||
-rw-r--r-- | script-beta/core/matchkey.lua | 5 |
2 files changed, 11 insertions, 6 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) diff --git a/script-beta/core/matchkey.lua b/script-beta/core/matchkey.lua index b46250cb..45c86eff 100644 --- a/script-beta/core/matchkey.lua +++ b/script-beta/core/matchkey.lua @@ -1,4 +1,4 @@ -return function (me, other) +return function (me, other, fast) if me == other then return true end @@ -13,6 +13,9 @@ return function (me, other) if lMe == lOther:sub(1, #lMe) then return true end + if fast and me:sub(1, 1) ~= other:sub(1, 1) then + return false + end local chars = {} for i = 1, #lOther do local c = lOther:sub(i, i) |