EmranMR / tree-sitter-blade

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

Neovim issues with injected PHP highlighting #51

Closed stormherz closed 10 months ago

stormherz commented 10 months ago

Hi!

First of all, thanks for all your hard work to make that blade support happen for TS, it means a lot for many devs out there.

The issue I'm having is with the latest improvements of PHP TS and TS blade implementation. I'm almost sure I messed something up, hoping you could give me a hint in the right direction.

I'm on neovim and here's the small snippet I'm testing on:

@php
    $abc = 123;
@endphp

{{ echo '123' }}

<div>
    <div>
        <span>some</span>
    </div>
</div>

There's no errors in InspectTree:

(php_statement) ; [1:1 - 3:7]
 (directive_start) ; [1:1 - 4]
 (php_only) ; [2:5 - 3:0]
 (directive_end) ; [3:1 - 7]
(php_statement) ; [5:1 - 16]
 (bracket_start) ; [5:1 - 2]
 (php_only) ; [5:4 - 14]
 (bracket_end) ; [5:15 - 16]
(text) ; [7:1 - 12:0]
 (element) ; [7:1 - 11:6]
  (start_tag) ; [7:1 - 5]
   (tag_name) ; [7:2 - 4]
  (element) ; [8:5 - 10:10]
   (start_tag) ; [8:5 - 9]
    (tag_name) ; [8:6 - 8]
   (element) ; [9:9 - 25]
    (start_tag) ; [9:9 - 14]
     (tag_name) ; [9:10 - 13]
    (text) ; [9:15 - 18]
    (end_tag) ; [9:19 - 25]
     (tag_name) ; [9:21 - 24]
   (end_tag) ; [10:5 - 10]
    (tag_name) ; [10:7 - 9]
  (end_tag) ; [11:1 - 6]
   (tag_name) ; [11:3 - 5]

My injections and highlights are the same as in repo:

((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 zsh))

((php_only) @injection.content
    (#set! injection.language php_only))
((parameter) @injection.content
    (#set! injection.language php_only))
(directive) @tag
(directive_start) @tag
(directive_end) @tag
(comment) @comment

but it leaves me with something like this: Screenshot 2024-01-09 084547

not quite sure what should I check next =)

EmranMR commented 10 months ago

Hey @stormherz ! Thank you very much for your kind words!

  1. Did you have issues injecting before? or it is your first time using this parser?

  2. Another quick question, are you using the very latest tree-sitter-php? I have not had a chance to play around with it, they just merged the split_parser PR which would hopefully make life easier for all of us and solves #5 :)

I would prob need to update the README and maybe injections.scm, would know more once I try it out? :)

stormherz commented 10 months ago

@EmranMR

  1. Did you have issues injecting before? or it is your first time using this parser?

First time user, yep

  1. Another quick question, are you using the very latest tree-sitter-php? I have not had a chance to play around with it, they just merged the split_parser PR which would hopefully make life easier for all of us and solves Problem injecting php #5 :)

Yeah, that was my first guess, I'm not sure how to verify if tree-sitter actually grabs the latest tree-sitter-php. They do have a lock file in their repo https://github.com/nvim-treesitter/nvim-treesitter/blob/master/lockfile.json which indeed does include commit hash of the latest work in tree-sitter-php (which should include split parser), but I'm not sure if updated tree-sitter-php actually landed on my machine. I've reinstalled it, for sure, but it's a bummer there's no way to check what version was used by tree-sitter, or maybe I'm just missing it :-\

EmranMR commented 10 months ago

Perfect! php injection inside php_only nodes were not possible up to like this week. Before that, it was only supported in the Nova extension, experimentally.

Now I am 100% certain you could do it, and in fact you are adopting the tree-sitter-blade the best time possible. The php_only injection was very much an anticipated feature request for the tree-sitter-php.

I actually think your editor is set up correctly on your side, because blade is parsing correctly, and you are also getting correct syntax highlighting for the html :)

I would keep you updated here, and I would also suggest subscribing to issue #5 . I will probably release more information about it for NVim in the coming days/weeks depending on my free time!

stormherz commented 10 months ago

yep, I've tried to track all of your latest work related to this switch and tree-sitter-php update. I'll stay tuned and try to be of help, at least in terms of verifying an entire chain for neovim, just to see blade up and running after all those years =)

stormherz commented 10 months ago

@EmranMR tried it with manually built parser as calebdw suggested in #5 - it works great! would you like me to close this issue or should we keep it up for now in case me or anyone else will stumble the same issue and will be able to follow the current state of transition to splitted parser?

EmranMR commented 10 months ago

@stormherz I am glad all is working well! Feel free to close the issue as other users can simply search the old ones, plus instead I am going to keep #5 open for time being considering it also includes the manual fix solution!