Hi @logan !
No problem at all! So, as you pointed correctly, oddly up until recently it was not possible to inject only php
due to the way the parser was designed.
As an example for Blade
, The file .blade.php
is a valid php
but instead of using <?php ?>
to start the php
parsing/completion you could do {{I am php now}}
in the regions parsed as HTML
.
Now before the release the <?php ?>
syntax was the only thing recognised by the tree-sitter-php
parser as it was hard-coded .
Also, just to add, the html
injection responsibility is passed on to the tree-sitter-php
and tree-sitter-blade will be only responsible for injecting php
or the php_only
based on the context
So for tree-sitter-blade
if I did php
injection for {{ php_only }}
, you would have gotten the content parsed as HTML
, and the only way to get the php
parsing would be {{<?php xxx ?>}}
. With the new release I can easily distinguish where to inject the php
or php_only
.
Now this a very interesting PR, and with the aim to have minimal overheads for yourself hopefully . I noticed users were able to swap with no bother in NeoVim and so forth, like flicking a switch.
Basically what they have done, is they created a common/ folder that holds the old parser. Then they created two folders php_only
and php
where the grammar exists, which imports the common-grammar
from the common/
and based on the argument decides what to do, bypass the HTML
or just parse the PHP
.
The tactic is very similar for what they did for typescript
and tsx
in tree-sitter-typescript!
Possible Update Guide?
I reckon all that is needed from your side is to make the .dylib
using the grammar.js
in those two folders, then make a simple php_only.xml
inside Syntaxes/
folder.
Here is what I did to port / hack my way to get the Laravel Suite Extension correctly parsing php_only
inside the tree-sitter-blade
using the old messier PR, which was sort of, based on a duplicate strategy rather than using common/
- I generated the
php-only.dylib
. for some odd reason I remember I had an issue with naming/generation and I could only do php-only
instead of php_only
because of the make file
or the way shell
script was working from Nova docs. So I manually changed them myself, to get them working by hard coding the parser-name, instead of relying on the automatic repo
based name generation. (might not be relevant for the new PR!)
- I then created a simple
php-only.xml
inside Syntaxes/
- Then I duplicated the internal php
Completions
for php … However inside Completions/PHP.xml
, I changed the following line, and it all started working fine!
// Completions/PHP.xml
<syntax>php-only</syntax>
The new version should hopefully be even easier to port!