summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/unknown-operator.lua
blob: 29a86eaa9e9baa0125d241b65597ffca3ade4512 (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
local files   = require 'files'
local guide   = require 'parser.guide'
local lang    = require 'language'
local vm      = require 'vm'
local await   = require 'await'
local util    = require 'utility'

---@async
return function (uri, callback)
    local state = files.getState(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.operator' then
            local op = doc.op
            if op then
                if  not util.arrayHas(vm.UNARY_OP, op[1])
                and not util.arrayHas(vm.BINARY_OP, op[1]) then
                    callback {
                        start   = doc.op.start,
                        finish  = doc.op.finish,
                        message = lang.script('DIAG_UNKNOWN_OPERATOR', op[1])
                    }
                end
            end
        end
    end
end