Comments (7)
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.
https://github.com/neovim/neovim/blob/58618d208acd3827c4e86668529edb619bb9b8dd/runtime/lua/vim/treesitter/query.lua#L210 can get the query for all injections and I believe this includes user-defined ones.
(Or rather the cached version: https://github.com/nvim-treesitter/nvim-treesitter/blob/23dfae4db84f71e2ddb56c024845b322035182ee/lua/nvim-treesitter/query.lua#LL106C1-L106C1 , which should also make it faster!)
And from this we should be able to get those captures:
https://github.com/neovim/neovim/blob/58618d208acd3827c4e86668529edb619bb9b8dd/runtime/doc/treesitter.txt#L484-L505
from otter.nvim.
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:
(call_expression
(member_expression
object: (identifier) @_object (#eq? @_object "knex")
property: (property_identifier) @_property (#eq? @_property "raw")
)
(arguments
(template_string) @sql
(#offset! @sql 0 1 0 -1)
)
)
from otter.nvim.
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.
from otter.nvim.
Looks like the offset
directive only affects the range
reported by the nodes metadata, not the text returned by get_node_text
as currently used (
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?
from otter.nvim.
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.
from otter.nvim.
I might be able to revisit this with the upstream changes to injections
from otter.nvim.
Workaround is implemented via #73. The underlying issue remains, but the most common use cases should be fixed.
from otter.nvim.
Related Issues (20)
- [bug]ask format eat some additional lines HOT 2
- Deprecated `vim.lsp.get_active_clients`
- attempt to call method '_rawquery' (a nil value) HOT 1
- Handle buffers without active raft more gracefully or provide a way to check whether a raft is registered HOT 3
- Installing quarto in Noevim produces multiple errors. HOT 5
- Rename doesn't work with dressing.nvim HOT 4
- Formatting Issues Using 'otter'.ask_format() in python HOT 6
- use Text Document Synchronization
- Broken syntax highlighting HOT 3
- Noice Issues After updating Otter.NVIM HOT 4
- feat: use lsp request params to determine position for language context
- fix: make completion more robust about restarting lsp servers
- pyright in otter buffer doesn't update when otter was activated from markdown main document HOT 15
- failed to run config for otter.nvim HOT 2
- Question/Help HOT 2
- bug: handle_leading_whitespace seems to delete all whitespace (?) HOT 12
- Add to mason? HOT 2
- Opening a blank file produces "Error requesting document symbols" HOT 28
- verbose.no_code_found = false does not work when entering buffer from a directory. HOT 3
- rewrite `config` to be more robust with lazy loading
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from otter.nvim.