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

php: Highlight PHPDoc comments #11695

Merged
merged 1 commit into from May 14, 2024

Conversation

claytonrcarter
Copy link
Contributor

@claytonrcarter claytonrcarter commented May 11, 2024

This adds highlighting of phpdoc tags and PHP types to phpdoc comments, using tree-sitter-phpdoc (maintained by yours me, and also in use by neovim).

Before After

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label May 11, 2024
@@ -1,3 +1,7 @@
((text) @content
(#set! "language" "html")
(#set! "combined"))

((comment) @content
(#match? @content "^/\\*\\*[^*]")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically, phpdoc comments must start with /**, so this prevents line comments and block comments that only start with /*, or "banner" comments like /***********/ from being highlighted.

@@ -0,0 +1,13 @@
(tag_name) @keyword
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +3 to +13
(tag (variable_name) @variable)
(variable_name "$" @operator)

(tag
(tag_name) @keyword
(#eq? @keyword "@method")
(name) @function.method)

(primitive_type) @type.builtin
(named_type (name) @type) @type
(named_type (qualified_name) @type) @type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of these were copied from the php highligts: https://github.com/zed-industries/zed/blob/main/extensions/php/languages/php/highlights.scm#L6-L9

The @method highlight was taken from neovim, and allows the highlighting of @method bool insufficient() to match that of function insufficient().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW the neovim highlight queries are at https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/phpdoc/highlights.scm. I don't know or use neovim, but I found that most of them were more specific than was needed just to get highlighting working (except for @method as mentioned above)

@claytonrcarter claytonrcarter marked this pull request as ready for review May 11, 2024 10:33
@maxdeviant maxdeviant changed the title PHP: highlight PHPDoc comments php: Highlight PHPDoc comments May 11, 2024
Copy link
Member

@maxdeviant maxdeviant left a comment

Choose a reason for hiding this comment

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

Thanks!

@maxdeviant maxdeviant merged commit 748cd38 into zed-industries:main May 14, 2024
9 checks passed
@maxdeviant maxdeviant mentioned this pull request May 14, 2024
maxdeviant added a commit that referenced this pull request May 14, 2024
This PR bumps the PHP extension to v0.0.3.

Changes:

- #11695

Release Notes:

- N/A
osiewicz pushed a commit to RemcoSmitsDev/zed that referenced this pull request May 18, 2024
This adds highlighting of phpdoc tags and PHP types to phpdoc comments,
using
[tree-sitter-phpdoc](https://github.com/claytonrcarter/tree-sitter-phpdoc)
(maintained by yours me, and also in use by neovim).

<table>
<tr>
<td>
<strong>Before</strong>
<img
src="https://github.com/zed-industries/zed/assets/1420419/bae4c502-8a2c-4399-893f-fcff4e5797b6">
</td>
<td>
<strong>After</strong>
<img
src="https://github.com/zed-industries/zed/assets/1420419/8848e9fb-61a0-4938-a118-7041da9589c0">
</td>
</tr>
</table>


Release Notes:

- N/A
osiewicz pushed a commit to RemcoSmitsDev/zed that referenced this pull request May 18, 2024
This PR bumps the PHP extension to v0.0.3.

Changes:

- zed-industries#11695

Release Notes:

- N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants