EmranMR / tree-sitter-blade

tree-sitter grammar for Laravel blade files
MIT License
186 stars 8 forks source link

Parsing shell recursively does not work after Laravel Envoy grammar implementation #38

Closed EmranMR closed 10 months ago

EmranMR commented 10 months ago

There is a bug, where, if you are in the $.envoy node, the shell injection is not applied recursively. Whereby after one level of nesting it is parsed as HTML text

Example
  1. Major refactoring required
  2. Reset all unit tests
  3. revert back from from aliasing for text, and hand it off to injection.scm
  4. very likely breaking change, users are required to change the capture node in injections.scm

However this is unfortunately necessary to make the parser future proof and removing duplication, ie creating a separate $.envoy_definition which basically mirrors $.definition, when implementing envoy

EmranMR commented 10 months ago

Hi @yaegassy and @calebdw!

I hope you are both very well! Can I please have your input on the v0.8.0 before I push it? There are breaking changes and I would really like to know if this is possible in Nvim! Everything is working as expected in Nova, it is just I am not sure about NVim. πŸ™

I have pushed the Envoy branch so that you can have a look, pull and play around

Here are the supported predicates in Nvim, I can see there is also a has_ancestor in the source code but I would like to have your input whether the new injections.scm I have created, can simply be used as a copy and paste solution when users upgrade to v0.8.0

Background and Nova's Working code snippets

((text) @injection.content (#has-ancestor? @injection.content "envoy") (#set! injection.combined) (#set! injection.language shell))

((php_only) @injection.content (#set! injection.combined) (#set! injection.language php_only)) ((parameter) @injection.content (#set! injection.language php_only))



Are the queries above valid in Nvim as well. Because that is the only change the users need to apply to start using `0.8.0^`
- " parse text as shell if it has the `$envoy` as an ancestor, if not parse as php" 

I hope it works because the results are amazing, you have php, html and shell injection in one document. The precision provided by tree-sitter is just mind blowing. I do not know any parser out there that this can be done with! Below is the working end result in Nova! πŸ˜… 🀯

<img width="625" alt="Screenshot 2023-11-30 at 12 16 38" src="https://github.com/EmranMR/tree-sitter-blade/assets/11975985/ef55d9b5-da33-4210-810f-80e4533cceb9">
calebdw commented 10 months ago

Hi @EmranMR,

This is neat, however, the shell language does not exist---I had to update to bash

EmranMR commented 10 months ago

@calebdw thank you so much for taking time and checking this. I really appreciate it!

I shall get on drafting the release.πŸ‘

And good catch with the shell as well, that was not intended!

I will certainly change to bash in theinjections.scm, to avoid confusion for the broader audience! ☺️