Had a problem where invalidating cache, deleting folders etc. wouldn't help at all - the UI completely froze after a while hanging on indexing/scanning. What surprisingly resolved the issue was renaming all the project folders that IntelliJ tried to open and scan at once - after that the program got a fresh start and I was able to open and index the project one by one.