66

I am using IntelliJ IDEA 14 Ultimate. When I search find usages, in find view, there is an info like "Searching for usages in project files" and doesn't return any result. Scope is "whole project".

I have also IntelliJ 14 Community Edition. When it tries find usages in Community Edition, it works.

Do you have any idea?

Pang
  • 9,564
  • 146
  • 81
  • 122
karlkeller
  • 1,251
  • 3
  • 12
  • 22

10 Answers10

96

I had exactly the same problem, so for people looking for the quick answer, try

File -> Invalidate Caches / Restart

Thanks to user @yole and his comment.

Eel Lee
  • 3,513
  • 2
  • 31
  • 49
  • 2
    Worked for Intellij 16 – jbarrameda Sep 27 '16 at 15:26
  • 1
    Worked for Idea 13.0 in ubuntu – shakhawat Nov 27 '16 at 05:08
  • 2
    Worked for PHPStorm 2017.1 on MacOS Sierra – seven77 May 15 '17 at 23:17
  • Worked for IntelliJ 2017.2.1 – Brian Aug 15 '17 at 15:23
  • 1
    should be called "Invalid Caches & Delete Your Local History" if there was one feature I really wish IDEA would implement it would be to separate the two, I actually like my Local History - plus most times people suggest Invalidating Caches, it doesn't actually help so I lose my Local History for no reason - in this case it actually did help (I think I corrupted things by quitting IDEA after upgrade before it finished indexing) – ycomp Dec 05 '17 at 05:18
  • This solution is still working for IntelliJ Ultimate 2017.3 – Mathieu Castets Dec 05 '17 at 10:26
  • I'm not sure whether I should be more surprised that this works, or that this is necessary. Eclipse seems to be smart enough to find references reliably without making users "invalidate and restart", why can't Android Studio do it? – Krease May 01 '18 at 23:50
  • Worked for Pycharm! – Atul Mishra Apr 15 '21 at 08:32
  • Fixed the issue for PyCharm 2021.1. Have never seen that issue before, after working with PyCharm and IntelliJ for years. But invalidating cache fixes it. – Ursin Brunner Apr 18 '21 at 14:42
22

If it doesn't solve by File -> Invalidate Caches / Restart then make sure your 'src' folder is marked as 'Sources' in project structure.

Abhijeet Jadhav
  • 326
  • 3
  • 8
  • wow, If i open a project with "Open" i certainly would expect that that folder would be automatically searched. This worked for me. – darKoram Jun 11 '18 at 16:24
4

If File -> Invalidate Caches / Restart is not working -> close the project, remove it from recent projects and then delete the .idea folder then open the project again.

Mohankumar M
  • 101
  • 2
  • In my case mine was a gradle project and in addition to your steps I deleted the .gradle folder as well and then it worked. – rumman0786 Dec 10 '21 at 07:09
1

There are also other cases the "Find Usages" feature does not work. I can illustrate one very simple case.

Provider.java:

public class Provider {
    private static final Provider instance = new Provider();
    public static Provider getInstance() { return instance; }
    public Integer getID() { return 0; }
}

User.java:

public class User {
    private final Integer pID;
    public User() { pID = Provider.getInstance().getID(); }
}

If you click on the getID() method in Provider.java and call "Find Usages", it finds the call in the User.java easily. But if you rename or remove the getInstance() method in Provider.java, then it won't find the getID() call in User.java anymore.

I assume that it happens because the line Provider.getInstance().getID() is marked with red (compilation error) and the "Find Usages" feature does not consider this failing code as a valid call of getID(). It means that, at least some compilation errors affect the "Find Usages" results.

I was curious enough to look into the list of bugs related to this feature on https://youtrack.jetbrains.com/issues?q=find%20usages and there I saw there are other cases and made my conclusion. To sum up, if you don't like to keep in mind all the conditions in which it works and want always full search I recommend using grep which finds always and everything.

Pang
  • 9,564
  • 146
  • 81
  • 122
Alexander Samoylov
  • 2,358
  • 2
  • 25
  • 28
1

In PhpStorm version 2019.1 on a Windows machine, if you hold AltGr key and hover on a function, it appears the popup 'Show usage of Method ...' but it's misleading since doesn't find the calls to that method from other files.

The correct way to show usages, is to hold the Ctrl button and click on the method name.

T30
  • 11,422
  • 7
  • 53
  • 57
1

IntelliJ IDEA 2022.2.1

After Invalidate Caches/Restart did not work, what did fix the problem was Mark Directory As -> Unmark As Sources Root, followed by Mark Directory As -> Sources Root on 'src/main/java'

Val Blant
  • 1,664
  • 2
  • 24
  • 34
0

Sometimes problem in your code format structure.

Try this - Press ctrl+alt+shift+l and

  1. Choose selected text

  2. Code cleanup

then your problem is resolved

mnestorov
  • 4,116
  • 2
  • 14
  • 24
Abhijit Rajmane
  • 173
  • 2
  • 12
0

You can also temporarily force a "bad" source folder (ex: .../tmp), then switch back to the correct source folder (ex: src/main/java). This, combined with cache cleaning as explained in the other posts solved the problem for one of my collegues.

You declare / undeclar source folder with a right click on the folder, then "Mark Directory as ...".

toggeli
  • 17
  • 3
0

have u tried mark directory as -> Project Source and Header?I just work out it in CLion.

HuSharp
  • 387
  • 3
  • 4
0

If you use Lombok to generate constructors, the find declaration and usages will probably not work. I noticed this problem in my project but didn't find a solution. So, I removed the Lombok annotation @AllArgsConstructor and added the constructor, or just removing the annotation and using the Spring dependency injection annotation @Autowired will work too.