Skip to content

Highlight instance vars, method defs, and keyword params distinctly#298

Open
orthodoX wants to merge 1 commit into
zed-extensions:mainfrom
orthodoX:highlight-scopes
Open

Highlight instance vars, method defs, and keyword params distinctly#298
orthodoX wants to merge 1 commit into
zed-extensions:mainfrom
orthodoX:highlight-scopes

Conversation

@orthodoX

@orthodoX orthodoX commented Jun 24, 2026

Copy link
Copy Markdown

Why

Coming from VSCode/Cursor ecosystem, I really miss these semantic token modifiers:

Construct Current capture Shares its color with
Instance variables (@foo) @variable.special self, super, class variables
Method definitions (def foo) @function.method every method call
Keyword params (def m(foo:)) @variable.parameter positional parameters

These are exactly the distinctions many editors/themes expose (e.g. VS Code separates a method declaration from a method call via semantic token modifiers), but here the grammar collapses them, so the information needed to theme them is thrown away before it ever reaches the theme layer.

self, super, and class variables intentionally stay on @variable.special; method calls stay on @function.method; positional params stay on @variable.parameter.

Backwards compatibility

This PR is purely additive: existing themes are unaffected, and theme authors gain three new opt-in targets.

Consistency with existing conventions

The new names follow the dotted sub-scoping already used throughout this file.

How a theme author opts in

// theme_overrides (or a theme's syntax map)
"syntax": {
  "variable.special.instance":  { "color": "#..." }, // @foo distinct from self/super
  "function.method.definition": { "color": "#..." }, // def name distinct from calls
  "variable.parameter.keyword": { "color": "#..." }  // kwargs distinct from positional
}

Screenshots

Before

Screenshot 2026-06-23 at 23 50 06

After

Screenshot 2026-06-23 at 23 48 56

These three constructs are folded into broader shared captures, so themes
cannot color them independently:

- instance variables share `@variable.special` with `self`, `super`, and
  class variables
- method definitions share `@function.method` with method calls
- keyword parameters share `@variable.parameter` with positional parameters

Give each its own dotted sub-scope, following the sub-scoping convention
already used throughout this file (e.g. `function.method.builtin`,
`keyword.control.conditional`, `string.special.symbol`):

- (instance_variable)        -> @variable.special.instance
- method / singleton_method  -> @function.method.definition
- keyword_parameter          -> @variable.parameter.keyword

Fully backwards-compatible: Zed resolves highlight names by longest prefix,
so themes that only define `variable.special`, `function.method`, or
`variable.parameter` render these exactly as before. Themes can now opt in to
distinguishing them.
@cla-bot

cla-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @orthodoX on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@orthodoX

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Jun 24, 2026
@cla-bot

cla-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant