Skip to content

Conversation

@alfredomtx
Copy link

@alfredomtx alfredomtx commented Jan 13, 2026

Summary

Adds syntax highlighting for PHP 8+ named arguments in function/method calls.

Named arguments like id:, firstName:, lastName: in:

$this->users->map(fn (User $user) => new UserDTO(
    id: $user->id,
    firstName: $user->first_name,
    lastName: $user->last_name,
));

Are now highlighted with the @label token, which themes can style distinctly (e.g., JetBrains IDEs use a muted blue for these).

Implementation

Added a simple tree-sitter query that captures the name field of argument nodes:

(argument
  name: (name) @label)

The tree-sitter-php grammar already exposes the name field on argument nodes for named arguments, so no grammar changes are needed.

Test plan

  • Tested locally with zed: install dev extension
  • Named arguments now highlight correctly in PHP files

@cla-bot cla-bot bot added the cla-signed label Jan 13, 2026
@MrSubidubi MrSubidubi changed the title Add syntax highlighting for named arguments (PHP 8+) Add syntax highlighting for named arguments Jan 17, 2026
Copy link
Contributor

@MrSubidubi MrSubidubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

Can you quickly elaborate why this shoud be highlighted as label? From an initial view, this seems unintuitive to me, but I might be lacking context here. Thanks!

@alfredomtx
Copy link
Author

Thanks for this!

Can you quickly elaborate why this shoud be highlighted as label? From an initial view, this seems unintuitive to me, but I might be lacking context here. Thanks!

Hello @MrSubidubi, you are welcome! And thanks for questioning this.

The ideal semantic token would be @variable.parameter (which nvim-treesitter uses for Python's keyword arguments), but Zed's theme system doesn't support that capture. Of the supported captures, @label is the closest fit because:

  1. Named arguments follow the name: syntax pattern similar to labels
  2. It's already used for regex group names in Zed (another form of named reference)
  3. Themes like One Dark style labels with a muted color, which matches how JetBrains IDEs(I come from PHPStorm) render named arguments

Alternatively, this could be an argument for Zed to support @variable.parameter as a capture.

Source: https://zed.dev/docs/extensions/languages#syntax-highlighting

The documentation provides a comprehensive list of captures supported by themes, and the only variable-related captures listed are:

  • @variable
  • @variable.special

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.

2 participants