summaryrefslogtreecommitdiff
path: root/script-beta/core/find-source.lua
blob: 2e42ca8233a5e4d560c0e4b9a4876bb1a8e97af7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
local guide     = require 'parser.guide'

return function (ast, offset, accept)
    local len = 999
    local result
    guide.eachSourceContain(ast.ast, offset, function (source)
        if source.finish - source.start < len and accept[source.type] then
            result = source
            len = source.finish - source.start
        end
    end)
    return result
end