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 | |
parent | 9c931e98e13ac7e781f1b7ddbfbb1d3daa1c33cf (diff) | |
download | lua-language-server-dbb99f3919751bea59e8ffffcda9bb968c74a8f5.zip |
优化自动完成的性能
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/completion.lua | 20 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 2 | ||||
-rw-r--r-- | script-beta/vm/getGlobals.lua | 25 |
3 files changed, 32 insertions, 15 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) diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 0c9ec43d..f52e9545 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -2083,7 +2083,7 @@ function m.searchSameFields(status, simple, mode) max = max + 1 status.cache.count = status.cache.count + 1 m.checkSameSimple(status, simple, data, mode, status.results, queue) - if max >= (m.searchMax or 10000) then + if max >= 10000 then logWarn('Queue too large!') break end diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua index d7470d47..ea2c5529 100644 --- a/script-beta/vm/getGlobals.lua +++ b/script-beta/vm/getGlobals.lua @@ -86,15 +86,24 @@ local function insertLibrary(results, name) end end -local function getGlobals(name) +local function getGlobals(name, fast) local results = {} + local mark = {} for uri in files.eachFile() do local cache = files.getCache(uri) cache.globals = cache.globals or getGlobalsOfFile(uri) if name == '*' then - for _, sources in util.sortPairs(cache.globals) do - for _, source in ipairs(sources) do - results[#results+1] = source + for destName, sources in util.sortPairs(cache.globals) do + if not fast or not mark[destName] then + if fast then + mark[destName] = true + end + for _, source in ipairs(sources) do + results[#results+1] = source + if fast then + break + end + end end end else @@ -109,13 +118,15 @@ local function getGlobals(name) return results end -function vm.getGlobals(name) +function vm.getGlobals(name, fast) local cache = vm.getCache('getGlobals')[name] if cache ~= nil then return cache end - cache = getGlobals(name) - vm.getCache('getGlobals')[name] = cache + cache = getGlobals(name, fast) + if not fast then + vm.getCache('getGlobals')[name] = cache + end return cache end |