summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/duplicate-doc-param.lua
blob: 676a6fb4095a15cbca8acdd7d69b33de33887432 (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
local files   = require 'files'
local lang    = require 'language'

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 name = doc.param[1]
        local bindGroup = doc.bindGroup
        if not bindGroup then
            goto CONTINUE
        end
        for _, other in ipairs(bindGroup) do
            if  other ~= doc
            and other.type == 'doc.param'
            and other.param[1] == name then
                callback {
                    start   = doc.param.start,
                    finish  = doc.param.finish,
                    message = lang.script('DIAG_DUPLICATE_DOC_PARAM', name)
                }
                goto CONTINUE
            end
        end
        ::CONTINUE::
    end
end