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

Syntax-highlight regex prompts #7738

Merged
merged 4 commits into from
Jul 27, 2023
Merged

Syntax-highlight regex prompts #7738

merged 4 commits into from
Jul 27, 2023

Commits on Jul 25, 2023

  1. Syntax-highlight regex prompts

    We can use tree-sitter-regex highlighting in prompts for entering
    regexes, like `search` or `global_search`. The `highlighted_code_block`
    function from the markdown component makes this a very small change.
    
    This could be improved in the future by leaving the parsed syntax tree
    on the prompt, allowing incremental updates. Prompt lines are usually so
    short though and tree-sitter-regex is rather small and uncomplicated,
    so that improvement probably wouldn't make a big difference.
    the-mikedavis committed Jul 25, 2023
    Configuration menu
    Copy the full SHA
    1f2471f View commit details
    Browse the repository at this point in the history

Commits on Jul 26, 2023

  1. Tune regex highlights for usage in prompts

    Since regex is almost always injected into other languages,
    `pattern_character`s will inherit the highlight for the structure that
    injects them (for example `/foo/` in JavaScript or `~r/foo/` in Elixir).
    This removes the string highlight when used in the prompt.
    
    We also add `ERROR` node highlighting so that errors in regex syntax
    appear in the prompt. This resolves a TODO in the `regex_prompt`
    function about highlighting errors in the regex.
    the-mikedavis committed Jul 26, 2023
    Configuration menu
    Copy the full SHA
    869a17d View commit details
    Browse the repository at this point in the history
  2. Prefer RopeSlice to &Rope in helix_core::syntax

    Pascal and I discussed this and we think it's generally better to
    take a 'RopeSlice' rather than a '&Rope'. The code block rendering
    function in the markdown component module is a good example for how
    this can be useful: we can remove an allocation of a rope and instead
    directly turn a '&str' into a 'RopeSlice' which is very cheap.
    
    A change to prefer 'RopeSlice' to '&Rope' whenever the rope isn't
    modified would be nice, but it would be a very large diff (around 500+
    500-). Starting off with just the syntax functions seems like a nice
    middle-ground, and we can remove a Rope allocation because of it.
    
    Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
    the-mikedavis and pascalkuthe committed Jul 26, 2023
    Configuration menu
    Copy the full SHA
    b533be9 View commit details
    Browse the repository at this point in the history
  3. highlighted_code_block: Take input text as &str

    This removes a handful of allocations for functions calling into the
    function, which is nice because the prompt may call this function on
    every keypress.
    the-mikedavis committed Jul 26, 2023
    Configuration menu
    Copy the full SHA
    ef47075 View commit details
    Browse the repository at this point in the history