EmranMR / tree-sitter-blade

tree-sitter grammar for Laravel blade files
MIT License
156 stars 5 forks source link

Any Blade indents.scm #48

Open RicardoRamirezR opened 6 months ago

RicardoRamirezR commented 6 months ago

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

calebdw commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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

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

EmranMR commented 5 months ago

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 commented 3 months ago

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.

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

https://github.com/EmranMR/tree-sitter-blade/assets/11975985/1706d8b9-e266-4429-9ba3-4e31fa8322c6

calebdw commented 3 months ago
EmranMR commented 3 months ago

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!