-
-
Couldn't load subscription status.
- Fork 714
Improve {*} comment parsing for better consistency with IDEs and old projects
#1127
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
base: master
Are you sure you want to change the base?
Improve {*} comment parsing for better consistency with IDEs and old projects
#1127
Conversation
…ng and legacy behavior
- Adjusted TemplateLexer to ensure `{*}` properly opens comments and ends only on valid `*}`
- Improved consistency with IDEs like PhpStorm and VS Code
- Simplified upgrades for projects migrating from Smarty v2 by preserving familiar comment handling
- Added new test case
|
I'm quite sure neither Plus, if I understand this correctly: if we change this now, we break compatibility with Smarty v3, v4 and v5. (v3 has been out since 2010, so 15 years ago.) That seems worse than leaving it as it is. I do agree it's a bummer the IDEs format this incorrectly, but shouldn't the IDEs plugins be fixed instead? |
|
Thanks for the feedback. I understand the hesitation around changing something that’s been the same since v3. The goal here is to make Smarty’s comment syntax act exactly as the docs say: comments are “surrounded by asterisks,” meaning With this PR, If a template has a standalone Overall, this update brings Smarty’s behavior in line with its documentation and what developers (and their tools) expect, making things clearer and more predictable all around. |
I totally agree
Also agree.
I'm not sure about that. I would have expected |
|
Here’s how GitHub (github-linguist/linguist) {**} CONTENT 1
{* normal 1 *} CONTENT 2
{*} pincers 1 *} CONTENT 3
{*} pincers 2 {*} CONTENT 4
{* normal 2 *} CONTENT 5 |
|
I'd vote for consistency and let Perhaps the latter is a discussing for a different thread. |
|
My colleagues were split on what they expected what would happen with I'm not sure how to proceed. One of my main goals with Smarty is to maintain stability and backwards compatibility. Changing the syntax would require a new major release. I don't think the problem at hand is so big that it warrants such a big step. I'd rather help fix the IDEs as that surely will not have any negative side effects for anyone. |
|
Thanks for considering all sides of this. I get that a major version sounds like the “proper” route, but I wanted to lay out what actually happens if the quirk stays for 3/4/5:
By confirming this as a bug and aligning the behavior for 3–5, tools and editors can support a single, predictable approach, and developers won’t get surprised when code that’s highlighted as a comment unexpectedly shows up in output. Long-term, this seems less disruptive than deferring the issue and ending up with even greater fragmentation. Thanks again for hearing me out and weighing the options with the bigger picture in mind. |
I'd say it already is a official feature, since it has been implemented like this for over 15 years. One could say the way things were in v2 was a quirk, because Smarty didn't have a real parser/lexer back then and relied on regular expressions to do the matching. Thus it follows that changing the behavior requires a new major version number.
I (again) propose fixing the IDE plugins. I've found a textmate bundle for Smarty that seems rather outdated. |
|
Understood, and thanks for the thoughtful back-and-forth. As a last idea: would a config toggle for comment parsing be possible? That would let people choose the behavior that fits their workflow, and everyone else keeps the status quo. If that’s not practical, I’ll just stick with my patch locally. Appreciate your time and all the work you put into Smarty! |



This PR adjusts
{*}comment parsing behavior to resolve inconsistencies with IDE syntax highlighting (e.g., PhpStorm, VS Code) and to better support projects upgrading from Smarty v2.Why:
{*}comments required*}to close, which aligns with modern IDE behaviors.{*}as both the start and end of a comment, which causes confusion when using IDEs or updating old templates.Behavior Before and After
For the following code:
{*} comment 1 {*}Before:
Outputs:
comment 1After:
Outputs: (nothing, comment is ignored as expected)
This fixes parsing inconsistencies, aligns with IDE syntax highlighting, and retains expected behavior for old templates written in Smarty v2.
Screenshots
Screenshots of IDE comment highlighting
PhpStorm
VS Code