You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/sessionconfig/CodeScanSessionConfig.kt
+23-7Lines changed: 23 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,8 @@ sealed class CodeScanSessionConfig(
33
33
privatevalselectedFile:VirtualFile,
34
34
privatevalproject:Project
35
35
) {
36
-
val projectRoot = project.guessProjectDir() ?: error("Cannot guess base directory for project ${project.name}")
36
+
var projectRoot = project.guessProjectDir() ?: error("Cannot guess base directory for project ${project.name}")
37
+
private set
37
38
38
39
abstractval sourceExt:String
39
40
@@ -64,23 +65,38 @@ sealed class CodeScanSessionConfig(
64
65
65
66
LOG.debug { "Creating payload. File selected as root for the context truncation: ${selectedFile.path}" }
66
67
67
-
val (includedSourceFiles, payloadSize, totalLines, _) = includeDependencies()
68
+
val payloadMetadata =when (selectedFile.path.startsWith(projectRoot.path)) {
69
+
true-> includeDependencies()
70
+
false-> {
71
+
// Set project root as the parent of the selected file.
72
+
projectRoot = selectedFile.parent
73
+
includeFileOutsideProjectRoot()
74
+
}
75
+
}
68
76
69
77
// Copy all the included source files to the source zip
70
-
val srcZip = zipFiles(includedSourceFiles.map { Path.of(it) })
78
+
val srcZip = zipFiles(payloadMetadata.sourceFiles.map { Path.of(it) })
Copy file name to clipboardExpand all lines: jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/CodeWhispererPythonCodeScanTest.kt
+36Lines changed: 36 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -149,6 +149,42 @@ class CodeWhispererPythonCodeScanTest : CodeWhispererCodeScanTestBase(PythonCode
149
149
assertThat(filesInZip).isEqualTo(2)
150
150
}
151
151
152
+
@Test
153
+
fun`test createPayload for file outside project`() {
154
+
val fileOutsideProjectPy = projectRule.fixture.addFileToProject(
155
+
"../fileOutsideProject.py",
156
+
"""
157
+
import numpy as np
158
+
import util
159
+
a = 1
160
+
"""
161
+
).virtualFile
162
+
val totalSize = fileOutsideProjectPy.length
163
+
val totalLines = fileOutsideProjectPy.toNioPath().toFile().readLines().size.toLong()
0 commit comments