Skip to content

Commit

Permalink
Adding featureDevSessionContext back for more rigorous file ignore in…
Browse files Browse the repository at this point in the history
… payload creation.
  • Loading branch information
ashishrp-aws committed May 25, 2024
1 parent 4c49439 commit 5870158
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import com.intellij.openapi.project.modules
import com.intellij.openapi.vcs.changes.ChangeListManager
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import kotlinx.coroutines.runBlocking
import software.aws.toolkits.core.utils.createTemporaryZipFile
import software.aws.toolkits.core.utils.debug
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.putNextEntry
import software.aws.toolkits.jetbrains.services.amazonq.FeatureDevSessionContext
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.fileTooLarge
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.noFileOpenError
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.noSupportedFilesError
Expand Down Expand Up @@ -45,6 +47,8 @@ class CodeScanSessionConfig(
}
private set

private val featureDevSessionContext = FeatureDevSessionContext(project)

/**
* Timeout for the overall job - "Run Security Scan".
*/
Expand Down Expand Up @@ -151,7 +155,9 @@ class CodeScanSessionConfig(
val current = stack.pop()

if (!current.isDirectory) {
if (!changeListManager.isIgnoredFile(current) && !files.contains(current.path)
if (!changeListManager.isIgnoredFile(current) &&
runBlocking { !featureDevSessionContext.ignoreFile(current, this) } &&
!files.contains(current.path)
) {
if (willExceedPayloadLimit(currentTotalFileSize, current.length)) {
fileTooLarge()
Expand All @@ -168,7 +174,9 @@ class CodeScanSessionConfig(
}
} else {
// Directory case: only traverse if not ignored
if (!changeListManager.isIgnoredFile(current) && !traversedDirectories.contains(current)
if (!changeListManager.isIgnoredFile(current) &&
runBlocking { !featureDevSessionContext.ignoreFile(current, this) } &&
!traversedDirectories.contains(current)
) {
for (child in current.children) {
stack.push(child)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,5 +367,10 @@ class CodeWhispererProjectCodeScanTest : CodeWhispererCodeScanTestBase(PythonCod
).virtualFile
totalSize += testYaml.length
totalLines += testYaml.toNioPath().toFile().readLines().size

// Adding gitignore file and gitignore file member for testing.
// The tests include the markdown file but not these two files.
projectRule.fixture.addFileToProject("/.gitignore", "node_modules\n.idea\n.vscode\n.DS_Store").virtualFile
projectRule.fixture.addFileToProject("test.idea", "ref: refs/heads/main")
}
}

0 comments on commit 5870158

Please sign in to comment.