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

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

    if not state.ast.docs then
        return
    end

    local mark
    for _, group in ipairs(state.ast.docs.groups) do
        for _, doc in ipairs(group) do
            if     doc.type == 'doc.class' then
                mark = {}
            elseif doc.type == 'doc.field' then
                if mark then
                    local name = doc.field[1]
                    local eventName = noder.getFieldEventName(doc)
                    if eventName then
                        name = name .. '|' .. eventName
                    end
                    if mark[name] then
                        callback {
                            start   = doc.field.start,
                            finish  = doc.field.finish,
                            message = lang.script('DIAG_DUPLICATE_DOC_FIELD', name),
                        }
                    end
                    mark[name] = true
                end
            end
        end
    end
end