I'm using the VSCode extension. For the same reason that using Go To Definition to go to the definition of a method being called is useful and desirable, it would also be nice if there was a way to use this feature for going to the constructor being called.
Static Example
class A {
public function __construct() {
}
}
class B extends A {
public static function make(): static {
return new static();
}
}
In this case, Go To Defition on the static in the context of it being constructed (when new is in front of it) should take you to that the constructor being called, which in this case is the constructor from class A. Especially when the user doesn't know where the constructor is defined, if the tool can take them right there, that could be quite helpful. Technically you don't really know which constructor it is calling because something else could extend B and have its own constructor, but I think it's better for it to take you somewhere than nowhere.
Self Example
class A {
public function __construct() {
}
}
class B extends A {
public static function make(): self {
return new self();
}
}
This is the same as the previous example except it uses the self keyword instead of static. Since the constructor for B is defined in Class A, it should still take you to that constructor.
Hard Coded Class Name Example
class A {
public function __construct() {
}
}
class B extends A {
public static function make(): B {
return new B();
}
}
This is the same as the previous example except it uses the B instead of self. In this case, the effect is the same since the constructor for B is defined in Class A.
That is how I would prefer it to work, but if you want B to continue to take them to the definition of class B instead of the constructor, you could perhaps allow using Go To Definition on the keyword new to get to the constructor, as that currently doesn't seem to be used for anything.
I'm using the VSCode extension. For the same reason that using Go To Definition to go to the definition of a method being called is useful and desirable, it would also be nice if there was a way to use this feature for going to the constructor being called.
Static Example
In this case, Go To Defition on the
staticin the context of it being constructed (whennewis in front of it) should take you to that the constructor being called, which in this case is the constructor from class A. Especially when the user doesn't know where the constructor is defined, if the tool can take them right there, that could be quite helpful. Technically you don't really know which constructor it is calling because something else could extend B and have its own constructor, but I think it's better for it to take you somewhere than nowhere.Self Example
This is the same as the previous example except it uses the
selfkeyword instead ofstatic. Since the constructor for B is defined in Class A, it should still take you to that constructor.Hard Coded Class Name Example
This is the same as the previous example except it uses the
Binstead ofself. In this case, the effect is the same since the constructor for B is defined in Class A.That is how I would prefer it to work, but if you want B to continue to take them to the definition of class B instead of the constructor, you could perhaps allow using Go To Definition on the keyword
newto get to the constructor, as that currently doesn't seem to be used for anything.