summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/diagnostics/undefined-global.lua3
-rw-r--r--script-beta/vm/eachDef.lua16
-rw-r--r--script-beta/vm/eachField.lua42
-rw-r--r--script-beta/vm/eachRef.lua16
4 files changed, 53 insertions, 24 deletions
diff --git a/script-beta/core/diagnostics/undefined-global.lua b/script-beta/core/diagnostics/undefined-global.lua
index e287fefa..9ef80182 100644
--- a/script-beta/core/diagnostics/undefined-global.lua
+++ b/script-beta/core/diagnostics/undefined-global.lua
@@ -23,8 +23,7 @@ return function (uri, callback)
if library.global[key] then
return
end
- local sets = vm.getGlobalSets(guide.getKeyName(src))
- if #sets > 0 then
+ if #vm.getGlobalSets(guide.getKeyName(src)) > 0 then
return
end
local message = lang.script('DIAG_UNDEF_GLOBAL', key)
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
index e1d964ee..320f3e97 100644
--- a/script-beta/vm/eachDef.lua
+++ b/script-beta/vm/eachDef.lua
@@ -28,9 +28,19 @@ function m.eachDef(source, results)
end
function vm.getDefs(source)
- local cache = vm.getCache('eachDef')[source] or m.eachDef(source)
- vm.getCache('eachDef')[source] = cache
- return cache
+ if guide.isGlobal(source) then
+ local name = guide.getKeyName(source)
+ local cache = vm.getCache('eachDefOfGlobal')[name]
+ or vm.getCache('eachDef')[source]
+ or m.eachDef(source)
+ vm.getCache('eachDefOfGlobal')[name] = cache
+ return cache
+ else
+ local cache = vm.getCache('eachDef')[source]
+ or m.eachDef(source)
+ vm.getCache('eachDef')[source] = cache
+ return cache
+ end
end
function vm.eachDef(source, callback)
diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua
index 74f9b591..f4c2963a 100644
--- a/script-beta/vm/eachField.lua
+++ b/script-beta/vm/eachField.lua
@@ -19,6 +19,11 @@ local function eachFieldOfLibrary(results)
end
local function eachField(source)
+ local unlock = vm.lock('eachField', source)
+ if not unlock then
+ return
+ end
+
while source.type == 'paren' do
source = source.exp
end
@@ -31,25 +36,30 @@ local function eachField(source)
if library.object[source.type] then
eachFieldInLibrary(source, library.object[source.type], results)
end
+
+ unlock()
return results
end
-function vm.eachField(source, callback)
- local cache = vm.getCache('eachField')[source]
- if cache ~= nil then
- for i = 1, #cache do
- callback(cache[i])
- end
- return
+function vm.getFields(source)
+ if guide.isGlobal(source) then
+ local name = guide.getKeyName(source)
+ local cache = vm.getCache('eachFieldOfGlobal')[name]
+ or vm.getCache('eachField')[source]
+ or eachField(source)
+ vm.getCache('eachFieldOfGlobal')[name] = cache
+ return cache
+ else
+ local cache = vm.getCache('eachField')[source]
+ or eachField(source)
+ vm.getCache('eachField')[source] = cache
+ return cache
end
- local unlock = vm.lock('eachField', source)
- if not unlock then
- return
- end
- cache = eachField(source)
- vm.getCache('eachField')[source] = cache
- unlock()
- for i = 1, #cache do
- callback(cache[i])
+end
+
+function vm.eachField(source, callback)
+ local results = vm.getFields(source)
+ for i = 1, #results do
+ callback(results[i])
end
end
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index 35321d24..cfdc1d19 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -25,9 +25,19 @@ local function getRefs(source, results)
end
function vm.getRefs(source)
- local cache = vm.getCache('eachRef')[source] or getRefs(source)
- vm.getCache('eachRef')[source] = cache
- return cache
+ if guide.isGlobal(source) then
+ local name = guide.getKeyName(source)
+ local cache = vm.getCache('eachRefOfGlobal')[name]
+ or vm.getCache('eachRef')[source]
+ or getRefs(source)
+ vm.getCache('eachRefOfGlobal')[name] = cache
+ return cache
+ else
+ local cache = vm.getCache('eachRef')[source]
+ or getRefs(source)
+ vm.getCache('eachRef')[source] = cache
+ return cache
+ end
end
function vm.eachRef(source, callback)