summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
Diffstat (limited to 'script/core')
-rw-r--r--script/core/diagnostics/undefined-field.lua42
-rw-r--r--script/core/diagnostics/undefined-global.lua2
2 files changed, 43 insertions, 1 deletions
diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua
new file mode 100644
index 00000000..e5e55f14
--- /dev/null
+++ b/script/core/diagnostics/undefined-field.lua
@@ -0,0 +1,42 @@
+local files = require 'files'
+local vm = require 'vm'
+local lang = require 'language'
+local config = require 'config'
+local guide = require 'parser.guide'
+local define = require 'proto.define'
+
+return function (uri, callback)
+ local ast = files.getAst(uri)
+ if not ast then
+ return
+ end
+
+ local function checkUndefinedField(src)
+ local fieldName = guide.getKeyName(src)
+ local refs = vm.getFields(src.node, 0)
+
+ local fields = {}
+ for _, ref in ipairs(refs) do
+ if ref.type == 'getfield' or ref.type == 'getmethod' then
+ goto CONTINUE
+ end
+ local name = vm.getKeyName(ref)
+ if not name or vm.getKeyType(ref) ~= 'string' then
+ goto CONTINUE
+ end
+ fields[name] = true
+ ::CONTINUE::
+ end
+
+ if not fields[fieldName] then
+ local message = lang.script('DIAG_UNDEF_FIELD', fieldName)
+ callback {
+ start = src.start,
+ finish = src.finish,
+ message = message,
+ }
+ end
+ end
+ guide.eachSourceType(ast.ast, 'getfield', checkUndefinedField);
+ guide.eachSourceType(ast.ast, 'getmethod', checkUndefinedField);
+end
diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua
index eb225169..75a43d0f 100644
--- a/script/core/diagnostics/undefined-global.lua
+++ b/script/core/diagnostics/undefined-global.lua
@@ -20,7 +20,7 @@ return function (uri, callback)
if config.config.diagnostics.globals[key] then
return
end
- if #vm.getGlobalSets(guide.getKeyName(src)) == 0 then
+ if #vm.getGlobalSets(key) == 0 then
local message = lang.script('DIAG_UNDEF_GLOBAL', key)
callback {
start = src.start,