summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/undefined-doc-param.lua
blob: 0bf371e500c0d713102af2869372fe1d72cd7a39 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
local files   = require 'files'
local guide   = require 'core.guide'
local lang    = require 'language'
local define  = require 'proto.define'
local vm      = require 'vm'

local function hasParamName(func, name)
    if not func.args then
        return false
    end
    for _, arg in ipairs(func.args) do
        if arg[1] == name then
            return true
        end
    end
    return false
end

return function (uri, callback)
    local state = files.getAst(uri)
    if not state then
        return
    end

    if not state.ast.docs then
        return
    end

    for _, doc in ipairs(state.ast.docs) do
        if doc.type ~= 'doc.param' then
            goto CONTINUE
        end
        local binds = doc.bindSources
        if not binds then
            goto CONTINUE
        end
        local param = doc.param
        local name = param[1]
        for _, source in ipairs(binds) do
            if source.type == 'function' then
                if not hasParamName(source, name) then
                    callback {
                        start   = param.start,
                        finish  = param.finish,
                        message = lang.script('DIAG_UNDEFINED_DOC_PARAM', name)
                    }
                end
            end
        end
        ::CONTINUE::
    end
end