getSourceRootForFile does not work for phpstorm


I develop a sonar plugin for intellij and want  also get it work for phpstorm. To calculate file pathes correctly I need  to know, what is the source root of each source code file.
For Intellij Idea I do it this way:

VirtualFile sourceRootForFile = ProjectFileIndex.SERVICE.getInstance(file.getProject()).getSourceRootForFile(virtualFile);

But for phpstorm this returns null, thus I workaround it currently by:
sourceRootForFile = ProjectFileIndex.SERVICE.getInstance(file.getProject()).getContentRootForFile(virtualFile);

This  gets my approach working somehow, but is not a fully correct way,  because php source files are also located in "src" directory and not in  root directory of the project.

So how do I get the correct source root for a file in phpstorm?


phpstorm 6.0.2, intellij idea 12.x
Comment actions Permalink

The "src" directory does not have any special significance in PhpStorm; .php files can be stored in any directory. PhpStorm does not have any concept of source roots in its UI, so the API does not return any information.

Comment actions Permalink

Ok so the correct way to get file path is using the contentSource.
Thank you.


Please sign in to leave a comment.