Skip to content

Conversation

@xHeaven
Copy link
Collaborator

@xHeaven xHeaven commented Nov 29, 2025

Closes #21.

Cursor in the example is |.
Typing {{| will produce {{|}}. Same with {{!! and {{--.
Upon pressing space with the cursor like this: {{|}} it will be expanded to {{ | }} instead of {{ |}} for ergonomics.

Additionally, modifying the opening bracket modifies the closing bracket as well. For example if you have {{ $variable }} and you change the opening bracket to {{!!, the closing bracket will also reflect the change and the line becomes {{!! $variable !!}}.

@github-actions
Copy link

github-actions bot commented Nov 29, 2025

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/qodana-action@v2025.2.1
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

@xepozz
Copy link
Collaborator

xepozz commented Nov 29, 2025

Typing {{ then pressing space will produce {{ }}.

I think it should be done with a lexer and brackets pair mechanism, what do you think?

Additionally, modifying the opening bracket modifies the closing bracket as well. For example if you have {{ $variable }} and you change the opening bracket to {{!!, the closing bracket will also reflect the change and the line becomes {{!! $variable !!}}.

Is it what users expect? and should it be done this way?
TypeHandlers are much expensive because they're called on each type, how often users want to switch the brackets?
As @brendt mentioned in the Issue it would be nice to have an intention to switch the brackets via a context action.
Switching from string interpolation to commented one should be done with a CommentHandler and be available with cmd+/ shortcut. I think it's better to keep this way at least for now.
What do you think?

@xHeaven
Copy link
Collaborator Author

xHeaven commented Nov 29, 2025

I think it should be done with a lexer and brackets pair mechanism, what do you think?

Ideally, yes, however it'd make things quite a lot more complex. I also have no experience with multi-character bracket matching, IntelliJ's brace matching model is single-token based. I could use a bit of help here.

Is it what users expect?

Not necessarily, but I personally find it a nice and quick way of replacing both brackets at once. Might need a bit of getting used to, though.

and should it be done this way? TypeHandlers are much expensive because they're called on each type, how often users want to switch the brackets? As @brendt mentioned in the Issue it would be nice to have an intention to switch the brackets via a context action. Switching from string interpolation to commented one should be done with a CommentHandler and be available with cmd+/ shortcut. I think it's better to keep this way at least for now. What do you think?

We could possibly let the users decide? We could add some kind of option to the menu and the user could choose whether they want automatic bracket changing (marked as CPU intensive like Laravel Idea does with some features) or not. What do you think?

@brendt
Copy link
Member

brendt commented Dec 2, 2025

I actually really like this feature, it's something I've often missed in Blade. For me personally, having this indeed removes the need for a context action, but I reckon that action will still be useful to others.

Of course, if it's performant enough.

@xHeaven
Copy link
Collaborator Author

xHeaven commented Dec 2, 2025

I actually really like this feature, it's something I've often missed in Blade. For me personally, having this indeed removes the need for a context action, but I reckon that action will still be useful to others.

Of course, if it's performant enough.

I'll add actions as well, then, and I'll make it so you can opt-out from the auto-bracket-matching feature via settings if it'd be too CPU-heavy on your machine.

As for the lexer part, I'll still need a bit of help with that. @xepozz 👀 It could also come in a next iteration, just so in the meantime users of the plugin could enjoy the feature as-is.

Copy link
Collaborator

@xepozz xepozz left a comment

Choose a reason for hiding this comment

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

com.github.tempest.framework.views.completion.TemplateBracketBackspaceHandler doesn't seem to work
I'd suggest to remove it at all.

As for closing pairs I'd suggest to implement it as the following:

  • placing { adds another } without any doubt
  • placing ! or - after {{ doubles the char and places doubled chars before the closing }}
  • placing a space adds another one, the same as you did

Regarding implementation, I'd suggest to use indexes instead of toString() and positional checks.

@xHeaven
Copy link
Collaborator Author

xHeaven commented Dec 2, 2025

com.github.tempest.framework.views.completion.TemplateBracketBackspaceHandler doesn't seem to work I'd suggest to remove it at all.

Are you sure? It works for me.
Try this:

{{
// gets autocompletd to {{}}
{{  }}
// lets add !!
{{!! !!}}
// now if you delete the first two !! (which is what this class does)
{{ }}

As for closing pairs I'd suggest to implement it as the following:

* placing `{` adds another `}` without any doubt

* placing `!` or `-` after `{{` doubles the char and places doubled chars before the closing `}}`

* placing a space adds another one, the same as you did

Regarding implementation, I'd suggest to use indexes instead of toString() and positional checks.

I'll look into this. Done.

@xepozz
Copy link
Collaborator

xepozz commented Dec 2, 2025

Looks good. Thanks for improving. Feel free to merge if you're done

@xHeaven xHeaven merged commit 9e7ada6 into main Dec 2, 2025
6 checks passed
@xHeaven xHeaven deleted the feature/bracket-autocompletion branch December 2, 2025 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically add closing }} !!} --}} brackets

4 participants