diff options
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/completion.lua | 4 | ||||
-rw-r--r-- | script-beta/files.lua | 5 | ||||
-rw-r--r-- | script-beta/provider/provider.lua | 2 | ||||
-rw-r--r-- | script-beta/vm/getGlobals.lua | 132 |
4 files changed, 122 insertions, 21 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index e0bdfd64..8b866afd 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -442,8 +442,10 @@ local function checkFieldOfRefs(refs, ast, word, start, offset, parent, oop, res end local last = fields[name] if not last then + -- TODO if guide.isGlobal(src) then - fields[name] = vm.getGlobalSets(key)[1] or src + --fields[name] = vm.getGlobalSets(key)[1] or src + fields[name] = src else fields[name] = src end diff --git a/script-beta/files.lua b/script-beta/files.lua index 681245e3..4d34568d 100644 --- a/script-beta/files.lua +++ b/script-beta/files.lua @@ -108,11 +108,13 @@ function m.setText(uri, text) if platform.OS == 'Windows' then uri = uri:lower() end + local create if not m.fileMap[uri] then m.fileMap[uri] = { uri = originUri, version = 0, } + create = true end local file = m.fileMap[uri] if file.text == text then @@ -126,6 +128,9 @@ function m.setText(uri, text) file.version = file.version + 1 m.globalVersion = m.globalVersion + 1 await.close('files.version') + if create then + m.onWatch('create', originUri) + end m.onWatch('update', originUri) end diff --git a/script-beta/provider/provider.lua b/script-beta/provider/provider.lua index c56914e3..5dbb9e48 100644 --- a/script-beta/provider/provider.lua +++ b/script-beta/provider/provider.lua @@ -193,6 +193,8 @@ proto.on('textDocument/didChange', function (params) end) proto.on('textDocument/hover', function (params) + await.close 'hover' + await.setID 'hover' local core = require 'core.hover' local doc = params.textDocument local uri = doc.uri diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua index e5165130..ccc86f7b 100644 --- a/script-beta/vm/getGlobals.lua +++ b/script-beta/vm/getGlobals.lua @@ -6,7 +6,12 @@ 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 @@ -30,6 +35,38 @@ local function getGlobalsOfFile(uri) 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 insertLibrary(results, name) if name:sub(1, 2) == 's|' then local libname = name:sub(3) @@ -46,17 +83,16 @@ end local function getGlobals(name) local results = {} for uri in files.eachFile() do - local cache = files.getCache(uri) - cache.globals = cache.globals or getGlobalsOfFile(uri) + local globals = getGlobalsOfFile(uri) if name == '*' then - for _, sources in util.sortPairs(cache.globals) do + for _, sources in util.sortPairs(globals) do for _, source in ipairs(sources) do results[#results+1] = source end end else - if cache.globals[name] then - for _, source in ipairs(cache.globals[name]) do + if globals[name] then + for _, source in ipairs(globals[name]) do results[#results+1] = source end end @@ -66,7 +102,29 @@ local function getGlobals(name) return results end -local function getAnyGlobalsFast() +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 + insertLibrary(results, name) + return results +end + +local function fastGetAnyGlobals() local results = {} local mark = {} for uri in files.eachFile() do @@ -83,31 +141,65 @@ local function getAnyGlobalsFast() return results end +local function fastGetAnyGlobalSets() + local results = {} + local mark = {} + for uri in files.eachFile() do + local cache = files.getCache(uri) + cache.globalSets = cache.globalSets or getGlobalSetsOfFile(uri) + for destName, sources in util.sortPairs(cache.globalSets) do + if not mark[destName] then + mark[destName] = true + results[#results+1] = sources[1] + end + end + end + insertLibrary(results, '*') + return results +end + function vm.getGlobals(key) if key == '*' and config.config.intelliSense.fastGlobal then - return getAnyGlobalsFast() - end - local cache = vm.getCache('getGlobals')[key] - if cache ~= nil 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 - cache = getGlobals(key) - vm.getCache('getGlobals')[key] = cache - return cache 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 = {} - local refs = getGlobals(key) - for _, source in ipairs(refs) do - if vm.isSet(source) then - cache[#cache+1] = source - end - 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) |