Skip to content

Commit b8f204c

Browse files
committed
clean up codebase
1 parent e2c86e6 commit b8f204c

File tree

11 files changed

+40
-223
lines changed

11 files changed

+40
-223
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ class CodeTestChatController(
639639
}
640640
LOG.debug { "Original code content from reference span: $originalContent" }
641641
withContext(EDT) {
642+
// TODO flare: hook /test references with flare correctly, this is only a compile error fix which is not tested
642643
manager.addReferenceLogPanelEntry(reference = InlineCompletionReference(
643644
referenceName = reference.repository(),
644645
referenceUrl = reference.url(),

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/controller/ReferenceLogController.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import software.aws.toolkits.jetbrains.services.cwc.messages.CodeReference
1717

1818
object ReferenceLogController {
1919
fun addReferenceLog(originalCode: String, codeReferences: List<CodeReference>?, editor: Editor, project: Project, inlineChatStartPosition: CaretPosition?) {
20+
// TODO flare: hook /dev references with flare correctly, this is only a compile error fix which is not tested
2021
codeReferences?.let { references ->
2122
val cwReferences = references.map { reference ->
2223
InlineCompletionReference(
@@ -44,6 +45,7 @@ object ReferenceLogController {
4445
fun addReferenceLog(codeReferences: List<CodeReferenceGenerated>?, project: Project) {
4546
val manager = CodeWhispererCodeReferenceManager.getInstance(project)
4647

48+
// TODO flare: hook /dev references with flare correctly, this is only a compile error fix which is not tested
4749
codeReferences?.forEach { reference ->
4850
val cwReferences = InlineCompletionReference(
4951
referenceName = reference.repository ?: "",

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/actions/CodeWhispererRecommendationAction.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,23 @@ class CodeWhispererRecommendationAction : AnAction(message("codewhisperer.trigge
4040
latencyContext.codewhispererEndToEndStart = System.nanoTime()
4141
val editor = e.getRequiredData(CommonDataKeys.EDITOR)
4242
if (!(
43-
// if (CodeWhispererFeatureConfigService.getInstance().getNewAutoTriggerUX()) {
44-
// CodeWhispererServiceNew.getInstance().canDoInvocation(editor, CodewhispererTriggerType.OnDemand)
45-
// } else {
43+
if (CodeWhispererFeatureConfigService.getInstance().getNewAutoTriggerUX()) {
44+
CodeWhispererServiceNew.getInstance().canDoInvocation(editor, CodewhispererTriggerType.OnDemand)
45+
} else {
4646
CodeWhispererService.getInstance().canDoInvocation(editor, CodewhispererTriggerType.OnDemand)
47-
// }
47+
}
4848
)
4949
) {
5050
return
5151
}
5252

5353
val triggerType = TriggerTypeInfo(CodewhispererTriggerType.OnDemand, CodeWhispererAutomatedTriggerType.Unknown())
54-
// val job = if (CodeWhispererFeatureConfigService.getInstance().getNewAutoTriggerUX()) {
55-
// CodeWhispererServiceNew.getInstance().showRecommendationsInPopup(editor, triggerType, latencyContext)
56-
// } else {
57-
// CodeWhispererService.getInstance().showRecommendationsInPopup(editor, triggerType, latencyContext)
58-
// }
5954
CodeWhispererInvocationStatus.getInstance().timeAtLastManualTrigger = Instant.now()
60-
val job = CodeWhispererService.getInstance().showRecommendationsInPopup(editor, triggerType, latencyContext)
55+
val job = if (CodeWhispererFeatureConfigService.getInstance().getNewAutoTriggerUX()) {
56+
CodeWhispererServiceNew.getInstance().showRecommendationsInPopup(editor, triggerType, latencyContext)
57+
} else {
58+
CodeWhispererService.getInstance().showRecommendationsInPopup(editor, triggerType, latencyContext)
59+
}
6160

6261
e.getData(CommonDataKeys.EDITOR)?.getUserData(ACTION_JOB_KEY)?.set(job)
6362
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/codescan/utils/CodeWhispererCodeScanIssueUtils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ fun applySuggestedFix(project: Project, issue: CodeWhispererCodeScanIssue) {
351351
LOG.debug { "Applied fix with reference: $reference" }
352352
val originalContent = updatedContent.substring(reference.recommendationContentSpan().start(), reference.recommendationContentSpan().end())
353353
LOG.debug { "Original content from reference span: $originalContent" }
354+
// TODO flare: hook codescan references with flare correctly, this is only a compile error fix which is not tested
354355
manager.addReferenceLogPanelEntry(reference = InlineCompletionReference(
355356
referenceName = reference.repository(),
356357
referenceUrl = reference.url(),

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/editor/CodeWhispererEditorManager.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,6 @@ class CodeWhispererEditorManager {
6666
WriteCommandAction.runWriteCommandAction(project) {
6767
val rangeMarker = document.createRangeMarker(originalOffset, endOffset, true)
6868

69-
// TODO: send accepted suggestion code percentage event
70-
// CodeWhispererTelemetryService.getInstance().enqueueAcceptedSuggestionEntry(
71-
// detail.itemId,
72-
// requestContext,
73-
// responseContext,
74-
// Instant.now(),
75-
// PsiDocumentManager.getInstance(project).getPsiFile(document)?.virtualFile,
76-
// rangeMarker,
77-
// remainingRecommendation,
78-
// selectedIndex,
79-
// detail.completionType
80-
// )
81-
8269
ApplicationManager.getApplication().messageBus.syncPublisher(
8370
CodeWhispererPopupManager.CODEWHISPERER_USER_ACTION_PERFORMED,
8471
).afterAccept(states, sessionContext, rangeMarker)

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/editor/CodeWhispererEditorManagerNew.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class CodeWhispererEditorManagerNew {
3131
val selectedIndex = sessionContext.selectedIndex
3232
val preview = previews[selectedIndex]
3333
val states = CodeWhispererServiceNew.getInstance().getAllPaginationSessions()[preview.jobId] ?: return
34-
val (requestContext, responseContext) = states
3534
val (project, editor) = sessionContext
3635
val document = editor.document
3736
val primaryCaret = editor.caretModel.primaryCaret
@@ -65,19 +64,6 @@ class CodeWhispererEditorManagerNew {
6564
WriteCommandAction.runWriteCommandAction(project) {
6665
val rangeMarker = document.createRangeMarker(originalOffset, endOffset, true)
6766

68-
// TODO YUX: handle accepted entry on service side
69-
// CodeWhispererTelemetryServiceNew.getInstance().enqueueAcceptedSuggestionEntry(
70-
// detail.itemId,
71-
// requestContext,
72-
// responseContext,
73-
// Instant.now(),
74-
// PsiDocumentManager.getInstance(project).getPsiFile(document)?.virtualFile,
75-
// rangeMarker,
76-
// remainingRecommendation,
77-
// selectedIndex,
78-
// detail.completionType
79-
// )
80-
8167
ApplicationManager.getApplication().messageBus.syncPublisher(
8268
CodeWhispererPopupManager.CODEWHISPERER_USER_ACTION_PERFORMED,
8369
).afterAccept(states, previews, sessionContext, rangeMarker)

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/importadder/CodeWhispererImportAdder.kt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,19 @@ abstract class CodeWhispererImportAdder {
2727
fun insertImportStatements(states: InvocationContext, sessionContext: SessionContext) {
2828
val completion = states.recommendationContext.details[sessionContext.selectedIndex].completion
2929
val imports = completion.mostRelevantMissingImports
30-
// TODO YUX:
31-
// LOG.info { "Adding ${imports.size} imports for completions, sessionId: ${completion..sessionId}" }
30+
LOG.info { "Adding ${imports?.size ?: 0} imports for completions, sessionId: ${states.responseContext.sessionId}" }
3231
imports?.forEach {
3332
insertImportStatement(states, it)
3433
}
3534
}
3635

37-
// fun insertImportStatements(states: InvocationContextNew, previews: List<PreviewContext>, sessionContext: SessionContextNew) {
38-
// val completion = states.recommendationContext.details[sessionContext.selectedIndex].completion
39-
// val imports = completion.mostRelevantMissingImports
40-
// val imports = previews[sessionContext.selectedIndex].detail.recommendation.mostRelevantMissingImports()
41-
// LOG.info { "Adding ${imports.size} imports for completions, sessionId: ${states.responseContext.sessionId}" }
42-
// imports.forEach {
43-
// insertImportStatement(states, it)
44-
// }
45-
// }
36+
fun insertImportStatements(states: InvocationContextNew, previews: List<PreviewContext>, sessionContext: SessionContextNew) {
37+
val imports = previews[sessionContext.selectedIndex].detail.completion.mostRelevantMissingImports
38+
LOG.info { "Adding ${imports?.size ?: 0} imports for completions, sessionId: ${states.responseContext.sessionId}" }
39+
imports?.forEach {
40+
insertImportStatement(states, it)
41+
}
42+
}
4643

4744
private fun insertImportStatement(states: InvocationContext, import: InlineCompletionImports) {
4845
val project = states.requestContext.project
@@ -76,13 +73,13 @@ abstract class CodeWhispererImportAdder {
7673
LOG.info { "Added import: $added" }
7774
}
7875

79-
private fun insertImportStatement(states: InvocationContextNew, import: Import) {
76+
private fun insertImportStatement(states: InvocationContextNew, import: InlineCompletionImports) {
8077
val project = states.requestContext.project
8178
val editor = states.requestContext.editor
8279
val document = editor.document
8380
val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document) ?: return
8481

85-
val statement = import.statement()
82+
val statement = import.statement
8683
LOG.info { "Import statement to be added: $statement" }
8784
val newImport = createNewImportPsiElement(psiFile, statement)
8885
if (newImport == null) {

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/importadder/CodeWhispererImportAdderListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ object CodeWhispererImportAdderListener : CodeWhispererUserActionListener {
4949
LOG.debug { "No import adder found for $language" }
5050
return
5151
}
52-
// importAdder.insertImportStatements(states, previews, sessionContext)
52+
importAdder.insertImportStatements(states, previews, sessionContext)
5353
}
5454
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/model/CodeWhispererModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ data class InvocationContext(
206206

207207
data class InvocationContextNew(
208208
val requestContext: RequestContextNew,
209+
val responseContext: ResponseContext,
209210
val recommendationContext: RecommendationContextNew,
210211
) : Disposable {
211212
private var isDisposed = false

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,10 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
262262
val endTime = System.nanoTime()
263263
val latency = TimeUnit.NANOSECONDS.toMillis(endTime - startTime).toDouble()
264264
startTime = endTime
265-
// val requestId = response.responseMetadata().requestId()
266-
// val sessionId = completion.sessionId
267265
if (requestCount == 1) {
268266
requestContext.latencyContext.paginationFirstCompletionTime =
269267
(endTime - requestContext.latencyContext.codewhispererEndToEndStart).toDouble()
270-
// requestContext.latencyContext.firstRequestId = requestId
271-
// CodeWhispererInvocationStatus.getInstance().setInvocationSessionId(sessionId)
272268
}
273-
// if (response.nextToken().isEmpty()) {
274-
// requestContext.latencyContext.paginationAllCompletionsEnd = System.nanoTime()
275-
// }
276269
val responseContext = ResponseContext(completion.sessionId)
277270
logServiceInvocation(requestContext, responseContext, completion, latency, null)
278271
lastRecommendationIndex += completion.items.size
@@ -341,16 +334,6 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
341334
val exceptionType = e::class.simpleName
342335
val responseContext = ResponseContext(sessionId)
343336

344-
// CodeWhispererTelemetryService.getInstance().sendServiceInvocationEvent(
345-
// requestId,
346-
// requestContext,
347-
// responseContext,
348-
// lastRecommendationIndex,
349-
// false,
350-
// 0.0,
351-
// exceptionType
352-
// )
353-
//
354337
LOG.debug {
355338
"The provided customization ${requestContext.customizationArn} is not found, " +
356339
"will fallback to the default and retry generate completion"
@@ -405,16 +388,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
405388
val responseContext = ResponseContext(sessionId)
406389
CodeWhispererInvocationStatus.getInstance().setInvocationSessionId(sessionId)
407390
logServiceInvocation(requestContext, responseContext, null, null, exceptionType)
408-
// CodeWhispererTelemetryService.getInstance().sendServiceInvocationEvent(
409-
// requestId,
410-
// requestContext,
411-
// responseContext,
412-
// lastRecommendationIndex,
413-
// false,
414-
// 0.0,
415-
// exceptionType
416-
// )
417-
//
391+
418392
if (e is ThrottlingException &&
419393
e.message == CodeWhispererConstants.THROTTLING_MESSAGE
420394
) {
@@ -516,9 +490,6 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
516490
return nextStates
517491
}
518492

519-
fun handleLspInlineCompletion(project: Project, editor: Editor, triggerType: TriggerTypeInfo, nextToken: Either<String, Int>?) {
520-
}
521-
522493
private fun initStates(
523494
requestContext: RequestContext,
524495
responseContext: ResponseContext,
@@ -667,25 +638,6 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
667638
} ?: (CompletableFuture.failedFuture(IllegalStateException("LSP Server not running")))
668639
}
669640

670-
fun validateResponse(response: GenerateCompletionsResponse): GenerateCompletionsResponse {
671-
// If contentSpans in reference are not consistent with content(recommendations),
672-
// remove the incorrect references.
673-
val validatedRecommendations = response.completions().map {
674-
val validReferences = it.hasReferences() && it.references().isNotEmpty() &&
675-
it.references().none { reference ->
676-
val span = reference.recommendationContentSpan()
677-
span.start() > span.end() || span.start() < 0 || span.end() > it.content().length
678-
}
679-
if (validReferences) {
680-
it
681-
} else {
682-
it.toBuilder().references(DefaultSdkAutoConstructList.getInstance()).build()
683-
}
684-
}
685-
686-
return response.toBuilder().completions(validatedRecommendations).build()
687-
}
688-
689641
private fun buildInvocationContext(
690642
requestContext: RequestContext,
691643
responseContext: ResponseContext,
@@ -814,45 +766,6 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
814766
}
815767

816768
fun hasReAuthPromptBeenShown() = reAuthPromptShown
817-
818-
fun buildCodeWhispererRequest(
819-
fileContextInfo: FileContextInfo,
820-
supplementalContext: SupplementalContextInfo?,
821-
customizationArn: String?,
822-
profileArn: String?,
823-
workspaceId: String?,
824-
): GenerateCompletionsRequest {
825-
val programmingLanguage = ProgrammingLanguage.builder()
826-
.languageName(fileContextInfo.programmingLanguage.toCodeWhispererRuntimeLanguage().languageId)
827-
.build()
828-
val fileContext = FileContext.builder()
829-
.leftFileContent(fileContextInfo.caretContext.leftFileContext)
830-
.rightFileContent(fileContextInfo.caretContext.rightFileContext)
831-
.filename(fileContextInfo.fileRelativePath ?: fileContextInfo.filename)
832-
.programmingLanguage(programmingLanguage)
833-
.build()
834-
val supplementalContexts = supplementalContext?.contents?.map {
835-
SupplementalContext.builder()
836-
.content(it.content)
837-
.filePath(it.path)
838-
.build()
839-
}.orEmpty()
840-
val includeCodeWithReference = if (CodeWhispererSettings.getInstance().isIncludeCodeWithReference()) {
841-
RecommendationsWithReferencesPreference.ALLOW
842-
} else {
843-
RecommendationsWithReferencesPreference.BLOCK
844-
}
845-
846-
return GenerateCompletionsRequest.builder()
847-
.fileContext(fileContext)
848-
.supplementalContexts(supplementalContexts)
849-
.referenceTrackerConfiguration { it.recommendationsWithReferences(includeCodeWithReference) }
850-
.customizationArn(customizationArn)
851-
.optOutPreference(getTelemetryOptOutPreference())
852-
.profileArn(profileArn)
853-
.workspaceId(workspaceId)
854-
.build()
855-
}
856769
}
857770
}
858771

0 commit comments

Comments
 (0)