Skip to content

Commit 2c42be0

Browse files
authored
Fix liquid tag completions support (#794)
1 parent 77b77db commit 2c42be0

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

Fluid.Tests/ParserTests.cs

+13-9
Original file line numberDiff line numberDiff line change
@@ -994,21 +994,25 @@ public void ShouldParseLiquidTag()
994994
}
995995

996996
[Fact]
997-
public void ShouldParseLiquidTagWithBlocks()
997+
public void LiquidTagShouldBreakOnCompletion()
998998
{
999-
var source = @"
1000-
{% liquid assign cool = true
1001-
if cool
1002-
echo 'welcome to the liquid tag' | upcase
1003-
endif
1004-
%}
1005-
";
999+
var source = """
1000+
{%- for i in (1..5) %}
1001+
{%- liquid
1002+
if i > 3
1003+
continue
1004+
endif
1005+
echo i
1006+
%}
1007+
{%- endfor %}
1008+
""";
10061009

10071010
var parser = new FluidParser(new FluidParserOptions { AllowLiquidTag = true });
10081011
Assert.True(parser.TryParse(source, out var template, out var errors), errors);
10091012
var rendered = template.Render();
1010-
Assert.Contains("WELCOME TO THE LIQUID TAG", rendered);
1013+
Assert.DoesNotContain("45", rendered);
10111014
}
1015+
10121016

10131017
[Fact]
10141018
public void ShouldParseFunctionCall()

Fluid/Ast/LiquidStatement.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ public override async ValueTask<Completion> WriteToAsync(TextWriter writer, Text
1515
for (var i = 0; i < Statements.Count; i++)
1616
{
1717
var statement = Statements[i];
18-
await statement.WriteToAsync(writer, encoder, context);
18+
var completion = await statement.WriteToAsync(writer, encoder, context);
19+
20+
if (completion != Completion.Normal)
21+
{
22+
// Stop processing the block statements
23+
// We return the completion to flow it to the outer loop
24+
return completion;
25+
}
1926
}
2027

2128
return Completion.Normal;

0 commit comments

Comments
 (0)