bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.63k stars 94 forks source link

How to deprecate property or method in class tags? #1822

Open dmitrach opened 3 years ago

dmitrach commented 3 years ago

Feature description or problem with existing feature I would like to deprecate properties and methods in class descriptions. Now it works only for real properties and methods.

/**
 * @property int $deprecatedProperty A depreccated property. @deprected @deprecated v1.19
 * @property-read Type[] $deprecatedProperties Returns deprecated object. @deprecated v1.19
 * @method static Builder deprecated(bool $state = true) Deprecated method. @deprecated v1.19
 */
class MyClass extends ParentClass
{
}

Describe the solution you'd like I would like to see behavior same as real deprecated properties and methods.

Thank you.

tianyiw2013 commented 3 years ago

Through phpdoc seems unable to achieve.

You can create a ide helper file, such as .idehelper.deprecated.php

// Save to `.idehelper.deprecated.php`
/**
 * ide-helper for deprecated
 */
class MyClass
{
    /**
     * Deprecated property.
     * 
     * @deprecated v1.19
     */
    public int $property;

    /**
     * Deprecated method
     * 
     * @deprecated v1.19
     */
    function method()
    {
    }
}
tianyiw2013 commented 3 years ago

Or append at the end of the class file.


class MyClass
{
    // ....
}

if( false ){
    /**
     * ide-helper for deprecated
     */
    class MyClass
    {
        /**
         * Deprecated property.
         * 
         * @deprecated v1.19
         */
        public int $property;

        /**
         * Deprecated method
         * 
         * @deprecated v1.19
         */
        function method()
        {
        }
    }

}
dmitrach commented 3 years ago

@tianyiw2013 Thanks. The first way works for me.

But both ways are disallowed to commit. In the first case I can ignore the helper. But I haven't tools to auto generate it like as _ide_helper.php. Do you know anything? It is a small problem.

More important problem is go to the definition. Now I find all references and both classes. I've added *ide*helper*.php to the config of the extension but it doesn't ignore this class in the result.

"intelephense.references.exclude": [
  "**/vendor/**",
  "*ide*helper*.php"
]

.idehelper.deprecated.php also doesn't the result.

Do you know a resolve of this problem?

KapitanOczywisty commented 2 years ago

The best solution is to put deprecations into .phpstorm.meta.php file, it has special treatment. There will be still duplicated definitions, but the original one will be used first for go to definition.

You can also include file from outside of workspace using intelephense.environment.includePaths.

mikkorantalainen commented 1 year ago

I would like to deprecate properties and methods in class descriptions. Now it works only for real properties and methods.

I personally think that if you have already removed the property or method, it's no longer deprecated but simply not supported at all.

As such, @deprecated status should be used only for properties and methods that still work but will be broken in the future.