-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(queries): add highlight queries #41
base: master
Are you sure you want to change the base?
Conversation
Would love this getting merged! |
Would this also support highlighting of variable interpolation? Ansible and Helm are two systems off the top of my head that use this and I'd love to be able to color the interpolation differently. For example:
Where Currently: - name: check if the correct loki version is downloaded
ansible.builtin.stat:
path: "/opt/loki/{{loki_server_version}}/loki-linux-amd64.zip"
register: loki_server_check_downloaded
changed_when: false TSPlayground:
|
@lcrownover I might be wrong, but I believe Ansible and Helm/Gotemplate style variable interpolation would require more than just syntax highlighting queries. The syntax tree built by the parser only exposes string nodes, so there's no nodes for interpolated variables available to query against for syntax highlighting purposes I'm afraid. |
@jimeh Maybe I'm showing my ignorance on the inner workings of treesitter, but why is python able to have this functionality:
Yet we can't modify the yaml parser to support something similar:
Isn't this the module that governs how the tokens get parsed? |
@lcrownover Apologies, I probably should have elaborated a bit more. The major difference is that in Python string interpolation is part of the language and syntax. Ansible and Helm templating stuff are not part of YAML's syntax. Hence I can't do anything with the highlight queries in this PR to syntax highlight Ansible and Helm things. That said, the tree-sitter YAML parser could be modified to support parsing those things, but that's outside of my area expertise. And I would not bet on that happening as they are not part of the YAML specification. What's more likely is that someone forks the YAML parser here to try and make Ansible and Helm specific tree-sitter parsers. I think Ansible would be a relatively simple fork, as it is should only be a matter of dealing with string interpolation within quoted strings. Helm however would be much more complex, because unlike Ansible, Helm templates are not valid YAML syntax. It's more like trying to parse Ansible Jinja2 template files that happen to output YAML. And it would need to fully support Go's text template engine that Helm uses as well. Hopefully that's helped clarify things a bit :) |
@jimeh Ahh, I see. It's been so long since I made the original comment that I forgot that this is a PR for the module, not the module itself. My mistake! I do agree with you that it'd be quite a pain to write a parser to handle all the edge cases that have been laid over the YAML standard. Having an ansible treesitter module would maybe work, though due to the overloading of YAML syntax, it's already hard enough to differentiate between a standard YAML file, an Ansible file (jinja2), or a Helm template as they all share the same extension. |
Yeah, I don't blame you. To make things slightly more convoluted, Ansible technically has two common uses of YAML:
|
Adds a set of queries for syntax highlighting yaml, similar to other tree-sitter grammar projects.
This is the same queries from my PR against Emacs' tree-sitter-langs project: emacs-tree-sitter/tree-sitter-langs#134
Screenshot
Here's how syntax highlighting turns out in Emacs, using the doom-vibrant theme: