Nesting language highlights (e.g. rst in Python docstrings) #4655
Unanswered
BrunoMSantos
asked this question in
Q&A
Replies: 1 comment 3 replies
-
See #4199 for rst in Python docstrings. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey, I'm really new to this treesitter thing and to the whole query bit, but I was hoping I could highlight docstrings in certain languages. I was especially hoping that this would give me better (not to mention easier) results than some clunky 'old vim' syntax configuration I had.
Notably, I was exploring if I could do rst in Python's docstrings and in C's / C++'s
/** */
block comments. In some jobs, doxygen inside C/C++ might also be nice, but I don't think there's a parser for that at the moment. Despite some early results I quickly found issues, which hopefully someone might be able to help with.Starting with Python, it seems pretty easy and in fact I think I got it right by injecting the query:
The relevant comments do get highlighted as rst and it looks pretty much like what I'd want. There are two nagging issues I'm facing though: can't get the 'paragraph' node to be in the colour I want (still shows up in 'string' colour, other rst nodes are fine) and it causes an issue in
:checkhealth
for starlark.To try and override the highlight, I tried this in the Python's
after/ftplugin
(colour unimportant, I was just looking for a change):But so far no change. If I do this instead, then it works, but all strings (and comments) get recoloured, which is not what I want:
As for the starlark issue, I have no clue, but this is the error I get:
I believe my injection file is getting roped in by starlark's inclusion of Python's injections. Is my injection query wrong? Or is this perhaps a bug? Otherwise, is there a way I can extend Python this way without the change affecting starlark as well?
Now, I'm not so hopeful about rst in C/C++, but I was looking to see if these type of comments were doable and go from there:
Even with no other considerations, I got stuck trying to filter out the
*
s. I was trying to do it withoffset
, but I clearly have no clue how to write this. Closest I got was this, which looks funny to me and indeed doesn't work:Any directions would be welcome. And if this is entirely hopeless at the moment, that will be good to know too.
And yes, I know rst in C is not a thing, but one can hope :)
Beta Was this translation helpful? Give feedback.
All reactions