Giter VIP home page Giter VIP logo

Comments (8)

wookayin avatar wookayin commented on September 26, 2024

Thanks for the detailed report. I think this is a duplicate of #4179, basically the same root cause causing the issue. What do you think?

from nvim-treesitter.

WilsonOh avatar WilsonOh commented on September 26, 2024

Thanks for the detailed report. I think this is a duplicate of #4179, basically the same root cause causing the issue. What do you think?

Thank you for the reply. The issue seems to be different as the @_comment and @injection.content captures point to the same node, so even if the #set! directive only applies to the first capture the result should still be the same.

I've tried to modify the query to use only one capture like so:

; extends

((comment) @injection.content
            (#contains? @injection.content "@swagger")
            (#set! injection.language "yaml")
            (#offset! @injection.content 2 3 0 0))

but I still get the same result where only the first line of yaml being highlighted.

from nvim-treesitter.

lucario387 avatar lucario387 commented on September 26, 2024

Testing the code below inside a yaml file

@swagger
test: [foo, 2]
another: one

and yaml parser doesn't return anything

Pressing :Inspect under any character doesn't return anything, meaning the parser is very restrictive on what's right and wrong

from nvim-treesitter.

WilsonOh avatar WilsonOh commented on September 26, 2024

Testing the code below inside a yaml file

@swagger
test: [foo, 2]
another: one

and yaml parser doesn't return anything

Pressing :Inspect under any character doesn't return anything, meaning the parser is very restrictive on what's right and wrong

You're right, that's why I tried to "extract out" the valid yaml from the jsdoc comment with the #offset! directive. I expected the offset of 2 3 0 0 to skip the first two lines containing

/**
 * @swagger

as well as the * characters at the start of each line.

What's confusing is that the yaml parser seems to only recognize the first line of yaml as seen here:

image

My understanding of how the #offset! directive works could be wrong though.

from nvim-treesitter.

lucario387 avatar lucario387 commented on September 26, 2024

My understanding of how the #offset! directive works could be wrong though.

It's wrong, indeed.
#offset! only moves the start and end position

So with a code of

/**
 * @swagger
 * test: ["foo", 2]
 * another: one
 */

and an offset of 2 3 0 0
You will have a yaml tree of

test: ["foo", 2]
 * another: one
 */

from nvim-treesitter.

WilsonOh avatar WilsonOh commented on September 26, 2024

and an offset of 2 3 0 0
You will have a yaml tree of

test: ["foo", 2]
 * another: one
 */

I see! In hindsight I don't know why I expected the column offset to be applied to every line...
Do you happen to know of a way to apply an offset to every line of the capture?
Or is it possible to programmatically perform injections to a custom set of ranges through the lua API?

from nvim-treesitter.

lucario387 avatar lucario387 commented on September 26, 2024

Nope, I don't know any reasonable way for that

If anything, it's best to bring the problem to upstream to ask.

Edit: Upstream here being Neovim

from nvim-treesitter.

WilsonOh avatar WilsonOh commented on September 26, 2024

Nope, I don't know any reasonable way for that

If anything, it's best to bring the problem to upstream to ask.

Edit: Upstream here being Neovim

I see, thank you!

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.