Skip to content
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

fix: empty metadata caused treesitter directives like offset to be ignored #80

Merged
merged 2 commits into from
Jan 15, 2024
Merged

fix: empty metadata caused treesitter directives like offset to be ignored #80

merged 2 commits into from
Jan 15, 2024

Commits on Jan 12, 2024

  1. fix: empty metadata caused treesitter directives like offset to be ig…

    …nored
    
    this commit fixes the vim.treesitter.get_node_text from ignoring the
    offset and possibly other directives like gsub as well.
    
    the reason for this change is that metadata in query:iter_captures was
    only available if the capture_id is 1 and was reset to an empty table
    for the captures after that but wasn't replenished and remained empty.
    
    assume that you have a treesitter injection in a rust macro. here's what
    it would look like
    
    (macro_invocation
     (scoped_identifier
        path: (identifier) @path (#eq? @path "sqlx")
        name: (identifier) @name (#match? @name "^query.*")
     )
    
     (token_tree
        (raw_string_literal) @injection.content
        (#set! injection.language "sql")
        (#set! injection.include-children)
     )
     (#offset! @injection.content 0 3 0 -2)
    )
    
    a raw string in rust looks like this r#"select * from "user";"#
    
    in the #offset! directive raw string start and end identifiers
    (#r" and "#) are offsetted and what remains is the inner sql.
    
    this offset information is set to the metadata for query.get_node_text
    to use.
    
    however, it's not available when it needs to be used.
    in query:iter_captures you get @path capture first then you get @name
    capture and finally @injection.content capture. metadata is only
    available in @path capture. which is when the capture_id is 1
    
    this commit sets this to an outside variable and makes it always available.
    
    maybe treesitter needs to fix this as a bug. I don't know honestly.
    rollincuberawhide committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    c8bcaf7 View commit details
    Browse the repository at this point in the history

Commits on Jan 13, 2024

  1. Configuration menu
    Copy the full SHA
    e3fc9d3 View commit details
    Browse the repository at this point in the history