-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLI-1556 In Rider, all solution's files should be analyzed
- Loading branch information
1 parent
4d6c923
commit ebef455
Showing
9 changed files
with
104 additions
and
118 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
common/src/main/java/org/sonarlint/intellij/common/analysis/FilesContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.sonarlint.intellij.common.analysis; | ||
|
||
import com.intellij.openapi.extensions.ExtensionPointName; | ||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import java.util.Set; | ||
|
||
public interface FilesContributor { | ||
// Name is constructed from plugin-id.extension-point-name | ||
ExtensionPointName<FilesContributor> EP_NAME = ExtensionPointName.create("org.sonarlint.idea.filesContributor"); | ||
|
||
Set<VirtualFile> listFiles(Module module); | ||
} |
31 changes: 31 additions & 0 deletions
31
common/src/main/java/org/sonarlint/intellij/common/util/FileUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.sonarlint.intellij.common.util | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.roots.GeneratedSourcesFilter.isGeneratedSourceByAnyFilter | ||
import com.intellij.openapi.roots.ProjectFileIndex | ||
import com.intellij.openapi.util.io.FileUtilRt | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import org.sonarlint.intellij.common.ui.ReadActionUtils.Companion.computeReadActionSafely | ||
import org.sonarlint.intellij.common.ui.SonarLintConsole | ||
|
||
class FileUtils { | ||
|
||
companion object { | ||
fun isFileValidForSonarLint(file: VirtualFile, project: Project): Boolean { | ||
try { | ||
val toSkip = computeReadActionSafely(project) { | ||
isGeneratedSourceByAnyFilter(file, project) | ||
|| ProjectFileIndex.getInstance(project).isExcluded(file) | ||
|| ProjectFileIndex.getInstance(project).isInLibrary(file) | ||
|| (!ApplicationManager.getApplication().isUnitTestMode && FileUtilRt.isTooLarge(file.length)) | ||
} | ||
return false == toSkip | ||
} catch (e: Exception) { | ||
SonarLintConsole.get(project).error("Error while visiting a file, reason: " + e.message) | ||
return false | ||
} | ||
} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
rider/src/main/java/org/sonarlint/intellij/rider/RiderFilesContributor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.sonarlint.intellij.rider | ||
|
||
import com.intellij.openapi.module.Module | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.jetbrains.rider.projectView.workspace.ProjectModelEntity | ||
import com.jetbrains.rider.projectView.workspace.ProjectModelEntityVisitor | ||
import com.jetbrains.rider.projectView.workspace.getVirtualFileAsContentRoot | ||
import com.jetbrains.rider.projectView.workspace.isProjectFile | ||
import org.sonarlint.intellij.common.analysis.FilesContributor | ||
import org.sonarlint.intellij.common.util.FileUtils.Companion.isFileValidForSonarLint | ||
|
||
class RiderFilesContributor : FilesContributor { | ||
|
||
override fun listFiles(module: Module): MutableSet<VirtualFile> { | ||
val filesInContentRoots = mutableSetOf<VirtualFile>() | ||
|
||
val visitor = object : ProjectModelEntityVisitor() { | ||
override fun visitProjectFile(entity: ProjectModelEntity): Result { | ||
if (module.isDisposed) { | ||
return Result.Stop | ||
} | ||
|
||
if (entity.isProjectFile()) { | ||
entity.getVirtualFileAsContentRoot()?.let { | ||
if (!it.isDirectory && it.isValid && isFileValidForSonarLint(it, module.project)) { | ||
filesInContentRoots.add(it) | ||
} | ||
} | ||
} | ||
|
||
return Result.Continue | ||
} | ||
} | ||
visitor.visit(module.project) | ||
|
||
return filesInContentRoots | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters