diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-05 16:49:00 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-05 16:49:00 +0800 |
commit | dbb99f3919751bea59e8ffffcda9bb968c74a8f5 (patch) | |
tree | 88835e93c48071f3f75080e4ec8d880ae3ab13e6 /script-beta/core/completion.lua | |
parent | 9c931e98e13ac7e781f1b7ddbfbb1d3daa1c33cf (diff) | |
download | lua-language-server-dbb99f3919751bea59e8ffffcda9bb968c74a8f5.zip |
优化自动完成的性能
Diffstat (limited to 'script-beta/core/completion.lua')
-rw-r--r-- | script-beta/core/completion.lua | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 2635f2bf..4f4f99c7 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -406,9 +406,9 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul } end -local function checkField(ast, word, start, offset, parent, oop, results) +local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results) local fields = {} - for _, src in ipairs(vm.getFields(parent, 'deep')) do + for _, src in ipairs(refs) do if src.type == 'library' then if src.name:sub(1, 1) == '@' then goto CONTINUE @@ -445,6 +445,16 @@ local function checkField(ast, word, start, offset, parent, oop, results) end end +local function checkField(ast, word, start, offset, parent, oop, results) + local refs = vm.getFields(parent, 'deep') + checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results) +end + +local function checkGlobal(ast, word, start, offset, parent, oop, results) + local refs = vm.getGlobals('*', 'fast') + checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, results) +end + local function checkTableField(ast, word, start, results) local source = guide.eachSourceContain(ast.ast, start, function (source) if source.start == start @@ -835,7 +845,7 @@ local function tryWord(ast, text, offset, results) checkLocal(ast, word, start, results) checkTableField(ast, word, start, results) local env = guide.getENV(ast.ast, start) - checkField(ast, word, start, offset, env, false, results) + checkGlobal(ast, word, start, offset, env, false, results) end end end @@ -1205,10 +1215,6 @@ local function completion(uri, offset) local results = {} clearStack() vm.setSearchLevel(3) - guide.searchMax = 1000 - local _ <close> = util.defer(function () - guide.searchMax = nil - end) if ast then if getComment(ast, offset) then tryLuaDoc(ast, text, offset, results) |