Skip to content

Commit 3afef56

Browse files
Merge branch 'main' into samgst/NotificationDismissedExpire
2 parents cb7d9f9 + 291be07 commit 3afef56

File tree

13 files changed

+104
-26
lines changed

13 files changed

+104
-26
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix incorrect text shown while updating documentation in /doc"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Amazon Q /dev: Fix issue when files are deleted while preparing context"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Amazon Q /test: Test generation fails for files outside the project"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Prevent customization override if user has manually selected a customization"
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/CodeWhispererUTGChatManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
512512
AmazonqTelemetry.utgGenerateTests(
513513
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
514514
hasUserPromptSupplied = session.hasUserPromptSupplied,
515+
isFileInWorkspace = true,
515516
isSupportedLanguage = true,
516517
credentialStartUrl = getStartUrl(project),
517518
jobGroup = session.testGenerationJobGroupName,

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.intellij.openapi.application.ApplicationManager
1212
import com.intellij.openapi.fileEditor.FileDocumentManager
1313
import com.intellij.openapi.fileEditor.FileEditorManager
1414
import com.intellij.openapi.project.Project
15+
import com.intellij.openapi.project.guessProjectDir
1516
import com.intellij.openapi.vfs.LocalFileSystem
1617
import com.intellij.openapi.vfs.VirtualFile
1718
import com.intellij.openapi.vfs.VirtualFileManager
@@ -22,6 +23,7 @@ import kotlinx.coroutines.future.await
2223
import kotlinx.coroutines.launch
2324
import kotlinx.coroutines.withContext
2425
import migration.software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererModelConfigurator
26+
import software.amazon.awssdk.services.codewhispererruntime.model.IdeCategory
2527
import software.amazon.awssdk.services.codewhispererruntime.model.Position
2628
import software.amazon.awssdk.services.codewhispererruntime.model.Range
2729
import software.amazon.awssdk.services.codewhispererruntime.model.Reference
@@ -157,6 +159,10 @@ class CodeTestChatController(
157159
// check if IDE has active file open, yes return (fileName and filePath) else return null
158160
val project = context.project
159161
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+
)
160166
session.programmingLanguage = fileInfo.fileLanguage
161167
if (session.isGeneratingTests === true) {
162168
return
@@ -184,7 +190,8 @@ class CodeTestChatController(
184190
message.tabId,
185191
false
186192
)
187-
if (isLanguageSupported(fileInfo.fileLanguage.languageId)) {
193+
val supported = fileInfo.filePath.startsWith(projectRoot.toString()) && isLanguageSupported(fileInfo.fileLanguage.languageId)
194+
if (supported) {
188195
// Send Capability card to chat
189196
codeTestChatHelper.addNewMessage(
190197
CodeTestChatMessageContent(informationCard = true, message = null, type = ChatMessageType.Answer, canBeVoted = false),
@@ -230,9 +237,15 @@ class CodeTestChatController(
230237
}
231238
.build()
232239

233-
val messageContent = "<span style=\"color: #EE9D28;\">&#9888;<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."
240+
val messageContent = if (fileInfo.filePath.startsWith(projectRoot.toString())) {
241+
"<span style=\"color: #EE9D28;\">&#9888;<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;\">&#9888;<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+
}
236249

237250
codeTestChatHelper.addNewMessage(
238251
CodeTestChatMessageContent(
@@ -287,7 +300,8 @@ class CodeTestChatController(
287300
AmazonqTelemetry.utgGenerateTests(
288301
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
289302
hasUserPromptSupplied = session.hasUserPromptSupplied,
290-
isSupportedLanguage = false,
303+
isFileInWorkspace = fileInfo.filePath.startsWith(projectRoot.toString()),
304+
isSupportedLanguage = isLanguageSupported(fileInfo.fileLanguage.languageId),
291305
credentialStartUrl = getStartUrl(project),
292306
result = MetricResult.Succeeded,
293307
perfClientLatency = (Instant.now().toEpochMilli() - session.startTimeOfTestGeneration),
@@ -571,6 +585,7 @@ class CodeTestChatController(
571585
session.testGenerationJob,
572586
session.testGenerationJobGroupName,
573587
session.programmingLanguage,
588+
IdeCategory.JETBRAINS,
574589
session.numberOfUnitTestCasesGenerated,
575590
session.numberOfUnitTestCasesGenerated,
576591
session.linesOfCodeGenerated,
@@ -588,6 +603,7 @@ class CodeTestChatController(
588603
AmazonqTelemetry.utgGenerateTests(
589604
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
590605
hasUserPromptSupplied = session.hasUserPromptSupplied,
606+
isFileInWorkspace = true,
591607
isSupportedLanguage = true,
592608
credentialStartUrl = getStartUrl(project = context.project),
593609
jobGroup = session.testGenerationJobGroupName,
@@ -766,6 +782,7 @@ class CodeTestChatController(
766782
session.testGenerationJob,
767783
session.testGenerationJobGroupName,
768784
session.programmingLanguage,
785+
IdeCategory.JETBRAINS,
769786
session.numberOfUnitTestCasesGenerated,
770787
0,
771788
session.linesOfCodeGenerated,
@@ -782,6 +799,7 @@ class CodeTestChatController(
782799
AmazonqTelemetry.utgGenerateTests(
783800
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
784801
hasUserPromptSupplied = session.hasUserPromptSupplied,
802+
isFileInWorkspace = true,
785803
isSupportedLanguage = true,
786804
credentialStartUrl = getStartUrl(project = context.project),
787805
jobGroup = session.testGenerationJobGroupName,

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fun getIconForStep(targetStep: DocGenerationStep, currentStep: DocGenerationStep
110110
else -> checkIcons["wait"]
111111
}
112112

113-
fun docGenerationProgressMessage(currentStep: DocGenerationStep, mode: Mode): String {
113+
fun docGenerationProgressMessage(currentStep: DocGenerationStep, mode: Mode?): String {
114114
val isCreationMode = mode == Mode.CREATE
115115
val baseLine = if (isCreationMode) message("amazonqDoc.progress_message.creating") else message("amazonqDoc.progress_message.updating")
116116

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/session/DocGenerationState.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class DocGenerationState(
6464
message = action.msg,
6565
intent = Intent.DOC
6666
)
67-
68-
val codeGenerationResult = generateCode(codeGenerationId = response.codeGenerationId(), token)
67+
val mode = if (action.msg == message("amazonqDoc.session.create")) Mode.CREATE else null
68+
val codeGenerationResult = generateCode(codeGenerationId = response.codeGenerationId(), mode, token)
6969
numberOfReferencesGenerated = codeGenerationResult.references.size
7070
numberOfFilesGenerated = codeGenerationResult.newFiles.size
7171
codeGenerationRemainingIterationCount = codeGenerationResult.codeGenerationRemainingIterationCount
@@ -138,7 +138,7 @@ fun getFileSummaryPercentage(input: String): Double {
138138
return percentage
139139
}
140140

141-
private suspend fun DocGenerationState.generateCode(codeGenerationId: String, token: CancellationTokenSource?): CodeGenerationResult {
141+
private suspend fun DocGenerationState.generateCode(codeGenerationId: String, mode: Mode?, token: CancellationTokenSource?): CodeGenerationResult {
142142
val pollCount = 180
143143
val requestDelay = 10000L
144144

@@ -214,7 +214,7 @@ private suspend fun DocGenerationState.generateCode(codeGenerationId: String, to
214214
} else {
215215
DocGenerationStep.GENERATING_ARTIFACTS
216216
},
217-
mode = Mode.CREATE
217+
mode
218218
)
219219
)
220220
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/credentials/CodeWhispererClientAdaptor.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import software.amazon.awssdk.services.codewhispererruntime.model.GenerateComple
2727
import software.amazon.awssdk.services.codewhispererruntime.model.GetCodeFixJobRequest
2828
import software.amazon.awssdk.services.codewhispererruntime.model.GetCodeFixJobResponse
2929
import software.amazon.awssdk.services.codewhispererruntime.model.GetTestGenerationResponse
30+
import software.amazon.awssdk.services.codewhispererruntime.model.IdeCategory
3031
import software.amazon.awssdk.services.codewhispererruntime.model.InlineChatUserDecision
3132
import software.amazon.awssdk.services.codewhispererruntime.model.ListAvailableCustomizationsRequest
3233
import software.amazon.awssdk.services.codewhispererruntime.model.ListFeatureEvaluationsResponse
@@ -199,6 +200,7 @@ interface CodeWhispererClientAdaptor : Disposable {
199200
jobId: String,
200201
groupName: String,
201202
language: CodeWhispererProgrammingLanguage?,
203+
ideCategory: IdeCategory?,
202204
numberOfUnitTestCasesGenerated: Int?,
203205
numberOfUnitTestCasesAccepted: Int?,
204206
linesOfCodeGenerated: Int?,
@@ -668,6 +670,7 @@ open class CodeWhispererClientAdaptorImpl(override val project: Project) : CodeW
668670
jobId: String,
669671
groupName: String,
670672
language: CodeWhispererProgrammingLanguage?,
673+
ideCategory: IdeCategory?,
671674
numberOfUnitTestCasesGenerated: Int?,
672675
numberOfUnitTestCasesAccepted: Int?,
673676
linesOfCodeGenerated: Int?,
@@ -682,6 +685,7 @@ open class CodeWhispererClientAdaptorImpl(override val project: Project) : CodeW
682685
}
683686
it.jobId(jobId)
684687
it.groupName(groupName)
688+
it.ideCategory(ideCategory)
685689
it.numberOfUnitTestCasesGenerated(numberOfUnitTestCasesGenerated)
686690
it.numberOfUnitTestCasesAccepted(numberOfUnitTestCasesAccepted)
687691
it.linesOfCodeGenerated(linesOfCodeGenerated)

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/customization/CodeWhispererModelConfigurator.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,24 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
157157
return@calculateIfIamIdentityCenterConnection customizationUiItems
158158
}
159159

160+
/**
161+
* Gets the active customization for a user. If a user has manually selected a customization,
162+
* respect that choice. If a user has not selected a customization, check if they have a customization
163+
* assigned to them via an AB feature. If so, use that customization.
164+
*/
160165
override fun activeCustomization(project: Project): CodeWhispererCustomization? {
161-
val result = calculateIfIamIdentityCenterConnection(project) { connectionIdToActiveCustomizationArn[it.id] }
162-
163-
// A/B case
164-
val customizationFeature = CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()
165-
if (customizationFeature == null || customizationFeature.value.stringValue().isEmpty()) return result
166-
return CodeWhispererCustomization(
167-
arn = customizationFeature.value.stringValue(),
168-
name = customizationFeature.variation,
169-
description = result?.description
170-
)
166+
val selectedCustomization = calculateIfIamIdentityCenterConnection(project) { connectionIdToActiveCustomizationArn[it.id] }
167+
168+
if (selectedCustomization != null) {
169+
return selectedCustomization
170+
} else {
171+
val customizationOverride = CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()
172+
if (customizationOverride == null || customizationOverride.value.stringValue().isEmpty()) return null
173+
return CodeWhispererCustomization(
174+
arn = customizationOverride.value.stringValue(),
175+
name = customizationOverride.variation,
176+
)
177+
}
171178
}
172179

173180
override fun switchCustomization(project: Project, newCustomization: CodeWhispererCustomization?) {

0 commit comments

Comments
 (0)