Skip to content

Commit

Permalink
fix: filter out excluded files from results
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Oct 2, 2024
1 parent 0b695b6 commit 85a49d3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/io/snyk/plugin/SnykFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import snyk.common.RelativePathHelper

data class SnykFile(val project: Project, val virtualFile: VirtualFile) {
val relativePath = runAsync { RelativePathHelper().getRelativePath(virtualFile, project) }

fun isInContent(): Boolean {
return this.virtualFile.isInContent(project)
}
}

fun toSnykFileSet(project: Project, virtualFiles: Set<VirtualFile>) =
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/io/snyk/plugin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package io.snyk.plugin

import com.intellij.codeInsight.codeVision.CodeVisionHost
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.icons.ExpUiIcons.Run
import com.intellij.ide.util.PsiNavigationSupport
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.PathManager
Expand All @@ -20,6 +21,7 @@ import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.io.toNioPathOrNull
import com.intellij.openapi.util.registry.Registry
Expand All @@ -32,6 +34,7 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.PsiManager
import com.intellij.util.Alarm
import com.intellij.util.messages.Topic
import com.jetbrains.rd.generator.nova.PredefinedType
import io.snyk.plugin.analytics.AnalyticsScanListener
import io.snyk.plugin.services.SnykApplicationSettingsStateService
import io.snyk.plugin.services.SnykCliAuthenticationService
Expand Down Expand Up @@ -449,3 +452,8 @@ fun Project.getContentRootVirtualFiles(): Set<VirtualFile> {
.filter { it.exists() && it.isDirectory }
.sortedBy { it.path }.toSet()
}

fun VirtualFile.isInContent(project: Project): Boolean {
val vf = this
return ReadAction.compute<Boolean, RuntimeException> { ProjectFileIndex.getInstance(project).isInContent(vf) }
}
2 changes: 1 addition & 1 deletion src/main/kotlin/snyk/common/SnykCachedResults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class SnykCachedResults(
snykFile: SnykFile,
issueList: List<ScanIssue>
) {

if (!snykFile.isInContent()) return
when (product) {
LsProductConstants.OpenSource.value -> {
currentOSSResultsLS[snykFile] = issueList
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/snyk/common/annotator/SnykAnnotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import icons.SnykIcons
import io.snyk.plugin.Severity
import io.snyk.plugin.getSnykCachedResultsForProduct
import io.snyk.plugin.getSnykToolWindowPanel
import io.snyk.plugin.isInContent
import io.snyk.plugin.toLanguageServerURL
import org.eclipse.lsp4j.CodeAction
import org.eclipse.lsp4j.CodeActionContext
Expand All @@ -43,7 +44,6 @@ import snyk.common.annotator.SnykAnnotator.SnykAnnotation
import snyk.common.lsp.LanguageServerWrapper
import snyk.common.lsp.RangeConverter
import snyk.common.lsp.ScanIssue
import java.util.Collections
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import javax.swing.Icon
Expand Down Expand Up @@ -249,7 +249,8 @@ abstract class SnykAnnotator(private val product: ProductType) :
private fun getIssuesForFile(psiFile: PsiFile): Set<ScanIssue> =
getSnykCachedResultsForProduct(psiFile.project, product)
?.filter {
it.key.virtualFile == psiFile.virtualFile
val virtualFile = it.key.virtualFile
virtualFile == psiFile.virtualFile && virtualFile.isInContent(psiFile.project)
}
?.map { it.value }
?.flatten()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiFile
import icons.SnykIcons
import io.snyk.plugin.isInContent
import io.snyk.plugin.toLanguageServerURL
import org.eclipse.lsp4j.CodeLens
import org.eclipse.lsp4j.CodeLensParams
Expand Down Expand Up @@ -47,13 +48,15 @@ class LSCodeVisionProvider : CodeVisionProvider<Unit>, CodeVisionGroupSettingPro
if (LanguageServerWrapper.getInstance().isDisposed()) return CodeVisionState.READY_EMPTY
if (!LanguageServerWrapper.getInstance().isInitialized) return CodeVisionState.READY_EMPTY
val project = editor.project ?: return CodeVisionState.READY_EMPTY
if (!editor.virtualFile.isInContent(project)) return CodeVisionState.READY_EMPTY

val document = editor.document

val file = ReadAction.compute<PsiFile, RuntimeException> {
PsiDocumentManager.getInstance(project).getPsiFile(document)
} ?: return CodeVisionState.READY_EMPTY


val params = CodeLensParams(TextDocumentIdentifier(file.virtualFile.toLanguageServerURL()))
val lenses = mutableListOf<Pair<TextRange, CodeVisionEntry>>()
val codeLenses = try {
Expand Down

0 comments on commit 85a49d3

Please sign in to comment.