diff options
Diffstat (limited to 'script/core/find-source.lua')
-rw-r--r-- | script/core/find-source.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/script/core/find-source.lua b/script/core/find-source.lua new file mode 100644 index 00000000..32de102c --- /dev/null +++ b/script/core/find-source.lua @@ -0,0 +1,14 @@ +local guide = require 'parser.guide' + +return function (ast, offset, accept) + local len = math.huge + local result + guide.eachSourceContain(ast.ast, offset, function (source) + local start, finish = guide.getStartFinish(source) + if finish - start < len and accept[source.type] then + result = source + len = finish - start + end + end) + return result +end |