Skip to content

Commit 63b9ff5

Browse files
committed
remove not needed methods and fields
1 parent 40100f3 commit 63b9ff5

File tree

3 files changed

+14
-146
lines changed

3 files changed

+14
-146
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/CodeWhispererPopupListener.kt

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.popup
55

66
import com.intellij.openapi.ui.popup.JBPopupListener
77
import com.intellij.openapi.ui.popup.LightweightWindowEvent
8+
import io.ktor.client.request.request
89
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLspService
910
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.InlineCompletionStates
1011
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.LogInlineCompletionSessionResultsParams
1112
import software.aws.toolkits.jetbrains.services.codewhisperer.model.InvocationContext
1213
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatus
1314
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererServiceNew
15+
import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeWhispererTelemetryService
1416
import java.time.Duration
1517
import java.time.Instant
1618

@@ -23,24 +25,12 @@ class CodeWhispererPopupListener(private val states: InvocationContext) : JBPopu
2325
super.onClosed(event)
2426
val (requestContext, responseContext, recommendationContext) = states
2527

26-
// TODO YUX: call flare hooks
27-
AmazonQLspService.executeIfRunning(requestContext.project) { server ->
28-
val params = LogInlineCompletionSessionResultsParams(
29-
sessionId = responseContext.sessionId,
30-
completionSessionResult = recommendationContext.details.associate {
31-
it.itemId to InlineCompletionStates(
32-
seen = it.hasSeen,
33-
accepted = it.isAccepted,
34-
discarded = it.isDiscarded
35-
)
36-
},
37-
firstCompletionDisplayLatency = CodeWhispererPopupManager.getInstance().sessionContext.perceivedLatency,
38-
totalSessionDisplayTime = CodeWhispererInvocationStatus.getInstance().completionShownTime?.let { Duration.between(it, Instant.now()) }
39-
?.toMillis()?.toDouble(),
40-
typeaheadLength = recommendationContext.userInput.length.toLong()
41-
)
42-
server.logInlineCompletionSessionResults(params)
43-
}
28+
CodeWhispererTelemetryService.getInstance().sendUserTriggerDecisionEvent(
29+
requestContext.project,
30+
requestContext.latencyContext,
31+
responseContext.sessionId,
32+
recommendationContext
33+
)
4434
CodeWhispererInvocationStatus.getInstance().setDisplaySessionActive(false)
4535
}
4636
}

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
187187

188188
val language = psiFile.programmingLanguage()
189189
val leftContext = requestContext.fileContextInfo.caretContext.leftFileContext
190-
// TODO: remove language check, flare needs to implement json aws template support only
190+
// TODO flare: remove language check, flare needs to implement json aws template support only
191191
if (!language.isCodeCompletionSupported() || (
192192
language is CodeWhispererJson && !isSupportedJsonFormat(
193193
requestContext.fileContextInfo.filename,
@@ -248,12 +248,9 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
248248
do {
249249
val result = AmazonQLspService.executeIfRunning(requestContext.project) { server ->
250250
val params = createInlineCompletionParams(requestContext.editor, requestContext.triggerTypeInfo, nextToken)
251-
println("cursor position: ${params.position.line}, ${params.position.character}")
252251
server.inlineCompletionWithReferences(params)
253252
}
254-
println(result)
255253
result?.thenAccept { completion ->
256-
println(completion)
257254
nextToken = completion.partialResultToken
258255
requestCount++
259256
val endTime = System.nanoTime()
@@ -311,7 +308,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
311308
}?.get()
312309
} while (nextToken != null)
313310
} catch (e: Exception) {
314-
// TODO YUX: flare doesn't return exceptions
311+
// TODO flare: flare doesn't return exceptions
315312
val requestId: String
316313
val sessionId: String
317314
val displayMessage: String
@@ -494,13 +491,11 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
494491

495492
if (CodeWhispererPopupManager.getInstance().hasConflictingPopups(requestContext.editor)) {
496493
LOG.debug { "Detect conflicting popup window with CodeWhisperer popup, not showing CodeWhisperer popup" }
497-
// TODO YUX: log discard
498494
return null
499495
}
500496

501497
if (caretMovement == CaretMovement.MOVE_BACKWARD) {
502498
LOG.debug { "Caret moved backward, discarding all of the recommendations. Session Id: ${completions.sessionId}" }
503-
// TODO YUX: log discard
504499
return null
505500
}
506501
val userInput =
@@ -593,8 +588,6 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
593588
// 5. customization
594589
val customizationArn = CodeWhispererModelConfigurator.getInstance().activeCustomization(project)?.arn
595590

596-
val profileArn = QRegionProfileManager.getInstance().activeProfile(project)?.arn
597-
598591
var workspaceId: String? = null
599592
try {
600593
val workspacesInfos = getWorkspaceIds(project).get().workspaces
@@ -618,7 +611,6 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
618611
connection,
619612
latencyContext,
620613
customizationArn,
621-
profileArn,
622614
workspaceId,
623615
)
624616
}
@@ -772,7 +764,6 @@ data class RequestContext(
772764
val connection: ToolkitConnection?,
773765
val latencyContext: LatencyContext,
774766
val customizationArn: String?,
775-
val profileArn: String?,
776767
val workspaceId: String?,
777768
)
778769

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

Lines changed: 4 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
130130
val project = editor.project ?: return
131131
if (!isCodeWhispererEnabled(project)) return
132132

133-
latencyContext.crdentialFetchingStart = System.nanoTime()
134-
135133
// try to refresh automatically if possible, otherwise ask user to login again
136134
if (isQExpired(project)) {
137135
// consider changing to only running once a ~minute since this is relatively expensive
@@ -245,12 +243,9 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
245243
do {
246244
val result = AmazonQLspService.executeIfRunning(requestContext.project) { server ->
247245
val params = createInlineCompletionParams(requestContext.editor, requestContext.triggerTypeInfo, nextToken)
248-
println("cursor position: ${params.position.line}, ${params.position.character}")
249246
server.inlineCompletionWithReferences(params)
250247
}
251-
println(result)
252248
result?.thenAccept { completion ->
253-
println(completion)
254249
nextToken = completion.partialResultToken
255250
val a = 1
256251
requestCount++
@@ -335,58 +330,7 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
335330
val sessionId: String
336331
val displayMessage: String
337332

338-
if (
339-
CustomizationConstants.invalidCustomizationExceptionPredicate(e) ||
340-
e is ResourceNotFoundException
341-
) {
342-
(e as CodeWhispererRuntimeException)
343-
344-
requestId = e.requestId().orEmpty()
345-
sessionId = e.awsErrorDetails().sdkHttpResponse().headers().getOrDefault(KET_SESSION_ID, listOf(requestId))[0]
346-
val exceptionType = e::class.simpleName
347-
val responseContext = ResponseContext(sessionId)
348-
349-
CodeWhispererTelemetryServiceNew.getInstance().sendServiceInvocationEvent(
350-
currentJobId,
351-
requestId,
352-
requestContext,
353-
responseContext,
354-
lastRecommendationIndex,
355-
false,
356-
0.0,
357-
exceptionType
358-
)
359-
360-
LOG.debug {
361-
"The provided customization ${requestContext.customizationArn} is not found, " +
362-
"will fallback to the default and retry generate completion"
363-
}
364-
logServiceInvocation(requestContext, responseContext, null, null, exceptionType)
365-
366-
notifyWarn(
367-
title = "",
368-
content = message("codewhisperer.notification.custom.not_available"),
369-
project = requestContext.project,
370-
notificationActions = listOf(
371-
NotificationAction.create(
372-
message("codewhisperer.notification.custom.simple.button.select_another_customization")
373-
) { _, notification ->
374-
CodeWhispererModelConfigurator.getInstance().showConfigDialog(requestContext.project)
375-
notification.expire()
376-
}
377-
)
378-
)
379-
CodeWhispererInvocationStatusNew.getInstance().finishInvocation()
380-
381-
requestContext.customizationArn?.let { CodeWhispererModelConfigurator.getInstance().invalidateCustomization(it) }
382-
383-
showRecommendationsInPopup(
384-
requestContext.editor,
385-
requestContext.triggerTypeInfo,
386-
latencyContext
387-
)
388-
return
389-
} else if (e is CodeWhispererRuntimeException) {
333+
if (e is CodeWhispererRuntimeException) {
390334
requestId = e.requestId().orEmpty()
391335
sessionId = e.awsErrorDetails().sdkHttpResponse().headers().getOrDefault(KET_SESSION_ID, listOf(requestId))[0]
392336
displayMessage = e.awsErrorDetails().errorMessage() ?: message("codewhisperer.trigger.error.server_side")
@@ -535,7 +479,7 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
535479
val detailContexts = completions.items.map {
536480
DetailContext("", it, true, getCompletionType(it))
537481
}.toMutableList()
538-
val recommendationContext = RecommendationContextNew(detailContexts, "", "", VisualPosition(0, 0), jobId)
482+
val recommendationContext = RecommendationContextNew(detailContexts, "", VisualPosition(0, 0), jobId)
539483
ongoingRequests[jobId] = buildInvocationContext(requestContext, responseContext, recommendationContext)
540484
disposeDisplaySession(false)
541485
return null
@@ -637,48 +581,13 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
637581
// 1. file context
638582
val fileContext: FileContextInfo = runReadAction { FileContextProvider.getInstance(project).extractFileContext(editor, psiFile) }
639583

640-
// the upper bound for supplemental context duration is 50ms
641-
// 2. supplemental context
642-
val supplementalContext = cs.async {
643-
try {
644-
FileContextProvider.getInstance(project).extractSupplementalFileContext(psiFile, fileContext, timeout = SUPPLEMENTAL_CONTEXT_TIMEOUT)
645-
} catch (e: Exception) {
646-
LOG.warn { "Run into unexpected error when fetching supplemental context, error: ${e.message}" }
647-
null
648-
}
649-
}
650-
651584
// 3. caret position
652585
val caretPosition = runReadAction { getCaretPosition(editor) }
653586

654587
// 4. connection
655588
val connection = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(CodeWhispererConnection.getInstance())
656589

657-
// 5. customization
658-
val customizationArn = CodeWhispererModelConfigurator.getInstance().activeCustomization(project)?.arn
659-
660-
val profileArn = QRegionProfileManager.getInstance().activeProfile(project)?.arn
661-
662-
return RequestContextNew(project, editor, triggerTypeInfo, caretPosition, fileContext, supplementalContext, connection, customizationArn, profileArn)
663-
}
664-
665-
fun validateResponse(response: GenerateCompletionsResponse): GenerateCompletionsResponse {
666-
// If contentSpans in reference are not consistent with content(recommendations),
667-
// remove the incorrect references.
668-
val validatedRecommendations = response.completions().map {
669-
val validReferences = it.hasReferences() && it.references().isNotEmpty() &&
670-
it.references().none { reference ->
671-
val span = reference.recommendationContentSpan()
672-
span.start() > span.end() || span.start() < 0 || span.end() > it.content().length
673-
}
674-
if (validReferences) {
675-
it
676-
} else {
677-
it.toBuilder().references(DefaultSdkAutoConstructList.getInstance()).build()
678-
}
679-
}
680-
681-
return response.toBuilder().completions(validatedRecommendations).build()
590+
return RequestContextNew(project, editor, triggerTypeInfo, caretPosition, fileContext, connection)
682591
}
683592

684593
private fun buildInvocationContext(
@@ -802,30 +711,8 @@ data class RequestContextNew(
802711
val triggerTypeInfo: TriggerTypeInfo,
803712
val caretPosition: CaretPosition,
804713
val fileContextInfo: FileContextInfo,
805-
private val supplementalContextDeferred: Deferred<SupplementalContextInfo?>,
806714
val connection: ToolkitConnection?,
807-
val customizationArn: String?,
808-
val profileArn: String?,
809-
) {
810-
// TODO: should make the entire getRequestContext() suspend function instead of making supplemental context only
811-
var supplementalContext: SupplementalContextInfo? = null
812-
private set
813-
get() = when (field) {
814-
null -> {
815-
if (!supplementalContextDeferred.isCompleted) {
816-
error("attempt to access supplemental context before awaiting the deferred")
817-
} else {
818-
null
819-
}
820-
}
821-
else -> field
822-
}
823-
824-
suspend fun awaitSupplementalContext(): SupplementalContextInfo? {
825-
supplementalContext = supplementalContextDeferred.await()
826-
return supplementalContext
827-
}
828-
}
715+
)
829716

830717
interface CodeWhispererIntelliSenseOnHoverListener {
831718
fun onEnter() {}

0 commit comments

Comments
 (0)