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/vm/getGlobals.lua | |
parent | 9c931e98e13ac7e781f1b7ddbfbb1d3daa1c33cf (diff) | |
download | lua-language-server-dbb99f3919751bea59e8ffffcda9bb968c74a8f5.zip |
优化自动完成的性能
Diffstat (limited to 'script-beta/vm/getGlobals.lua')
-rw-r--r-- | script-beta/vm/getGlobals.lua | 25 |
1 files changed, 18 insertions, 7 deletions
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 |