Giter VIP home page Giter VIP logo

Comments (11)

ColinKennedy avatar ColinKennedy commented on September 26, 2024 1

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.

dirichy avatar dirichy commented on September 26, 2024 1

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.

clason avatar clason commented on September 26, 2024

These tools are deprecated; use Neovim's built-in API. If you still run into problems, please open an issue there.

from nvim-treesitter.

ColinKennedy avatar ColinKennedy commented on September 26, 2024

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.

lucario387 avatar lucario387 commented on September 26, 2024

(4, 0) can be the position of the parent node

from nvim-treesitter.

ColinKennedy avatar ColinKennedy commented on September 26, 2024

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.

clason avatar clason commented on September 26, 2024

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.

ColinKennedy avatar ColinKennedy commented on September 26, 2024

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.

clason avatar clason commented on September 26, 2024

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.

ColinKennedy avatar ColinKennedy commented on September 26, 2024

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.

clason avatar clason commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.