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

Rainbow tree-sitter matches 🌈 #2857

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Commits on Jan 11, 2024

  1. Parse rainbow style array in themes

    This change adds a field to the schema of themes which takes a
    list of styles.
    
        rainbow = ["red", "orange", "yellow", { modifiers = ["reversed"] }]
        [palette]
        red = "#ff0000"
        orange = "#ffa500"
        yellow = "#fff000"
    
    Normal style rules apply for each element in `rainbows`: you can
    use definitions from the palette and the full fg/bg/modifiers
    notation.
    
    Themes written with `rainbow` keys are not backwards compatible.
    Parsing errors will be generated for older versions of Helix
    attempting to use themes with `rainbow` keys.
    
    A default rainbow is provided with base16 colors.
    
    This change is made with rainbow pair characters (parens, brackets, etc.)
    in mind but it could also be used for other rainbow cosmetic elements
    like rainbow indent-guides.
    the-mikedavis committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    a2760bf View commit details
    Browse the repository at this point in the history
  2. Add rainbow_brackets configuration option

    This option is similar to the `rulers` config: it can be set no the
    editor key in config and also overridden for specific languages, so
    you could enable rainbow brackets for lisps for example without
    enabling it globally.
    the-mikedavis committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    dae731a View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d5bfab7 View commit details
    Browse the repository at this point in the history
  4. Add a generic iterator over captures across injections

    This can be used to calculate rainbow highlights (see the child commit)
    or indents or textobjects and be accurate to the injected content
    rather than just the root layer. This is useful for languages which
    use injections heavily like Vue or JavaScript within HTML but are also
    useful in common scenarios like within codeblocks in Markdown.
    
    This iterator shares some code with the HighlightIter and
    HighlightIterLayer but that iterator emits HighlightEvents, so it cares
    about the beginnings and ends of highlight events rather than captures.
    the-mikedavis committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    04c7304 View commit details
    Browse the repository at this point in the history
  5. Calculate rainbow highlights spans

    This is an example usage of the query_iter introduced in the parent
    commit: captures are returned in order across language layers. We
    can use this iterator and a stack for the rainbow scopes to calculate
    highlight spans that can be merged into the syntax highlights using
    syntax::merge.
    the-mikedavis committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    8e3d43d View commit details
    Browse the repository at this point in the history
  6. Overlay rainbow highlights onto syntax highlights

    We call the rainbow_spans function introduced in the parent commits
    over the largest node that contains the current viewport: we need to
    reach far enough back in the document that we find the absolute
    beginning for brackets. If we run rainbow_spans only over the current
    viewport, we get a bug where the color of rainbow brackets changes as
    we move the viewport.
    the-mikedavis committed Jan 11, 2024
    Configuration menu
    Copy the full SHA
    26625d1 View commit details
    Browse the repository at this point in the history

Commits on Jan 12, 2024

  1. Add rainbows.scm queries

    Co-authored-by: SoraTenshi <dream@neoncity.dev>
    the-mikedavis and SoraTenshi committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    b6669ad View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0978b47 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    93b7190 View commit details
    Browse the repository at this point in the history
  4. Share sort_key function between query iterators

    This is brings the fix from d5f17d3 to the QueryIter layers. A trait
    for getting the cursor and sort-key from each layer helps cut down on
    code duplicated between these iterators.
    the-mikedavis committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    75f4f4a View commit details
    Browse the repository at this point in the history
  5. Share sort_layers function between query iterators

    The code in the `sort_layers` function was fully duplicated between
    the HighlightIter and the QueryIter. This change adds a common
    `sort_layers` function that accepts a layer Vec from both.
    the-mikedavis committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    410a2b2 View commit details
    Browse the repository at this point in the history
  6. Use a helper function for creating query captures

    This deduplicates some somewhat complex code between the highlight_iter
    and query_iter.
    the-mikedavis committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    ca4417c View commit details
    Browse the repository at this point in the history
  7. Mark query_captures function as unsafe

    It's easy to mistakenly use-after-free the cursor and captures iterator
    here because of the transmute. Ideally this could be fixed upstream in
    tree-sitter by introducing an API with lifetimes/types that reflect the
    lifetimes of the underlying data.
    
    Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
    the-mikedavis and pascalkuthe committed Jan 12, 2024
    Configuration menu
    Copy the full SHA
    35d707d View commit details
    Browse the repository at this point in the history