FileBasedIndex.getAllKeys filtered by module scope
Answered
It is possible to do something like mentioned in post topic? Or in other way - can I get collection of values matching collection of given keys?
Actually I do something like this:
FileBasedIndex.getInstance().getAllKeys(getName(), psiElement.getProject())
but I obtain all keys. I would like to get only keys from module in which is given psiElement or all values from this module.
Please sign in to leave a comment.
There is no method for it, also processAllKeys method will pass to your processor all keys of the project despite of given GlobalSearchScope, you should filter them by yourself.
Sorry for resurrecting this old thread, but I believe I've hit a related problem and want to clarify the solution. I'm calling:
and am getting back keys from all open projects. It sounds like that's what Alexander is referencing, though he's speaking specifically about processAllKeys() (UPDATE: I just noticed that getAllKeys() simply calls processAllKeys() using allScope()).
Am I correct in assuming that I need to post-process the result of getAllKeys() to determine which are actually for the supplied project? If so, there a more efficient way to do that than:
with each returned index key and seeing if the resulting collection is empty or not? That seems very inefficient.
Thanks!
Yes you have to post-process the keys in order to determine which of them have values in particular scope. E.g.:
Perfect. Thanks, Alexander!
seems to work if the index has overriden `traceKeyHashToVirtualFileMapping` as following:
Works for me in IntelliJ 2021.3.