diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-20 21:57:09 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-20 21:57:09 +0800 |
commit | 4ca61ec457822dd14966afa0752340ae8ce180a1 (patch) | |
tree | ae8adb1ad82c717868e551e699fd3cf3bb290089 /script-beta/vm/getGlobals.lua | |
parent | c63b2e404d8d2bb984afe3678a5ba2b2836380cc (diff) | |
download | lua-language-server-4ca61ec457822dd14966afa0752340ae8ce180a1.zip |
no longer beta
Diffstat (limited to 'script-beta/vm/getGlobals.lua')
-rw-r--r-- | script-beta/vm/getGlobals.lua | 192 |
1 files changed, 0 insertions, 192 deletions
diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua deleted file mode 100644 index 83d6a5e6..00000000 --- a/script-beta/vm/getGlobals.lua +++ /dev/null @@ -1,192 +0,0 @@ -local guide = require 'parser.guide' -local vm = require 'vm.vm' -local files = require 'files' -local util = require 'utility' -local config = require 'config' - -local function getGlobalsOfFile(uri) - local cache = files.getCache(uri) - if cache.globals then - return cache.globals - end - local globals = {} - cache.globals = globals - local ast = files.getAst(uri) - if not ast then - return globals - end - local results = guide.findGlobals(ast.ast) - local mark = {} - for _, res in ipairs(results) do - if mark[res] then - goto CONTINUE - end - mark[res] = true - local name = guide.getSimpleName(res) - if name then - if not globals[name] then - globals[name] = {} - end - globals[name][#globals[name]+1] = res - end - ::CONTINUE:: - end - return globals -end - -local function getGlobalSetsOfFile(uri) - local cache = files.getCache(uri) - if cache.globalSets then - return cache.globalSets - end - local globals = {} - cache.globalSets = globals - local ast = files.getAst(uri) - if not ast then - return globals - end - local results = guide.findGlobals(ast.ast) - local mark = {} - for _, res in ipairs(results) do - if mark[res] then - goto CONTINUE - end - mark[res] = true - if vm.isSet(res) then - local name = guide.getSimpleName(res) - if name then - if not globals[name] then - globals[name] = {} - end - globals[name][#globals[name]+1] = res - end - end - ::CONTINUE:: - end - return globals -end - -local function getGlobals(name) - local results = {} - for uri in files.eachFile() do - local globals = getGlobalsOfFile(uri) - if name == '*' then - for _, sources in util.sortPairs(globals) do - for _, source in ipairs(sources) do - results[#results+1] = source - end - end - else - if globals[name] then - for _, source in ipairs(globals[name]) do - results[#results+1] = source - end - end - end - end - return results -end - -local function getGlobalSets(name) - local results = {} - for uri in files.eachFile() do - local globals = getGlobalSetsOfFile(uri) - if name == '*' then - for _, sources in util.sortPairs(globals) do - for _, source in ipairs(sources) do - results[#results+1] = source - end - end - else - if globals[name] then - for _, source in ipairs(globals[name]) do - results[#results+1] = source - end - end - end - end - return results -end - -local function fastGetAnyGlobals() - local results = {} - local mark = {} - for uri in files.eachFile() do - --local globalSets = getGlobalsOfFile(uri) - --for destName, sources in util.sortPairs(globalSets) do - -- if not mark[destName] then - -- mark[destName] = true - -- results[#results+1] = sources[1] - -- end - --end - local globals = getGlobalsOfFile(uri) - for destName, sources in util.sortPairs(globals) do - if not mark[destName] then - mark[destName] = true - results[#results+1] = sources[1] - end - end - end - return results -end - -local function fastGetAnyGlobalSets() - local results = {} - local mark = {} - for uri in files.eachFile() do - local globals = getGlobalSetsOfFile(uri) - for destName, sources in util.sortPairs(globals) do - if not mark[destName] then - mark[destName] = true - results[#results+1] = sources[1] - end - end - end - return results -end - -function vm.getGlobals(key) - if key == '*' and config.config.intelliSense.fastGlobal then - local cache = vm.getCache('fastGetAnyGlobals')[key] - if cache ~= nil then - return cache - end - cache = fastGetAnyGlobals() - vm.getCache('fastGetAnyGlobals')[key] = cache - return cache - else - local cache = vm.getCache('getGlobals')[key] - if cache ~= nil then - return cache - end - cache = getGlobals(key) - vm.getCache('getGlobals')[key] = cache - return cache - end -end - -function vm.getGlobalSets(key) - if key == '*' and config.config.intelliSense.fastGlobal then - local cache = vm.getCache('fastGetAnyGlobalSets')[key] - if cache ~= nil then - return cache - end - cache = fastGetAnyGlobalSets() - vm.getCache('fastGetAnyGlobalSets')[key] = cache - return cache - end - local cache = vm.getCache('getGlobalSets')[key] - if cache ~= nil then - return cache - end - cache = getGlobalSets(key) - vm.getCache('getGlobalSets')[key] = cache - return cache -end - -files.watch(function (ev, uri) - if ev == 'update' then - getGlobalsOfFile(uri) - getGlobalSetsOfFile(uri) - end -end) |