summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/undefined-env-child.lua
blob: a32ad3062d680e31bc02fb751da7b5d8cdbea1d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local files  = require 'files'
local searcher  = require 'core.searcher'
local vm     = require 'vm'
local lang   = require 'language'

return function (uri, callback)
    local ast = files.getAst(uri)
    if not ast then
        return
    end
    searcher.eachSourceType(ast.ast, 'getglobal', function (source)
        -- 单独验证自己是否在重载过的 _ENV 中有定义
        if source.node.tag == '_ENV' then
            return
        end
        local defs = searcher.requestDefinition(source)
        if #defs > 0 then
            return
        end
        local key = source[1]
        callback {
            start   = source.start,
            finish  = source.finish,
            message = lang.script('DIAG_UNDEF_ENV_CHILD', key),
        }
    end)
end