helix
helix copied to clipboard
Add rust injections for c, c++, html, js, py
cc @the-mikedavis
Example
use inline_python::python;
fn main() {
let who = "world";
let n = 5;
python! {
import csv # first import highlight won't work, not sure why
for i in range('n):
print(i, "Hello", 'who)
print("Goodbye")
}
}
I'm not totally sure what's happening here with the injections within (token_tree). The results are same across helix master, incremental, and tree-sitter-cli: the injection works on individual identifiers under the token_tree, but any python that uses multiple identifiers isn't parsed correctly. For example, in the string of identifiers making up the comment after the import, the "#" is highlighted as a comment but the subsequent nodes are not highlighted as comments. Based on the range of the outermost (token_tree) and the description of injection.include-children in the tree-sitter docs
injection.include-children- indicates that the@injection.contentnode's entire text should be re-parsed, including the text of its child nodes. By default, child nodes' text will be excluded from the injected document.
I would expect that the contents of (token_tree) shouldn't matter, as the entire text of that node should be re-parsed.
I think what's happening here is that some of the rules from the rust grammar are excluding nodes from the token tree that are important to be parsed for python's sake. For example, it looks like the # token is not present under (token_tree).
@archseer do you have thoughts about the behavior here?
I find most of these a bit niche and not sure if we want these in by default. i.e. https://github.com/search?l=Rust&q=inline_python&type=Code is barely used
I find most of these a bit niche and not sure if we want these in by default. i.e. https://github.com/search?l=Rust&q=inline_python&type=Code is barely used
Maybe have them commented out by default? But I doubt anyone using it wants to dig into the highlight to enable support for it. Will enabling it slows down the tree-sitter highlighting?
The injections for python in rust may work better with the new (#set injection.include-unnamed-children true) rule from https://github.com/helix-editor/helix/pull/3129
I haven't tried it out though.
@the-mikedavis Do you think I should continue to work on this or just close it given that these are rarely used?
IMO it's more work than it's worth to make these queries look good but I'm biased since I haven't used Rust in a cross-language way like this before :P
I only used it a couple of times only and I don't need it anymore so I guess I am just going to close this. Or maybe we can add it commented out.