claytonrcarter / tree-sitter-phpdoc

PHPDoc grammar for tree-sitter
22 stars 10 forks source link

Support for docblock annotations #28

Closed sandermarechal closed 2 months ago

sandermarechal commented 8 months ago

Is it possible to add support for docblock annotations? For example:

<?php

use Symfony\Component\Routing\Annotation\Route;

class FooController
{
    /**
     * @Route("foo")
     */
    public function foo()
    {
    }
}

So, anything starting with @ that is followed by an imported or fully qualified classname should be highlighed. And parameters passed to that annotation as well, much like the standard PHP 8 attributes highlight.

Is that possible?

claytonrcarter commented 8 months ago

So, anything starting with @ that is followed by an imported or fully qualified classname

This usage is entirely new to me. I’d like to keep support focused on documented syntax (standard php doc) And commonly used extensions (phpstan/psalm/etc).

Can you tell me more about this usage, or point me to any documentation, tooling or more examples?

As I recall, it’s hard (maybe not possible?) to limit tags (eg @.***) only to dynamic types that have been imported (eguse Route`).

sandermarechal commented 8 months ago

This usage is called "PHP annotations" and is extremely common though it is slowly being phased out in new projects since PHP 8 has attributes now. Some examples:

There are many, many more. Almost all these depend on https://packagist.org/packages/doctrine/annotations as a generic annotations parser. As you can see on that page, over 2000 other packages depend (directly) on this one.

sandermarechal commented 8 months ago

The simple solution may be to simply highlight anything that has the format of @SomeString or @SomeString() (matching brackets). The Doctrine annotations parser will throw an exception for any @ tag that is not a known phpdoc/psalm/phpstan/phpunit tag and not a valid classname.

claytonrcarter commented 8 months ago

Gotcha. Thank you for the info and context. I don’t plan on implementing support for this myself, but I would merge a suitable PR that does.

claytonrcarter commented 2 months ago

I don’t plan on implementing support for this myself, but I would merge a suitable PR that does.

Closing for now, but this statement is still true! 😄