Skip to content

Proposal: Ignore the use statement when looking for class references #831

Closed

Description

@camilledejoye

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 ?

Activity

  1. dantleech commented on Oct 22, 2019

    @dantleech
    Collaborator

    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
    • Add a new method isClassImportStatement here
    • Filter in the find-references handler in Phpactor if a config flag is enabled
      (I guess it can be enabled by default).
  2. camilledejoye commented on Oct 23, 2019

    @camilledejoye
    ContributorAuthor

    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.

  3. weeman1337 commented on Apr 22, 2021

    @weeman1337
    Contributor

    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.

  4. dantleech commented on Apr 22, 2021

    @dantleech
    Collaborator

    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)

  5. weeman1337 commented on Apr 22, 2021

    @weeman1337
    Contributor

    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:

    • If a file contains any reference to the class → skipt the use for that file
    • If a file doesn't contain any reference fo the class → show the use in the results

    That could be a smart way to make everyone happy :)

  6. dantleech commented on Apr 22, 2021

    @dantleech
    Collaborator

    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?)

  7. dantleech commented on Apr 22, 2021

    @dantleech
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions