-
Notifications
You must be signed in to change notification settings - Fork 11
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
offset
directive in injection queries is not respected
#37
Comments
Treesitter supports syntax highlighting for nested languages by adding a query to your nvim configuration, by putting it in a queries/LANGUAGE/injections.scm file. Would it be possible to use these same queries? For example; I made a query to get syntax highlighting for SQL in my Javascript files by creating the following query in ~/.config/nvim/queries/javascript/injections.scm. Because the output variable is '@Sql', treesitter recognizes it as sequel and highlights it as such:
|
Indeed, my dream-API would be to get the ranges of injections directly from the treesitter module in neovim. Upon closer searching, I think this is possible. And from this we should be able to get those captures: |
Wow this is great! For me it still does not properly work however, and that might be out of the scope of your package. But the used query injection does not seem to acknowledge the offset I've defined for querying my sql. Which means the backticks in my code are incorrectly parsed as part of the SQL: For example, the query in my previous comment finds the SQL inside the knex.raw(), but it trips over the backticks: const plan = await knex.raw(`
SELECT plan.name
FROM subscription
JOIN plan ON subscription.plan_id = plan.id
WHERE account_id = :accountId
`, { accountId: user.accountId }).then(firstOrNull); This might be more an issue with treesitter, but I am not sure. |
Looks like the otter.nvim/lua/otter/keeper.lua Line 67 in 242d180
However, I can't get treesitter to give me the correct range with directives applied, which supposedly was supposed to happen with the way I do it in the commit mentioned above. Any idea? |
offset
directive in injection queries is not respected
If I read this correctly, someone proposed a change to treesitter to update the injection with the offset: https://github.com/nvim-treesitter/nvim-treesitter/pull/1240/files#diff-81f58ecd0f4978b575136c86619adc8dbc9a0c9e87f87702ddf22615d0ac6c4bR93-R102. But it is already two years old. |
I might be able to revisit this with the upstream changes to injections |
Workaround is implemented via #73. The underlying issue remains, but the most common use cases should be fixed. |
@lang
from@code
to allow for language-specific queries, where the type of query already defineslang
and doesn't return it https://github.com/jmbuhr/otter.nvim/blob/5bfc1f5ab9cd19647dc7a919694fab7c1cfe0ccb/lua/otter/tools/queries.luaThe text was updated successfully, but these errors were encountered: