Skip to content

Regex literal # marker font-lock override not taking effect #135

Description

@bbatsov

The regex font-lock feature defines a rule to highlight the # marker in regex literals (#"pattern") with font-lock-property-face, using :override t to override the string feature's font-lock-regexp-face that covers the entire regex_lit node. However, the override doesn't take effect -- the # gets font-lock-regexp-face like the rest of the literal.

The query itself is correct (manually running it against the tree returns the right node), so this appears to be a tree-sitter font-lock engine issue with overriding a parent-node capture from a child-node capture in a later rule.

Options:

  1. Remove the regex marker rule and let the whole #"pattern" be font-lock-regexp-face. The # is part of the regex syntax, so this is reasonable.
  2. Change the string rule to capture regex parts individually (marker, open, content, close) instead of the whole regex_lit node, avoiding the override issue entirely.
  3. Use a different face if we fix the override. font-lock-property-face is an odd choice for a reader dispatch character -- font-lock-delimiter-face would be more consistent with how #' and quote markers are handled.

I'm leaning towards option 1. Came across this while backfilling font-lock tests -- opening this so I don't forget to fix it eventually.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions