@@ -89,6 +89,7 @@ import software.aws.toolkits.resources.message
89
89
import software.aws.toolkits.telemetry.AmazonqTelemetry
90
90
import software.aws.toolkits.telemetry.MetricResult
91
91
import software.aws.toolkits.telemetry.UiTelemetry
92
+ import java.io.File
92
93
import java.nio.file.Files
93
94
import java.nio.file.Path
94
95
import java.nio.file.Paths
@@ -159,10 +160,6 @@ class CodeTestChatController(
159
160
// check if IDE has active file open, yes return (fileName and filePath) else return null
160
161
val project = context.project
161
162
val fileInfo = checkActiveFileInIDE(project, message) ? : return
162
- val projectRoot = Path .of(
163
- project.basePath ? : project.guessProjectDir()?.path
164
- ? : error(" Cannot guess base directory for project ${project.name} " )
165
- )
166
163
session.programmingLanguage = fileInfo.fileLanguage
167
164
if (session.isGeneratingTests == = true ) {
168
165
return
@@ -190,8 +187,7 @@ class CodeTestChatController(
190
187
message.tabId,
191
188
false
192
189
)
193
- val supported = fileInfo.filePath.startsWith(projectRoot.toString()) && isLanguageSupported(fileInfo.fileLanguage.languageId)
194
- if (supported) {
190
+ if (fileInfo.fileInWorkspace && isLanguageSupported(fileInfo.fileLanguage.languageId)) {
195
191
// Send Capability card to chat
196
192
codeTestChatHelper.addNewMessage(
197
193
CodeTestChatMessageContent (informationCard = true , message = null , type = ChatMessageType .Answer , canBeVoted = false ),
@@ -237,7 +233,7 @@ class CodeTestChatController(
237
233
}
238
234
.build()
239
235
240
- val messageContent = if (fileInfo.filePath.startsWith(projectRoot.toString()) ) {
236
+ val messageContent = if (fileInfo.fileInWorkspace ) {
241
237
" <span style=\" color: #EE9D28;\" >⚠<b> ${fileInfo.fileLanguage.languageId} is not a " +
242
238
" language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
243
239
" I support now are Python and Java. I can still provide examples, instructions and code suggestions."
@@ -300,7 +296,7 @@ class CodeTestChatController(
300
296
AmazonqTelemetry .utgGenerateTests(
301
297
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
302
298
hasUserPromptSupplied = session.hasUserPromptSupplied,
303
- isFileInWorkspace = fileInfo.filePath.startsWith(projectRoot.toString()) ,
299
+ isFileInWorkspace = fileInfo.fileInWorkspace ,
304
300
isSupportedLanguage = isLanguageSupported(fileInfo.fileLanguage.languageId),
305
301
credentialStartUrl = getStartUrl(project),
306
302
result = MetricResult .Succeeded ,
@@ -1129,6 +1125,7 @@ class CodeTestChatController(
1129
1125
val filePath : String ,
1130
1126
val fileName : String ,
1131
1127
val fileLanguage : CodeWhispererProgrammingLanguage ,
1128
+ val fileInWorkspace : Boolean = true ,
1132
1129
)
1133
1130
1134
1131
private suspend fun updateUIState () {
@@ -1160,6 +1157,9 @@ class CodeTestChatController(
1160
1157
val fileEditorManager = FileEditorManager .getInstance(project)
1161
1158
val activeEditor = fileEditorManager.selectedEditor
1162
1159
val activeFile = fileEditorManager.selectedFiles.firstOrNull()
1160
+ val projectRoot = project.basePath?.let { Path .of(it) }?.toFile()?.toVirtualFile() ? : run {
1161
+ project.guessProjectDir() ? : error(" Cannot guess base directory for project ${project.name} " )
1162
+ }
1163
1163
1164
1164
if (activeEditor == null || activeFile == null ) {
1165
1165
handleInvalidFileState(message.tabId)
@@ -1174,6 +1174,7 @@ class CodeTestChatController(
1174
1174
filePath = activeFile.path,
1175
1175
fileName = activeFile.name,
1176
1176
fileLanguage = programmingLanguage,
1177
+ fileInWorkspace = activeFile.path.startsWith(projectRoot.path)
1177
1178
)
1178
1179
} catch (e: Exception ) {
1179
1180
LOG .debug { " Error checking active file: $e " }
@@ -1187,6 +1188,8 @@ class CodeTestChatController(
1187
1188
}
1188
1189
}
1189
1190
1191
+ private fun File.toVirtualFile () = LocalFileSystem .getInstance().findFileByIoFile(this )
1192
+
1190
1193
/* UTG Tab Chat input use cases:
1191
1194
* 1. If User exits the flow and want to start a new generate unit test cycle.
1192
1195
* 2. If User clicks on Modify build command option and can enter the build command from chat input
0 commit comments