EmranMR / tree-sitter-blade

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

Two trees in TSPlayground #47

Closed RicardoRamirezR closed 10 months ago

RicardoRamirezR commented 10 months ago

Thank you for the amazing work here, very functional!

The following code, generates two trees in TSPlayground

<div class="photo">

    <h3 class="record-title">{{ $photo->title }}</h3>

    @if ($photo->extension == '.pdf')
        @foreach ($photo->urls as $url)
            <img src="{{ $url }}" alt="pdf page">
        @endforeach
    @else
        <img src="{{ $photo->path }}" alt="image">
    @endif
</div>

In the next image, the cursor is in the second tree in the TSPlayground buffer

Screenshot 2023-12-15 at 12 07 13 PM

And here in the second tree there are errors not shown in the first tree

Screenshot 2023-12-15 at 12 08 20 PM

any clues?

EmranMR commented 10 months ago

Hi @RicardoRamirezR Thank you for the kind words!

This is so strange how can the same file give two trees? 😂 I am actually clueless here. Is this reproducible or just randomly decides to give one or the other??

However I parsed your code in CLI and this is what I got with no error

(blade [0, 0] - [9, 0]
  (text [0, 0] - [1, 29])
  (php_statement [1, 29] - [1, 48]
    (bracket_start [1, 29] - [1, 31])
    (php_only [1, 32] - [1, 46])
    (bracket_end [1, 46] - [1, 48]))
  (text [1, 48] - [3, 4])
  (conditional [3, 4] - [7, 10]
    (directive_start [3, 4] - [3, 7])
    (bracket_start [3, 8] - [3, 9])
    (parameter [3, 9] - [3, 36])
    (bracket_end [3, 36] - [3, 37])
    (loop [3, 38] - [5, 15]
      (directive_start [3, 38] - [3, 46])
      (bracket_start [3, 47] - [3, 48])
      (parameter [3, 48] - [3, 68])
      (bracket_end [3, 68] - [3, 69])
      (text [4, 4] - [4, 14])
      (php_statement [4, 14] - [4, 24]
        (bracket_start [4, 14] - [4, 16])
        (php_only [4, 17] - [4, 22])
        (bracket_end [4, 22] - [4, 24]))
      (text [4, 24] - [5, 4])
      (directive_end [5, 4] - [5, 15]))
    (conditional_keyword [5, 16] - [5, 21]
      (directive [5, 16] - [5, 21]))
    (text [6, 4] - [6, 14])
    (php_statement [6, 14] - [6, 32]
      (bracket_start [6, 14] - [6, 16])
      (php_only [6, 17] - [6, 30])
      (bracket_end [6, 30] - [6, 32]))
    (text [6, 32] - [7, 4])
    (directive_end [7, 4] - [7, 10]))
  (text [8, 0] - [9, 0]))

Here is the photo in Nova using the lates parser, there is a tiny un noticeable hiccup in the experimental feature I have that parses parameters as php-only but, thats out of tree-sitter-blade scope

As you can see the syntax highlighting is performed correctly. I can see your brackets are not being picked up for some reason 🤔

image
RicardoRamirezR commented 10 months ago

Hey @EmranMR hope you are well.

I testes is various files and the same double tree. I've installed your tree-sitter and copied the queries in Neovim.

Your tree starts with blade, mine with text.

Yes no php-only

EmranMR commented 10 months ago

@RicardoRamirezR ah perfect! So I turned off the php_only injection and still works fine on my side! I am not an expert in NeoVim unfortunately! not sure why it is behaving like that!

I am sure you have done so but, have you had a look at the configs here for NeoVim NeoVim Discussion? a few people seemed to have had issues and managed to fix it and posted the corrected config. Feel free to comment there and link this issue there as well, the NVim community are extremely helpful! 😊

Here is a screenshot with the latest parser and no php injection in Nova.

image
RicardoRamirezR commented 10 months ago

Hi @EmranMR

I removed the Neovim after/queries/blade folder, no highlights then but there is only one tree.

Screenshot 2023-12-17 at 9 49 56 AM

So is a Neovim config issue. I'll go to the Neovim Discussions

Now, why your CLI parsed shows blade and mine text, just wondering

EmranMR commented 10 months ago

If you mean the highlighted <div> in the photo the cli is showing text as well as it should.

But the root should be (blade) Also bear in mind my cli is parsing with no injections etc.

The AST looks correct though, if there is no (blade) I am not sure if Neovim is hiding it and just showing the sub-tree? 🤔

RicardoRamirezR commented 10 months ago

Thnak you for your time

RicardoRamirezR commented 10 months ago

Me again @EmranMR, with the injections empty or with, only one tree:

((text) @injection.content
    (#not-has-ancestor? @injection.content "envoy")
    (#set! injection.combined)
    (#set! injection.language bash))
Screenshot 2023-12-18 at 2 35 43 PM

Tree twice with:

((text) @injection.content
    (#not-has-ancestor? @injection.content "envoy")
    (#set! injection.combined)
    (#set! injection.language php))
RicardoRamirezR commented 10 months ago

I've place the inquire in #19, thank you

EmranMR commented 10 months ago

Hey @RicardoRamirezR ! I think if found the issue for you, (well that's what I am hoping)

You are using the same predicates for both php and bash!

Please note the #has-ancestor? for bash. The #not-has-ancestor? is for the rest of the document php

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

So I would suggest just deleting everything in injection.scm and replacing with following:

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

; could be bash or zsh
; or whatever tree-sitter grammar you have.
((text) @injection.content
    (#has-ancestor? @injection.content "envoy")
    (#set! injection.combined)
    (#set! injection.language bash))

; 🚧  Available for experimental split_parser see issue #5 
;((php_only) @injection.content
;    (#set! injection.language php_only))
;((parameter) @injection.content
;    (#set! injection.language php_only))

Do let me know if it worked!

RicardoRamirezR commented 10 months ago

Hi @EmranMR, may be it was an issue coping a pasting, with:

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

; could be bash or zsh
; or whatever tree-sitter grammar you have.
((text) @injection.content
    (#has-ancestor? @injection.content "envoy")
    (#set! injection.combined)
    (#set! injection.language bash))

; 🚧  Available for experimental split_parser see issue #5 
;((php_only) @injection.content
;    (#set! injection.language php_only))
;((parameter) @injection.content
;    (#set! injection.language php_only))

I got double tree, the first one with errors the second one is ok.

EmranMR commented 10 months ago

ah, I was hoping that was the issue? unfortunately I am away from my iMac for a few weeks! But will run some tests once back to see what Nova shows.

However maybe a good excuse for me to finally get my hand dirty with NeoVim haha. I see if I can set it up on my remote system, and try to debug on that!

Wish me luck as I know the learning curve is quite steep!

RicardoRamirezR commented 10 months ago

I wish you luck @EmranMR, have a good end of year

calebdw commented 10 months ago

This issue can be closed, the double tree is just a result of all the injected languages (php, html, etc) and the use of the injection.combined directive