From 514026b6786bcc554ff865b9c3543495caebb6d0 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Sat, 3 May 2025 14:26:08 -0700 Subject: [PATCH] Fix liquid tag completions support --- Fluid.Tests/ParserTests.cs | 22 +++++++++++++--------- Fluid/Ast/LiquidStatement.cs | 9 ++++++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Fluid.Tests/ParserTests.cs b/Fluid.Tests/ParserTests.cs index 2ac1c835..1bb22444 100644 --- a/Fluid.Tests/ParserTests.cs +++ b/Fluid.Tests/ParserTests.cs @@ -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) %} + {%- 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() diff --git a/Fluid/Ast/LiquidStatement.cs b/Fluid/Ast/LiquidStatement.cs index cde38edd..2ebd564c 100644 --- a/Fluid/Ast/LiquidStatement.cs +++ b/Fluid/Ast/LiquidStatement.cs @@ -15,7 +15,14 @@ public override async ValueTask 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;