@@ -12,6 +12,7 @@ import com.intellij.openapi.application.ApplicationManager
1212import com.intellij.openapi.fileEditor.FileDocumentManager
1313import com.intellij.openapi.fileEditor.FileEditorManager
1414import com.intellij.openapi.project.Project
15+ import com.intellij.openapi.project.guessProjectDir
1516import com.intellij.openapi.vfs.LocalFileSystem
1617import com.intellij.openapi.vfs.VirtualFile
1718import com.intellij.openapi.vfs.VirtualFileManager
@@ -158,6 +159,10 @@ class CodeTestChatController(
158159 // check if IDE has active file open, yes return (fileName and filePath) else return null
159160 val project = context.project
160161 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+ )
161166 session.programmingLanguage = fileInfo.fileLanguage
162167 if (session.isGeneratingTests == = true ) {
163168 return
@@ -185,7 +190,8 @@ class CodeTestChatController(
185190 message.tabId,
186191 false
187192 )
188- if (isLanguageSupported(fileInfo.fileLanguage.languageId)) {
193+ val supported = fileInfo.filePath.startsWith(projectRoot.toString()) && isLanguageSupported(fileInfo.fileLanguage.languageId)
194+ if (supported) {
189195 // Send Capability card to chat
190196 codeTestChatHelper.addNewMessage(
191197 CodeTestChatMessageContent (informationCard = true , message = null , type = ChatMessageType .Answer , canBeVoted = false ),
@@ -231,9 +237,15 @@ class CodeTestChatController(
231237 }
232238 .build()
233239
234- val messageContent = " <span style=\" color: #EE9D28;\" >⚠<b> ${fileInfo.fileLanguage.languageId} is not a " +
235- " language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
236- " I support now are Python and Java. I can still provide examples, instructions and code suggestions."
240+ val messageContent = if (fileInfo.filePath.startsWith(projectRoot.toString())) {
241+ " <span style=\" color: #EE9D28;\" >⚠<b> ${fileInfo.fileLanguage.languageId} is not a " +
242+ " language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
243+ " I support now are Python and Java. I can still provide examples, instructions and code suggestions."
244+ } else {
245+ " <span style=\" color: #EE9D28;\" >⚠<b> I can't generate tests for ${fileInfo.fileName} " +
246+ " because it's outside the project directory.</b><br></span> " +
247+ " I can still provide examples, instructions and code suggestions."
248+ }
237249
238250 codeTestChatHelper.addNewMessage(
239251 CodeTestChatMessageContent (
@@ -288,7 +300,8 @@ class CodeTestChatController(
288300 AmazonqTelemetry .utgGenerateTests(
289301 cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
290302 hasUserPromptSupplied = session.hasUserPromptSupplied,
291- isSupportedLanguage = false ,
303+ isFileInWorkspace = fileInfo.filePath.startsWith(projectRoot.toString()),
304+ isSupportedLanguage = isLanguageSupported(fileInfo.fileLanguage.languageId),
292305 credentialStartUrl = getStartUrl(project),
293306 result = MetricResult .Succeeded ,
294307 perfClientLatency = (Instant .now().toEpochMilli() - session.startTimeOfTestGeneration),
@@ -590,6 +603,7 @@ class CodeTestChatController(
590603 AmazonqTelemetry .utgGenerateTests(
591604 cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
592605 hasUserPromptSupplied = session.hasUserPromptSupplied,
606+ isFileInWorkspace = true ,
593607 isSupportedLanguage = true ,
594608 credentialStartUrl = getStartUrl(project = context.project),
595609 jobGroup = session.testGenerationJobGroupName,
@@ -785,6 +799,7 @@ class CodeTestChatController(
785799 AmazonqTelemetry .utgGenerateTests(
786800 cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
787801 hasUserPromptSupplied = session.hasUserPromptSupplied,
802+ isFileInWorkspace = true ,
788803 isSupportedLanguage = true ,
789804 credentialStartUrl = getStartUrl(project = context.project),
790805 jobGroup = session.testGenerationJobGroupName,
0 commit comments