diff --git a/common/src/main/java/org/sonarlint/intellij/common/util/FileUtils.kt b/common/src/main/java/org/sonarlint/intellij/common/util/FileUtils.kt index 92eafb30f..b6ffd0dcb 100644 --- a/common/src/main/java/org/sonarlint/intellij/common/util/FileUtils.kt +++ b/common/src/main/java/org/sonarlint/intellij/common/util/FileUtils.kt @@ -37,8 +37,7 @@ class FileUtils { fun isFileValidForSonarLint(file: VirtualFile, project: Project): Boolean { try { val toSkip = computeReadActionSafely(file, project) { - project.isDisposed - || (!ApplicationManager.getApplication().isUnitTestMode && !file.isDirectory && FileUtilRt.isTooLarge(file.length)) + (!ApplicationManager.getApplication().isUnitTestMode && !file.isDirectory && FileUtilRt.isTooLarge(file.length)) || FileElement.isArchive(file) || ProjectCoreUtil.isProjectOrWorkspaceFile(file) || isGeneratedSourceByAnyFilter(file, project) @@ -56,8 +55,7 @@ class FileUtils { try { val fileIndex = ProjectRootManager.getInstance(project).fileIndex val toSkip = computeReadActionSafely(file, project) { - project.isDisposed - || (!ApplicationManager.getApplication().isUnitTestMode && !file.isDirectory && FileUtilRt.isTooLarge(file.length)) + (!ApplicationManager.getApplication().isUnitTestMode && !file.isDirectory && FileUtilRt.isTooLarge(file.length)) || FileElement.isArchive(file) || !fileIndex.isInContent(file) || fileIndex.isInLibrarySource(file) diff --git a/src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt b/src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt index dd36e44ad..93bf389f5 100644 --- a/src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt +++ b/src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt @@ -69,7 +69,6 @@ import org.sonarlint.intellij.analysis.RunningAnalysesTracker import org.sonarlint.intellij.common.analysis.FilesContributor import org.sonarlint.intellij.common.ui.ReadActionUtils.Companion.computeReadActionSafely import org.sonarlint.intellij.common.ui.SonarLintConsole -import org.sonarlint.intellij.common.util.FileUtils.Companion.isFileValidForSonarLintWithExtensiveChecks import org.sonarlint.intellij.common.util.SonarLintUtils.getService import org.sonarlint.intellij.common.util.SonarLintUtils.isRider import org.sonarlint.intellij.common.vcs.VcsRepo @@ -111,6 +110,7 @@ import org.sonarlint.intellij.util.ProjectUtils.tryFindFile import org.sonarlint.intellij.util.SonarLintAppUtils.findModuleForFile import org.sonarlint.intellij.util.SonarLintAppUtils.getRelativePathForAnalysis import org.sonarlint.intellij.util.SonarLintAppUtils.visitAndAddAllFilesForModule +import org.sonarlint.intellij.util.SonarLintAppUtils.visitAndAddAllFilesForProject import org.sonarlint.intellij.util.VirtualFileUtils import org.sonarlint.intellij.util.VirtualFileUtils.getFileContent import org.sonarlint.intellij.util.computeInEDT @@ -674,17 +674,19 @@ object SonarLintIntelliJClient : SonarLintRpcClientDelegate { override fun listFiles(configScopeId: String): List { val timeStart = System.currentTimeMillis() val listClientFiles = BackendService.findModule(configScopeId)?.let { module -> - listModuleFiles(module, configScopeId) + computeOnPooledThread(module.project, "Listing All Module Files") { listModuleFiles(module, configScopeId) } } ?: findProject(configScopeId)?.let { project -> - val listProjectFiles = listProjectFiles(project, configScopeId) + computeOnPooledThread(project, "Listing All Project Files") { + val listProjectFiles = listProjectFiles(project, configScopeId) - if (isRider()) { - computeRiderSharedConfiguration(project, configScopeId)?.let { - listProjectFiles.add(it) + if (isRider()) { + computeRiderSharedConfiguration(project, configScopeId)?.let { + listProjectFiles.add(it) + } } + + listProjectFiles } - - listProjectFiles } ?: emptyList() val timeEnd = System.currentTimeMillis() @@ -751,7 +753,7 @@ object SonarLintIntelliJClient : SonarLintRpcClientDelegate { } private fun listProjectFiles(project: Project, configScopeId: String): MutableList { - return listFilesInProjectBaseDir(project).mapNotNull { file -> + return visitAndAddAllFilesForProject(project).mapNotNull { file -> getRelativePathForAnalysis(project, file)?.let { relativePath -> toClientFileDto( project, @@ -795,16 +797,6 @@ object SonarLintIntelliJClient : SonarLintRpcClientDelegate { } } - // useful for Rider where the files to find are not located in content roots - private fun listFilesInProjectBaseDir(project: Project): Set { - return project.guessProjectDir()?.children?.filter { - !it.isDirectory && it.isValid && isFileValidForSonarLintWithExtensiveChecks( - it, - project - ) - }?.toSet() ?: return emptySet() - } - override fun didChangeTaintVulnerabilities( configurationScopeId: String, closedTaintVulnerabilityIds: Set, addedTaintVulnerabilities: List, updatedTaintVulnerabilities: List, diff --git a/src/main/java/org/sonarlint/intellij/util/SonarLintAppUtils.java b/src/main/java/org/sonarlint/intellij/util/SonarLintAppUtils.java index 589fd1d94..474ab2f25 100644 --- a/src/main/java/org/sonarlint/intellij/util/SonarLintAppUtils.java +++ b/src/main/java/org/sonarlint/intellij/util/SonarLintAppUtils.java @@ -166,7 +166,7 @@ public static List visitAndAddAllFilesForModule(Module module) { return false; } - if (!vFile.isDirectory() && vFile.isValid() && FileUtils.Companion.isFileValidForSonarLint(vFile, module.getProject())) { + if (!vFile.isDirectory() && FileUtils.Companion.isFileValidForSonarLint(vFile, module.getProject())) { filesToAdd.add(vFile); return true; } @@ -184,7 +184,7 @@ public static List visitAndAddAllFilesForProject(Project project) { return false; } - if (!vFile.isDirectory() && vFile.isValid() && FileUtils.Companion.isFileValidForSonarLint(vFile, project)) { + if (!vFile.isDirectory() && FileUtils.Companion.isFileValidForSonarLint(vFile, project)) { filesToAdd.add(vFile); return true; } @@ -203,7 +203,7 @@ public boolean visitFile(VirtualFile file) { return false; } - if (!file.isDirectory() && file.isValid()) { + if (!file.isDirectory()) { filesToAdd.add(file); }