Skip to content
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

Any Blade indents.scm #48

Open
RicardoRamirezR opened this issue Dec 15, 2023 · 7 comments
Open

Any Blade indents.scm #48

RicardoRamirezR opened this issue Dec 15, 2023 · 7 comments

Comments

@RicardoRamirezR
Copy link

Hi all, do any one has an indents.scm file for share

@calebdw
Copy link
Contributor

calebdw commented Jan 26, 2024

I took a crack at this, but I'm pretty sure it's impossible with the current grammar. The indent.begin is used to indent child nodes and the current grammar has them as siblings instead.

image

@EmranMR
Copy link
Owner

EmranMR commented Jan 26, 2024

Mmmm can I have an example of how this is used? I have never come across this capture.

Is this used to implement a functionality like this? 🤔

@php
    automatic indentation after pressing return
@endphp

@calebdw
Copy link
Contributor

calebdw commented Jan 26, 2024

Bingo, you can find a ton of indents.scm below:

https://github.com/nvim-treesitter/nvim-treesitter/tree/master/queries

@EmranMR
Copy link
Owner

EmranMR commented Jan 26, 2024

Oh wow that's a goldmine thanks for sharing all these goodies @calebdw ! As always very much appreciated!

Well, that's not good at all! 😬

I will definitely look into this when I get a chance, but as I am extremely busy just now with university work. It might be a while!

Nova bizarrely still uses their old XML RegEx API to do the indentation hence the oversight.

Regardless, being siblings does not make sense anyways. The stuff should appear as sub-tree! 😊

@EmranMR
Copy link
Owner

EmranMR commented Mar 24, 2024

I have a few questions. I have been playing around in Helix, but I am a bit unsure about the workflow in the modal editors.

  • Do you use snippets? ie write @ifand then it prints stubs?
    • If so, is the indent not baked, inside the snippet?
@if(<placeholder>)
     <placeholder>
@endif
  • Now lets say, after @if the editor indents, when you type @endif do you expect the editor to automatically outdent the line with the @endif as well?

I managed to get the indent working in Helix using the current grammar, for if statements, but there are some caveats:

  • For normal indentation to work, the @if and @endif must be written and present. (this is like brackets, without the matching pair no indentation happens. At least with helix and their defaults anyways)

  • I did of course managed to get around this using a specific capture they have for python style grammars, which is @indent @extend but not sure what would be the equivalent in NeoVim

  • On both occasions, I do need to manually outdent the @endif... is this an expected behaviour?

    • This is my major concern, if this behaviour is normal, I can crack on coming up with a solution/stubs that can be used across editors. Only problem being, there are no standardisation around predicates and captures in tree-sitter, meaning each editor will need to have a different indents.scm for sure!
RPReplay_Final1711240294.mov

@calebdw
Copy link
Contributor

calebdw commented Mar 24, 2024

  • Indents would be backed into the snippet, but that's completely separate from treesitter indents
  • Indentation should happen as soon as there's an @if and it would end when there's an @endif
  • You can take a look at the php indents which I just fixed a bug in
  • I took a look at the indents in the past for blade, and I'm not sure if they're possible without some structural changes
  • Indents are very much editor specific---tree-sitter does not support indents on its own. So I would say that's not the responsibility of this repo to craft the indents (no other ts grammar repo has indent queries in them).

@EmranMR
Copy link
Owner

EmranMR commented Mar 24, 2024

Indents would be backed into the snippet, but that's completely separate from treesitter indents

Indentation should happen as soon as there's an @if and it would end when there's an @endif

Looks promising!
Because if you have snippets, you can align @if and @endif, then allow the editor to take over indentation.

So I reckon the video I uploaded shows a correct functioning indentation?

  1. Write @if
  2. Press o, <return> and O(from endif) to get the indent
  3. And in the end when you write the @endif and press return the editor indents back!

As you said I prob have to adjust some of the nodes, but seems feasible.

I will see how the query works out if too complicated I will just write the stubs so people can have a look and port, like the other scm files. But hoping to keep it clean and simple as possible!

The only gotcha were the nodes that can also be inline, @php() and @php @endphp but already have some ideas how I could get around!

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

No branches or pull requests

3 participants