summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/await-in-sync.lua
blob: 5fb6467de97074eb18a11817d16878130a009fec (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
local files = require 'files'
local guide = require 'parser.guide'
local vm    = require 'vm'
local lang  = require 'language'

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

    guide.eachSourceType(state.ast, 'call', function (source)
        local currentFunc = guide.getParentFunction(source)
        if currentFunc and vm.isAsync(currentFunc) then
            return
        end
        if not vm.isAsync(source.node, true) then
            return
        end
        callback {
            start   = source.node.start,
            finish  = source.node.finish,
            message = lang.script('DIAG_AWAIT_IN_SYNC'),
        }
    end)
end