diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-29 21:43:43 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-29 21:43:43 +0800 |
commit | 4e9f8c16ed240d949cf06aa3bdd9736bdff7e737 (patch) | |
tree | 97bb6c2b15c2982f12315c9a591ffb5045660f73 /script-beta/vm/getLibrary.lua | |
parent | 1aff4a30c4c2cebba241fbff442eacb6e98ac328 (diff) | |
download | lua-language-server-4e9f8c16ed240d949cf06aa3bdd9736bdff7e737.zip |
构建 table 先写个 TODO
Diffstat (limited to 'script-beta/vm/getLibrary.lua')
-rw-r--r-- | script-beta/vm/getLibrary.lua | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua index 3a3c1baf..f5c643e9 100644 --- a/script-beta/vm/getLibrary.lua +++ b/script-beta/vm/getLibrary.lua @@ -2,7 +2,7 @@ local vm = require 'vm.vm' local guide = require 'parser.guide' local library = require 'library' -local function getLibrary(source, simple) +local function getLibrary(source, deep) if source.type == 'library' then return source end @@ -18,29 +18,42 @@ local function getLibrary(source, simple) end end end - local defs = vm.getDefs(source, simple) + + local unlock = vm.lock('getLibrary', source) + if not unlock then + return + end + + local defs = vm.getDefs(source, deep) + unlock() + for _, def in ipairs(defs) do if def.type == 'library' then return def end end + return nil end -function vm.getLibrary(source, simple) - if simple then - return getLibrary(source, simple) or false +function vm.getLibrary(source, deep) + if ALL_DEEP then + deep = 'deep' end - local cache = vm.getCache('getLibrary')[source] - if cache ~= nil then + if guide.isGlobal(source) then + local name = guide.getKeyName(source) + local cache = vm.getCache('getLibraryOfGlobal')[name] + or vm.getCache('getLibrary')[source] + or getLibrary(source, 'deep') + vm.getCache('getLibraryOfGlobal')[name] = cache + vm.getCache('getLibrary')[source] = cache + return cache + else + local cache = vm.getCache('getLibrary')[source] + or getLibrary(source, deep) + if deep then + vm.getCache('getLibrary')[source] = cache + end return cache end - local unlock = vm.lock('getLibrary', source) - if not unlock then - return - end - cache = getLibrary(source) or false - vm.getCache('getLibrary')[source] = cache - unlock() - return cache end |