Closed eduardoarandah closed 3 years ago
Hey! The tree that the PHP treesitter parser creates seems to be a bit weird and it doesn't seem to match the output in the treesitter playground.
For example, in this simple case, the playground shows the tags, but in reality, the HTML part is just text
(everything up to <?php
):
(I checked the current node under the cursor with :lua print(require'nvim-treesitter.ts_utils'.get_node_at_cursor(0):type())
)
This means that there is no container node that can be used as a check for this plugin. The only nodes are text
and program
.
However, if I add a PHP end tag (?>
), then there is a text_interpolation
node:
text_interpolation
seems like a good check for setting <!-- %s -->
.
Everything inside text_interpolation
is once again a text
node. This means that any style
or script
tags cannot be detected 😕
Also, if the PHP tag is wrapped in an HTML tag, then the parser will break:
This is the best result I managed to get:
https://user-images.githubusercontent.com/9450943/112734545-1efcbb80-8f4f-11eb-9125-3f25cd6c378b.mov
I used this config:
php = {
text_interpolation = '<!-- %s -->',
},
And setlocal commentstring=//\ %s
in after/ftplugin/php.vim
I'm hoping that once https://github.com/JoosepAlviste/nvim-ts-context-commentstring/issues/3 is implemented, we could use language tree to improve this.
Hey @eduardoarandah, just wanted to let you know that #3 has been implemented and PHP should work a bit better now.
However, I still didn't get the injected CSS and JS working because it doesn't seem like they even get injected.
Anyways, if you manage to inject those languages, then the current solution should work 😄 I just couldn't figure out how to get the injection working.
Other than that, let me know if there are any other problems with PHP.
I've been trying to figure out how to setup commentstring for a php file.
I'm trying Treesitterplayground to get information, but have no luck setting up correct comment style.
What is the procedure to find out that info?
plugins:
treesitter config: