Coder Social home page Coder Social logo

Comments (11)

hworld avatar hworld commented on May 18, 2024 1

There is support for this in phpdoc. It's called @method. Documentation: https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#711-method

Looks like intelephense already supports it and works fine.

Would look like this:

/**
 * @method string getString()
 * @method void setInteger(int $integer)
 * @method setString(int $integer)
 */
class Child
{
    <...>
}

from vscode-intelephense.

TheColorRed avatar TheColorRed commented on May 18, 2024

That somewhat works, maybe I am doing it wrong, but it doesn't go to the function, just where the comment is. Is there a way to use it so it goes to the method?

/**
 * @method void DefaultSelect()
 */
class GameCache extends BaseGameModel{
    public function scopeDefaultSelect($query, $filters){
		// Do stuff
	}
}

from vscode-intelephense.

hworld avatar hworld commented on May 18, 2024

Oh, I see. So in the __call you end up funneling it to the scopeDefaultSelect (as an example)? Yeah, I don't think that phpdoc allows you to mark that at least...

from vscode-intelephense.

TheColorRed avatar TheColorRed commented on May 18, 2024

Yeah, that is a Laravel feature for doing database queries:
https://laravel.com/docs/5.5/eloquent#local-scopes

Other frameworks may do something differently

from vscode-intelephense.

artrz avatar artrz commented on May 18, 2024

I don't think this could be really helpful as code should not depend on an editor. Adding random (and non-sense for others) phpdoc tags will 'couple' the code to one editor plugin, not even an editor, but a plugin feature, ending on dirty code. I'm in a project where some people use Atom, others Sublime or even PhpStorm. I see no reason to have code with custom stuff so each ones editor works, and I cannot imagine my self tagging a scope with @called for me, tagging whatever method with @forwarded so it works on some random Atom plugin and @scopedMethod for my mate using a Sublime plugin. However, suggesting this tag to the phpDoc team may be helpful, some kind of mix between @method and @see

from vscode-intelephense.

TheColorRed avatar TheColorRed commented on May 18, 2024

I did submit something after. No reply yet though

from vscode-intelephense.

artrz avatar artrz commented on May 18, 2024

I did submit something after.

Cheers mate!

I'd love to have this feature supported on phpDoc blocks

from vscode-intelephense.

bmewburn avatar bmewburn commented on May 18, 2024

Good discussion, I don't think introducing a new phpdoc tag is appropriate, I'd rather stick with current standards. @arturock mentions @see. I wonder if this would be suitable in itself. Document _call with @see tags and then go to definition can provide multiple locations. It wouldn't distinguish between scopeMethodA and scopeMethodB but would at least provide useful information to the user to make a decision rather than just going to the @method in the class docblock.

from vscode-intelephense.

bmewburn avatar bmewburn commented on May 18, 2024

I think the way to go here would be to use inline @see in the @method description.

/**
 * @method void DefaultSelect() {@see GameCache::scopeDefaultSelect}
 */
class GameCache extends BaseGameModel{
    public function scopeDefaultSelect($query, $filters){
		// Do stuff
	}
}

from vscode-intelephense.

scott-davidjones avatar scott-davidjones commented on May 18, 2024

would this also work with, as an example, laravel facades:
https://github.com/laravel/framework/blob/5.5/src/Illuminate/Support/Facades/DB.php

the @see directive is class level and not method level. Currently when using a facade no intellisense is provided.

from vscode-intelephense.

dmitrach avatar dmitrach commented on May 18, 2024

A part of the implementation works with "barryvdh/laravel-ide-helper".
It generates descriptions for classes like as @method void DefaultSelect() {@see GameCache::scopeDefaultSelect}.
But it doesn't work to go to the definitionm only to the class definition. Also it needs to duplicate a description of the method.

The @called tag doesn't work with other editors. May be better to use known cases.

Laravel works with scopes as static and class methods: MyModel::myScope($var). But @called and :alias: don't change a type of the method.

I could be implemented with :alias: as @see number_of() :alias: to except duplicated descriptions.
https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc-tags.md#512-see

In the other case it could be implemented with the class definition and jump to the original definition (optional) though the description with ClassName::method() :alias: or @see ClassName::method() or @uses ClassName::method() (they can have priorities). Also for class properties: @see self::$variable, @uses self::$variable.

/**
 * @method static SomeType someMethod() My description. @uses ClassName::originalMethod()
 * @method void someMethod2() My description. @see ClassName::originalMethod2()
 * @property mixed $someProperty My description. @uses self::getProperty()
 * @property mixed $someProperty2 My description. @see self::$originalProperty @see http://somedescription.com 
 */
class ClassName
{
    protected $originalProperty;

    public function originalMethod(): SomeType
    {
        // 
    }
    
   public function originalMethod2(): void
    {
        // 
    }

   public function getProperty()
   {
       return someChanges($this->originalProperty);
   }

    /**
     * @see self::getName() :alias:
     */
    public function getTitle(): string
    {
        return $this->getName();
    }

    /**
     * Returns a name.
     */
    public function getName(): string
    {
        return $this->name;
    }
}

from vscode-intelephense.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.