Skip to content

Commit

Permalink
Fix for gitignore filter for project payload. (#5309)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishrp-aws authored Jan 28, 2025
1 parent aa98252 commit 445dd9e
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import software.aws.toolkits.core.utils.debug
import software.aws.toolkits.core.utils.error
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.cannotFindBuildArtifacts
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.cannotFindFile
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.fileTooLarge
Expand All @@ -38,6 +37,7 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhisperer
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.DEFAULT_PAYLOAD_LIMIT_IN_BYTES
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.EXPRESS_SCAN_TIMEOUT_IN_SECONDS
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.FILE_SCAN_PAYLOAD_SIZE_LIMIT_IN_BYTES
import software.aws.toolkits.jetbrains.services.codewhisperer.util.GitIgnoreFilteringUtil
import software.aws.toolkits.jetbrains.services.codewhisperer.util.isWithin
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.CodewhispererLanguage
Expand All @@ -59,8 +59,6 @@ class CodeScanSessionConfig(
}
private set

private val featureDevSessionContext = FeatureDevSessionContext(project)

val fileIndex = ProjectRootManager.getInstance(project).fileIndex

fun isInitiatedByChat(): Boolean = initiatedByChat
Expand Down Expand Up @@ -234,14 +232,15 @@ class CodeScanSessionConfig(

moduleLoop@ for (module in project.modules) {
val changeListManager = ChangeListManager.getInstance(module.project)
if (module.guessModuleDir() != null) {
stack.push(module.guessModuleDir())
module.guessModuleDir()?.let { moduleDir ->
val gitIgnoreFilteringUtil = GitIgnoreFilteringUtil(moduleDir)
stack.push(moduleDir)
while (stack.isNotEmpty()) {
val current = stack.pop()

if (!current.isDirectory) {
if (current.isFile && !changeListManager.isIgnoredFile(current) &&
runBlocking { !featureDevSessionContext.ignoreFile(current) } &&
runBlocking { !gitIgnoreFilteringUtil.ignoreFile(current) } &&
runReadAction { !fileIndex.isInLibrarySource(current) }
) {
if (willExceedPayloadLimit(currentTotalFileSize, current.length)) {
Expand Down Expand Up @@ -284,7 +283,7 @@ class CodeScanSessionConfig(
}
// Directory case: only traverse if not ignored
if (!changeListManager.isIgnoredFile(current) &&
runBlocking { !featureDevSessionContext.ignoreFile(current) } &&
runBlocking { !gitIgnoreFilteringUtil.ignoreFile(current) } &&
!traversedDirectories.contains(current) && current.isValid &&
runReadAction { !fileIndex.isInLibrarySource(current) }
) {
Expand Down

0 comments on commit 445dd9e

Please sign in to comment.