Skip to content

[TwigComponent] Minimal support of comment lines - #2464

Merged
Kocal merged 1 commit into
symfony:2.xfrom
smnandre:twig/minimal-support-comment-line
Feb 24, 2025
Merged

[TwigComponent] Minimal support of comment lines#2464
Kocal merged 1 commit into
symfony:2.xfrom
smnandre:twig/minimal-support-comment-line

Conversation

@smnandre

Copy link
Copy Markdown
Member

Twig introduced the inline comments in twigphp/Twig#4349

This PR add minimal support for it the PreLexer / HTML syntax

<twig:Button
    # comment
    bar="bar"
/>

I'd like some IRL feedbacks on this one :)

@Kocal Kocal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool!

I don't have real use-cases from the projets I'm working on, but I believe it will be super-useful (even if I believe some comments can be avoid by using good attribute's name or variable!)

However, introducing a new syntax means that tools manipulating ASTs (like IDEs, Twig-CS-Fixer, maybe TwigStan, and syntax highlighting) will break, right?

@smnandre

Copy link
Copy Markdown
Member Author

Not at all, they already are compatible. I'm just following Twig syntax here, not adding anything new. But that means adapting the PreLexer we use to convert HTML Syntax into regular Twig code :)

@Kocal

Kocal commented Dec 23, 2024

Copy link
Copy Markdown
Member

I mean, for tools that does not use our PreLexer.

I've tested with Twig-CS-Fixer and no issues so far, but I think it does not support Twig Component at all.
I don't know about TwigStan (which I believe indirectly use our PreLexer).

But, for syntax coloration it does not work, and I don't know who/when this new syntax will be added to IDE and other syntax coloration libraries:
image

@smnandre

Copy link
Copy Markdown
Member Author

I've tested with Twig-CS-Fixer and no issues so far, but I think it does not support Twig Component at all.

They do, and they integrated inline comments right after Twig release :)

But, for syntax coloration it does not work, and I don't know who/when this new syntax will be added

Me neither but... how is this related to this PR ? :) I'm genuinely not sure to get the questions here.

Twig syntax changes are generally pretty quickly integrated into PhpStorm Twig integration (or in the Symfony plugin).

@94noni 94noni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would be very welcome to allow props comment next to/along the usage in the template👍🏻

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Feb 16, 2025
@smnandre

Copy link
Copy Markdown
Member Author

cc @Kocal @kbond @WebMamba ?

@smnandre
smnandre force-pushed the twig/minimal-support-comment-line branch from bab6e5b to 11d8d12 Compare February 22, 2025 22:08
Twig introduced the inline comments in twigphp/Twig#4349

This PR add minimal support for it the PreLexer / HTML syntax

```twig
<twig:Button
    # comment
    bar="bar"
/>
```

I'd like some IRL feedbacks on this one :)
@smnandre
smnandre force-pushed the twig/minimal-support-comment-line branch from 11d8d12 to df97990 Compare February 24, 2025 18:28
@Kocal

Kocal commented Feb 24, 2025

Copy link
Copy Markdown
Member

Thanks Simon.

@Kocal
Kocal merged commit f144cf0 into symfony:2.x Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DX Feature New Feature Status: Reviewed Has been reviewed by a maintainer TwigComponent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants