Skip to content

Fix liquid tag completions support #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions Fluid.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -994,21 +994,25 @@ public void ShouldParseLiquidTag()
}

[Fact]
public void ShouldParseLiquidTagWithBlocks()
public void LiquidTagShouldBreakOnCompletion()
{
var source = @"
{% liquid assign cool = true
if cool
echo 'welcome to the liquid tag' | upcase
endif
%}
";
var source = """
{%- for i in (1..5) %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is - after the percentage symbol for a reason? This is the first time I see it

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In liquid it means that the spaces before the tag should not be rendered. Works on every tags or output tag.

{%- liquid
if i > 3
continue
endif
echo i
%}
{%- endfor %}
""";

var parser = new FluidParser(new FluidParserOptions { AllowLiquidTag = true });
Assert.True(parser.TryParse(source, out var template, out var errors), errors);
var rendered = template.Render();
Assert.Contains("WELCOME TO THE LIQUID TAG", rendered);
Assert.DoesNotContain("45", rendered);
}


[Fact]
public void ShouldParseFunctionCall()
Expand Down
9 changes: 8 additions & 1 deletion Fluid/Ast/LiquidStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ public override async ValueTask<Completion> WriteToAsync(TextWriter writer, Text
for (var i = 0; i < Statements.Count; i++)
{
var statement = Statements[i];
await statement.WriteToAsync(writer, encoder, context);
var completion = await statement.WriteToAsync(writer, encoder, context);

if (completion != Completion.Normal)
{
// Stop processing the block statements
// We return the completion to flow it to the outer loop
return completion;
}
}

return Completion.Normal;
Expand Down