You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: Ignore the use statement when looking for class references #831
Another proposal about the find references action.
When we are searching the references to a class the result includes all the use statements declaring the object we are looking for.
I find it annoying since it pollute the result list and make it harder to get a quick filling about how many references there is.
Plus we don't really care about those statements, they are a syntactic sugar so we don't have to use FQCN all other our code.
Am I the only one with this feeling ?
Would it make sense for others to filter the use statement in order to not show them ?
@dantleech Will it break anything if we filter them ?
Like a refactoring tool we will use this feature to find out every occurrence to replace when renaming a class/interface ?
If so, should we create another finder to look for implementations instead of references and change the context menu action ?
Reacted by Bruce Weirdan, Yann Rabiller and Baptiste Clavié
Filtering in class-mover would break
things, as that is used for replacing references.
That library was built initially only for moving classes (it was the first
functionality in Phpactor) and has subsequently been hijacked for finding and
replacing references. It should be renamed and refactored at some point, but
for this problem I can suggest:
We replace the property $isClassDeclaration with an enum $type
It makes sense, I will try to look into it if I can make time.
I don't think it's a great priority right now, first of all we can still filter the use statement with fzf (once #832 will be merged) by typing !use.
Secondly I'm not sure it will really be what we want right there.
I was thinking about it and I think my main use case is to find implementations instead of references.
What I mean is that I don't only want the classes/interfaces that directly implements an interface (for example).
But all classes/interfaces that are instanceof a given interface.
I find it really useful, especially with inversion of dependencies, we inject a lot of object by type hinting against interfaces and it's quite handy to be able to quickly find all possible object that can be injected.
So it might me a totally new "finder" like FindImplementation we might even extends that to methods in order to find all classes that implements an interface's method.
Especially useful since when you try to goto a method on an object that was injected threw an interface phpactor opens the file of the interface.
Tell me what you think about all that and if you would prefer a different ticket for that, it you feel it's legitimate.
In my opinion if searching for class references uses should be returned as well. If really required it would be better to have separate finders for the different use cases.
Yes, it should be configurable - or we can remove it... I think originally it was in mind to use it when replacing references etc, but the current logic doesn't use that info anyway (it just needs the list of files that reference the class)
Well, the question is "is it useful". A orphaned use statement is doing no harm, and CS fixers take care of this sort of thing. It would slightly reduce the index size. So I'd certainly consider it. Making it optional would be a bit involved (although making it a configuration option would be easy, but again, who would turn it on?)
Activity
dantleech commentedon Oct 22, 2019
Filtering in class-mover would break
things, as that is used for replacing references.
That library was built initially only for moving classes (it was the first
functionality in Phpactor) and has subsequently been hijacked for finding and
replacing references. It should be renamed and refactored at some point, but
for this problem I can suggest:
$isClassDeclarationwith an enum$typeisClassImportStatementhere(I guess it can be enabled by default).
camilledejoye commentedon Oct 23, 2019
It makes sense, I will try to look into it if I can make time.
I don't think it's a great priority right now, first of all we can still filter the use statement with fzf (once #832 will be merged) by typing
!use.Secondly I'm not sure it will really be what we want right there.
I was thinking about it and I think my main use case is to find implementations instead of references.
What I mean is that I don't only want the classes/interfaces that directly implements an interface (for example).
But all classes/interfaces that are
instanceofa given interface.I find it really useful, especially with inversion of dependencies, we inject a lot of object by type hinting against interfaces and it's quite handy to be able to quickly find all possible object that can be injected.
So it might me a totally new "finder" like
FindImplementationwe might even extends that to methods in order to find all classes that implements an interface's method.Especially useful since when you try to goto a method on an object that was injected threw an interface phpactor opens the file of the interface.
Tell me what you think about all that and if you would prefer a different ticket for that, it you feel it's legitimate.
weeman1337 commentedon Apr 22, 2021
In my opinion if searching for class references uses should be returned as well. If really required it would be better to have separate finders for the different use cases.
dantleech commentedon Apr 22, 2021
Yes, it should be configurable - or we can remove it... I think originally it was in mind to use it when replacing references etc, but the current logic doesn't use that info anyway (it just needs the list of files that reference the class)
weeman1337 commentedon Apr 22, 2021
Maybe not just removing it. :/
So @camilledejoye issue is that he has too many matches. I am also interested in finding "only uses".
I investigated how others™ do that:
usefor that fileusein the resultsThat could be a smart way to make everyone happy :)
dantleech commentedon Apr 22, 2021
Well, the question is "is it useful". A orphaned use statement is doing no harm, and CS fixers take care of this sort of thing. It would slightly reduce the index size. So I'd certainly consider it. Making it optional would be a bit involved (although making it a configuration option would be easy, but again, who would turn it on?)
dantleech commentedon Apr 22, 2021
Actually, this is currently the case with the language server - use statements are not included.
The original issue relates only to the legacy implementation, so I think this can be closed.