gayanper / sonarlint-intellij

SonarLint for IntelliJ
http://intellij.sonarlint.org
Other
1 stars 2 forks source link

Project bound to an invalid remote project #8

Open Sitjakun opened 3 years ago

Sitjakun commented 3 years ago

Hi !

Thank you very much for developing this Sonarlint upgrade. This is very useful to me.

I encountered an error while my Project Structure and Module files (.iml and more) are stored outside of the project code. Example: Intellij files -> C:/IdeaProjectName/ Source code (with .git) -> C:/ProjectName/

I struggled a bit to find out what was going wrong and found a fix :

in org.sonarlint.intellij.config.project.SonarLintProjectSettings.java

I changed : return Optional.ofNullable(m.getModuleFile()) .orElseGet(() -> Arrays.stream(ModuleRootManager.getInstance(m).getContentRoots()).findFirst().orElse(null)); to : return Optional.ofNullable(Arrays.stream(ModuleRootManager.getInstance(m).getContentRoots()).findFirst().orElse(null)) .orElseGet(() -> m.getModuleFile());

Because ProjectLevelVcsManager.getInstance(project).getVcsRootFor(virtualFile) will return null if virtualFile is the .iml file, when the content root will target the folder which is linked to VCS.