Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Amazon Q /test: Fix to redirect /test to generate tests in chat for external files out of project scope."
}
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
AmazonqTelemetry.utgGenerateTests(
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
hasUserPromptSupplied = session.hasUserPromptSupplied,
isFileInWorkspace = true,
isSupportedLanguage = true,
credentialStartUrl = getStartUrl(project),
jobGroup = session.testGenerationJobGroupName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
Expand Down Expand Up @@ -157,6 +158,10 @@ class CodeTestChatController(
// check if IDE has active file open, yes return (fileName and filePath) else return null
val project = context.project
val fileInfo = checkActiveFileInIDE(project, message) ?: return
val projectRoot = Path.of(
project.basePath ?: project.guessProjectDir()?.path
?: error("Cannot guess base directory for project ${project.name}")
)
session.programmingLanguage = fileInfo.fileLanguage
if (session.isGeneratingTests === true) {
return
Expand Down Expand Up @@ -184,7 +189,8 @@ class CodeTestChatController(
message.tabId,
false
)
if (isLanguageSupported(fileInfo.fileLanguage.languageId)) {
val supported = fileInfo.filePath.startsWith(projectRoot.toString()) && isLanguageSupported(fileInfo.fileLanguage.languageId)
if (supported) {
// Send Capability card to chat
codeTestChatHelper.addNewMessage(
CodeTestChatMessageContent(informationCard = true, message = null, type = ChatMessageType.Answer, canBeVoted = false),
Expand Down Expand Up @@ -230,9 +236,15 @@ class CodeTestChatController(
}
.build()

val messageContent = "<span style=\"color: #EE9D28;\">&#9888;<b> ${fileInfo.fileLanguage.languageId} is not a " +
"language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
"I support now are Python and Java. I can still provide examples, instructions and code suggestions."
val messageContent = if (fileInfo.filePath.startsWith(projectRoot.toString())) {
"<span style=\"color: #EE9D28;\">&#9888;<b> ${fileInfo.fileLanguage.languageId} is not a " +
"language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
"I support now are Python and Java. I can still provide examples, instructions and code suggestions."
} else {
"<span style=\"color: #EE9D28;\">&#9888;<b>External File Detected: ${fileInfo.fileName} \n" +
" is outside the project directory.</b><br></span>" +
"However, I can still help you create unit tests for ${fileInfo.fileName} here"
}

codeTestChatHelper.addNewMessage(
CodeTestChatMessageContent(
Expand Down Expand Up @@ -287,7 +299,8 @@ class CodeTestChatController(
AmazonqTelemetry.utgGenerateTests(
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
hasUserPromptSupplied = session.hasUserPromptSupplied,
isSupportedLanguage = false,
isFileInWorkspace = fileInfo.filePath.startsWith(projectRoot.toString()),
isSupportedLanguage = isLanguageSupported(fileInfo.fileLanguage.languageId),
credentialStartUrl = getStartUrl(project),
result = MetricResult.Succeeded,
perfClientLatency = (Instant.now().toEpochMilli() - session.startTimeOfTestGeneration),
Expand Down Expand Up @@ -588,6 +601,7 @@ class CodeTestChatController(
AmazonqTelemetry.utgGenerateTests(
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
hasUserPromptSupplied = session.hasUserPromptSupplied,
isFileInWorkspace = true,
isSupportedLanguage = true,
credentialStartUrl = getStartUrl(project = context.project),
jobGroup = session.testGenerationJobGroupName,
Expand Down Expand Up @@ -782,6 +796,7 @@ class CodeTestChatController(
AmazonqTelemetry.utgGenerateTests(
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
hasUserPromptSupplied = session.hasUserPromptSupplied,
isFileInWorkspace = true,
isSupportedLanguage = true,
credentialStartUrl = getStartUrl(project = context.project),
jobGroup = session.testGenerationJobGroupName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@
"type": "boolean",
"description": "True if user selected code snippet as input else false"
},
{
"name": "isFileInWorkspace",
"type": "boolean",
"description": "Indicate if the file is in the current workspace."
},
{
"name": "isSupportedLanguage",
"type": "boolean",
Expand Down Expand Up @@ -573,6 +578,9 @@
"type": "isCodeBlockSelected",
"required": false
},
{
"type": "isFileInWorkspace"
},
{
"type": "isSupportedLanguage"
},
Expand Down
Loading