summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/completion.lua20
-rw-r--r--script-beta/parser/guide.lua2
-rw-r--r--script-beta/vm/getGlobals.lua25
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