Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nquinquenel committed Oct 3, 2024
1 parent 5846ac4 commit 1cc96e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
30 changes: 11 additions & 19 deletions src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -674,17 +674,19 @@ object SonarLintIntelliJClient : SonarLintRpcClientDelegate {
override fun listFiles(configScopeId: String): List<ClientFileDto> {
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()
Expand Down Expand Up @@ -751,7 +753,7 @@ object SonarLintIntelliJClient : SonarLintRpcClientDelegate {
}

private fun listProjectFiles(project: Project, configScopeId: String): MutableList<ClientFileDto> {
return listFilesInProjectBaseDir(project).mapNotNull { file ->
return visitAndAddAllFilesForProject(project).mapNotNull { file ->
getRelativePathForAnalysis(project, file)?.let { relativePath ->
toClientFileDto(
project,
Expand Down Expand Up @@ -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<VirtualFile> {
return project.guessProjectDir()?.children?.filter {
!it.isDirectory && it.isValid && isFileValidForSonarLintWithExtensiveChecks(
it,
project
)
}?.toSet() ?: return emptySet()
}

override fun didChangeTaintVulnerabilities(
configurationScopeId: String, closedTaintVulnerabilityIds: Set<UUID>, addedTaintVulnerabilities: List<TaintVulnerabilityDto>,
updatedTaintVulnerabilities: List<TaintVulnerabilityDto>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static List<VirtualFile> 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;
}
Expand All @@ -184,7 +184,7 @@ public static List<VirtualFile> 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;
}
Expand All @@ -203,7 +203,7 @@ public boolean visitFile(VirtualFile file) {
return false;
}

if (!file.isDirectory() && file.isValid()) {
if (!file.isDirectory()) {
filesToAdd.add(file);
}

Expand Down

0 comments on commit 1cc96e3

Please sign in to comment.