Comments (11)
If it's vim.treesitter.get_node()
then it ignores the injected language and just returns <node string_content>
instead of the RST's <node paragraph>
. Unless you mean some other function that returns the node at the cursor position.
Edit: Oh nvm, there's an option that is set to ignore_injections = true
from nvim-treesitter.
I meet the same problem. I don’t know how to solve it. Could you please tell me how to (not convenientlly) get parent node of injection node? Thank you!
from nvim-treesitter.
These tools are deprecated; use Neovim's built-in API. If you still run into problems, please open an issue there.
from nvim-treesitter.
Here's some more calls
:lua print(vim.treesitter.get_node({pos={4,0}, lang="rst", ignore_injections=false}):parent():parent():parent():parent():parent():parent())
Returns nil
in the same spot
:lua vim.treesitter.get_node({pos={4, 0}, lang="python", ignore_injections=false})
returns <node string_content>
, not the intended injection language.
It looks to not be possible to grab from the injected language and call parent() to reach out to the outer language. I'm new to this API so I could be using it wrong but it seems to me that this issue's listed bug still applies.
from nvim-treesitter.
(4, 0) can be the position of the parent node
from nvim-treesitter.
I thought the docs said it's zero-indexed so I subtracted one from the 5th line. Anyway let's just do 5G
and remove pos
to rely on just the current cursor position.
:lua print(vim.treesitter.get_node({lang="rst", ignore_injections=false}):parent():parent():parent():parent():parent():parent( ):parent():parent())
It's still nil
in this case as well
from nvim-treesitter.
In any case, this is not an nvim-treesitter issue (and, since parent()
are tree-sitter API calls, not a Neovim issue).
from nvim-treesitter.
Fair, Neovim is simply calling ts_node_parent
in its implementation it seems. I'll take it up with tree-sitter. Thank you!
from nvim-treesitter.
You may also be misunderstanding how the language tree works: it's not a single tree, but a tree of trees. So you cannot simply walk up and "out of" a child tree into the parent one. So this is actually working as intended; you'll have to implement your functionality (whatever it is) some other way.
from nvim-treesitter.
If it's tree of trees then that wouldn't surprise me that parent() doesn't keep reaching to outer trees. However I think you can also agree that users of tree-sitter who use injections might want to be able to repeatedly call parent()
and not have to worry "am I at the boundary of another parser?" and having to do extra manual checks to make that work when handling injected languages.
In practice though, I'll probably just end up changing my code not to have to rely on parent() at all. But the convenience of it would be nice. That's for tree-sitter's maintainers to weigh in on, of course.
from nvim-treesitter.
However I think you can also agree that users of tree-sitter who use injections might want to be able to repeatedly call parent() and not have to worry "am I at the boundary of another parser?" and having to do extra manual checks to make that work when handling injected languages.
I think that would be a wrong expectation from this API. Whether there should be a higher-level convenience API in Neovim that abstracts from this depends on how strong the use case is -- convenience alone is not enough to justify adding, documenting, and maintaining a new API. We consider treesitter an advanced topic, so familiarity and some work on the side of plugin authors is expected.
from nvim-treesitter.
Related Issues (20)
- Python indentation not working properly HOT 2
- bash regex editing hangs neovim HOT 1
- Selecting inside / within a node HOT 2
- nvim +PlugUpdate does not update treesitter (results in errors) HOT 4
- C23 auto keyword highlighted as keyword.modifier not as type HOT 4
- Python: Current line dedented while typing slice (`:`) HOT 1
- TS Parser PHP errors with Invalid node type "anonymous_function_creation_expression" HOT 5
- Error in php files HOT 1
- Indentation module breaks auto indent in JS files HOT 2
- Cant Install Latex HOT 1
- Brewfile support HOT 1
- bug: [python] [indent] conditional return prematurely de-indents
- Vimdoc: concealed characters not hidden, replaced by box-drawing characters HOT 13
- multiple dollar signs in a line in a markdown file makes tree-sitter crash HOT 2
- Impossible pattern "~" @markup.heading.4 HOT 2
- Incorrect indenting using `ts=8:sw=3:noet` with old C codebase
- nvim-treesitter[cpp]: Failed to execute the following command: HOT 3
- Error in decoration provider treesitter/highlighter.line HOT 4
- TSEnable highlight html HOT 1
- I tried My very dear friend, i tried the solution in #3092 because I spent 2 hours on this problem. And it solved issue for ts. But not for html for some weird reason. HOT 1
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 nvim-treesitter.