@@ -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
@@ -157,6 +158,10 @@ class CodeTestChatController(
157158 // check if IDE has active file open, yes return (fileName and filePath) else return null
158159 val project = context.project
159160 val fileInfo = checkActiveFileInIDE(project, message) ? : return
161+ val projectRoot = Path .of(
162+ project.basePath ? : project.guessProjectDir()?.path
163+ ? : error(" Cannot guess base directory for project ${project.name} " )
164+ )
160165 session.programmingLanguage = fileInfo.fileLanguage
161166 if (session.isGeneratingTests == = true ) {
162167 return
@@ -184,7 +189,8 @@ class CodeTestChatController(
184189 message.tabId,
185190 false
186191 )
187- if (isLanguageSupported(fileInfo.fileLanguage.languageId)) {
192+ val supported = fileInfo.filePath.startsWith(projectRoot.toString()) && isLanguageSupported(fileInfo.fileLanguage.languageId)
193+ if (supported) {
188194 // Send Capability card to chat
189195 codeTestChatHelper.addNewMessage(
190196 CodeTestChatMessageContent (informationCard = true , message = null , type = ChatMessageType .Answer , canBeVoted = false ),
@@ -230,9 +236,15 @@ class CodeTestChatController(
230236 }
231237 .build()
232238
233- val messageContent = " <span style=\" color: #EE9D28;\" >⚠<b> ${fileInfo.fileLanguage.languageId} is not a " +
234- " language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
235- " I support now are Python and Java. I can still provide examples, instructions and code suggestions."
239+ val messageContent = if (fileInfo.filePath.startsWith(projectRoot.toString())) {
240+ " <span style=\" color: #EE9D28;\" >⚠<b> ${fileInfo.fileLanguage.languageId} is not a " +
241+ " language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
242+ " I support now are Python and Java. I can still provide examples, instructions and code suggestions."
243+ } else {
244+ " <span style=\" color: #EE9D28;\" >⚠<b>External File Detected: ${fileInfo.fileName} \n " +
245+ " is outside the project directory.</b><br></span>" +
246+ " However, I can still help you create unit tests for ${fileInfo.fileName} here"
247+ }
236248
237249 codeTestChatHelper.addNewMessage(
238250 CodeTestChatMessageContent (
0 commit comments