summaryrefslogtreecommitdiff
path: root/server-beta/src/core/diagnostics/unused-function.lua
blob: 801239489cdd7120c61dba5f289704eb196b23ba (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
local files    = require 'files'
local guide    = require 'parser.guide'
local searcher = require 'searcher'
local define = require 'proto.define'
local lang   = require 'language'

return function (uri, callback)
    local ast = files.getAst(uri)
    if not ast then
        return
    end
    guide.eachSourceType(ast.ast, 'function', function (source)
        local hasGet
        searcher.eachRef(source, function (info)
            if info.mode == 'get' then
                hasGet = true
            end
        end)
        if not hasGet then
            callback {
                start   = source.start,
                finish  = source.finish,
                tags    = { define.DiagnosticTag.Unnecessary },
                message = lang.script.DIAG_UNUSED_FUNCTION,
            }
        end
    end)
end