Support for @context.start

This commit is contained in:
Lewis Russell 2023-03-08 22:06:29 +00:00 committed by Lewis Russell
parent 75f8704fd3
commit 97d36de214
3 changed files with 43 additions and 1 deletions

View file

@ -93,6 +93,8 @@ local is_valid = cache.memoize(function(node, query)
range[3] = range[1]
range[4] = -1
local node_srow = range[1]
-- Try and iterate on the parent node as iter_matches won't match on the top
-- level node
local iter_node = node:parent() or node
@ -104,13 +106,16 @@ local is_valid = cache.memoize(function(node, query)
local srow, scol, erow, ecol = node0:range()
-- because iter_node != node we could match outside of node
if srow < range[1] then
if srow < node_srow then
break
end
local name = query.captures[id] -- name of the capture in the query
if not r and name == 'context' then
r = node == node0
elseif name == 'context.start' then
range[1] = srow
range[2] = scol
elseif name == 'context.final' then
range[3] = erow
range[4] = ecol

View file

@ -7,3 +7,9 @@
(template_literal)
] @context)
(for_object_expr
(_)
(for_intro) @context.start
(_) @context.end
) @context

31
test/test.tf Normal file
View file

@ -0,0 +1,31 @@
locals {
input_deps = {
for slug, group in local.t2r_map :
slug => {
a = 1
a = 1
a = 1
a = 1
}
}
}