-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature request: activate injection using a comment #3
Comments
Thank you for your request! How could this work exactly? # injectme: rst_for_docstring
def myfun():
""" This should be formatted as rst"""
pass It is hard to get this to work, as injections are chosen by treesiter-nvim per filetype and not per buffer. |
My idea is "the comment activates injection for the next string". This would be useful to reduce the amount of analysis that treesitter had to perform to identify other languages in every string: the comment would already be the analysis, like one key of an associative array where the values are treesitter functions that will interpret the string. |
This should be done by a treesitter query. When I monitor the strings with lua, only to activate treesitter on a certain comment, this would be much slower. Sorry, but I don't know what to make of this idea |
I used to have a query that conditionally marked the next text fragment to be parsed as an injected language. It just broke and I am trying to figure out why, I think what I had might be what @massimiliano-della-rovere is looking for. For example, in typescript I would write: export const CREATE = /* sql */ `
create or replace function safe_sqrt(double precision)
returns double precision
language sql IMMUTABLE PARALLEL SAFE
as $$
SELECT CASE
WHEN $1 is null THEN null
WHEN $1 < 0 THEN null
ELSE SQRT($1)
END;
$$;
`; and it would highlight it as sql, even if the given sql string does not fit the standard injection template that assumes a generic select query. The injections.scm looked like this:
It broke on a recent update of treesitter. I have no idea why or how to make it work again. Do you think you can fix it? |
When the buffer is parsed by treesitter, an ad-hoc written comment could activate one or more pre-saved injection
The text was updated successfully, but these errors were encountered: