Skip to content

Commit 58aa6c7

Browse files
Merge branch 'main' into samgst/emitSessionStart
2 parents 838b641 + 49e31b2 commit 58aa6c7

File tree

14 files changed

+124
-60
lines changed

14 files changed

+124
-60
lines changed

buildSrc/src/main/kotlin/toolkit-detekt.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies {
1616
detektPlugins(project(":detekt-rules"))
1717
}
1818

19+
// detekt with type introspection configured in kotlin conventions
1920
private val detektFiles = fileTree(projectDir).matching {
2021
include("**/*.kt", "**/*.kts")
2122
exclude("**/build")

buildSrc/src/main/kotlin/toolkit-kotlin-conventions.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ project.afterEvaluate {
6060
}
6161
}
6262

63-
// can't figure out why exclude() doesn't work on the generated source tree, so copy logic from detekt
63+
// detekt applies sources directly from source sets in this scenario
64+
// can't figure out why source is empty in the detekt conventions
6465
project.extensions.getByType(KotlinJvmProjectExtension::class.java).target.compilations.configureEach {
65-
val inputSource = kotlinSourceSets
66-
.map { it.kotlin.sourceDirectories.filter { !it.path.contains("build") } }
67-
.fold(project.files() as FileCollection) { collection, next -> collection.plus(next) }
66+
// can't figure out why exclude("build/**") doesn't work
67+
fun FileTree.withoutBuild() = filter { f -> f.path.split(File.separatorChar).none { it == "build" } }.asFileTree
6868

6969
tasks.named<Detekt>(DetektPlugin.DETEKT_TASK_NAME + name.capitalize()).configure {
70-
setSource(inputSource)
70+
source = source.withoutBuild()
7171
}
7272

7373
tasks.named<DetektCreateBaselineTask>(DetektPlugin.BASELINE_TASK_NAME + name.capitalize()).configure {
74-
setSource(inputSource)
74+
source = source.withoutBuild()
7575
}
7676
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mockitoKotlin = "5.4.0"
2727
mockk = "1.13.10"
2828
nimbus-jose-jwt = "9.40"
2929
node-gradle = "7.0.2"
30-
telemetryGenerator = "1.0.272"
30+
telemetryGenerator = "1.0.278"
3131
testLogger = "4.0.0"
3232
testRetry = "1.5.10"
3333
# test-only; platform provides slf4j transitively at runtime

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/inline/InlineChatController.kt

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,26 @@ class InlineChatController(
138138
}
139139

140140
private fun recordInlineChatTelemetry(decision: InlineChatUserDecision) {
141-
if (metrics == null) return
142-
metrics?.userDecision = decision
143-
if (metrics?.requestId?.isNotEmpty() == true) {
141+
val metrics = metrics ?: return
142+
metrics.userDecision = decision
143+
144+
if (metrics.requestId.isNotEmpty()) {
144145
telemetryHelper.recordInlineChatTelemetry(
145-
metrics?.requestId!!,
146-
metrics?.inputLength,
147-
metrics?.numSelectedLines,
148-
metrics?.codeIntent,
149-
metrics?.userDecision,
150-
metrics?.responseStartLatency,
151-
metrics?.responseEndLatency,
152-
metrics?.numSuggestionAddChars,
153-
metrics?.numSuggestionAddLines,
154-
metrics?.numSuggestionDelChars,
155-
metrics?.numSuggestionDelLines,
156-
metrics?.programmingLanguage
146+
metrics.requestId,
147+
metrics.inputLength,
148+
metrics.numSelectedLines,
149+
metrics.codeIntent,
150+
metrics.userDecision,
151+
metrics.responseStartLatency,
152+
metrics.responseEndLatency,
153+
metrics.numSuggestionAddChars,
154+
metrics.numSuggestionAddLines,
155+
metrics.numSuggestionDelChars,
156+
metrics.numSuggestionDelLines,
157+
metrics.programmingLanguage
157158
)
158159
}
159-
metrics = null
160+
this.metrics = null
160161
}
161162

162163
private fun undoChanges() {
@@ -202,12 +203,17 @@ class InlineChatController(
202203

203204
fun initPopup(editor: Editor) {
204205
currentPopup?.let { Disposer.dispose(it) }
205-
currentPopup = InlineChatPopupFactory(
206-
acceptHandler = diffAcceptHandler, rejectHandler = { diffRejectHandler(editor) },
207-
submitHandler = popupSubmitHandler, cancelHandler = { popupCancelHandler(editor) }
208-
).createPopup(editor, scope)
209-
addPopupListeners(currentPopup!!, editor)
210-
Disposer.register(this, currentPopup!!)
206+
val popup = InlineChatPopupFactory(
207+
acceptHandler = diffAcceptHandler,
208+
rejectHandler = { diffRejectHandler(editor) },
209+
submitHandler = popupSubmitHandler,
210+
cancelHandler = { popupCancelHandler(editor) }
211+
).createPopup(editor, scope).also {
212+
currentPopup = it
213+
}
214+
215+
addPopupListeners(popup, editor)
216+
Disposer.register(this, popup)
211217
canPopupAbort.set(true)
212218
val caretListener = createCaretListener(editor)
213219
editor.caretModel.addCaretListener(caretListener)
@@ -526,21 +532,19 @@ class InlineChatController(
526532
}
527533

528534
private fun insertString(editor: Editor, offset: Int, text: String): RangeMarker {
529-
var rangeMarker: RangeMarker? = null
535+
lateinit var rangeMarker: RangeMarker
530536

531537
ApplicationManager.getApplication().invokeAndWait {
532538
CommandProcessor.getInstance().runUndoTransparentAction {
533539
WriteCommandAction.runWriteCommandAction(project) {
534540
editor.document.insertString(offset, text)
535541
rangeMarker = editor.document.createRangeMarker(offset, offset + text.length)
536542
}
537-
rangeMarker?.let { marker ->
538-
highlightCodeWithBackgroundColor(editor, marker.startOffset, marker.endOffset, true)
539-
}
543+
highlightCodeWithBackgroundColor(editor, rangeMarker.startOffset, rangeMarker.endOffset, true)
540544
}
541545
}
542546

543-
return rangeMarker!!
547+
return rangeMarker
544548
}
545549

546550
private fun replaceString(document: Document, start: Int, end: Int, text: String) {
@@ -667,9 +671,9 @@ class InlineChatController(
667671
return@withLock
668672
}
669673
try {
670-
if (selectionRange != null) {
671-
processChatDiff(selectedCode, event, editor, selectionRange!!)
672-
} else {
674+
selectionRange?.let {
675+
processChatDiff(selectedCode, event, editor, it)
676+
} ?: run {
673677
processNewCode(editor, selectedLineStart, event, prevMessage)
674678
}
675679
} catch (e: Exception) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ class CodeWhispererPopupManagerNew {
601601
}
602602

603603
private fun getValidCount(): Int =
604-
CodeWhispererServiceNew.getInstance().getAllSuggestionsPreviewInfo().filter { isValidRecommendation(it) }.size
604+
CodeWhispererServiceNew.getInstance().getAllSuggestionsPreviewInfo().count { isValidRecommendation(it) }
605605

606606
private fun getValidSelectedIndex(selectedIndex: Int): Int {
607607
var curr = 0

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
364364
) {
365365
(e as CodeWhispererRuntimeException)
366366

367-
requestId = e.requestId() ?: ""
367+
requestId = e.requestId().orEmpty()
368368
sessionId = e.awsErrorDetails().sdkHttpResponse().headers().getOrDefault(KET_SESSION_ID, listOf(requestId))[0]
369369
val exceptionType = e::class.simpleName
370370
val responseContext = ResponseContext(sessionId)
@@ -410,11 +410,11 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
410410
)
411411
return
412412
} else if (e is CodeWhispererException) {
413-
requestId = e.requestId() ?: ""
413+
requestId = e.requestId().orEmpty()
414414
sessionId = e.awsErrorDetails().sdkHttpResponse().headers().getOrDefault(KET_SESSION_ID, listOf(requestId))[0]
415415
displayMessage = e.awsErrorDetails().errorMessage() ?: message("codewhisperer.trigger.error.server_side")
416416
} else if (e is CodeWhispererRuntimeException) {
417-
requestId = e.requestId() ?: ""
417+
requestId = e.requestId().orEmpty()
418418
sessionId = e.awsErrorDetails().sdkHttpResponse().headers().getOrDefault(KET_SESSION_ID, listOf(requestId))[0]
419419
displayMessage = e.awsErrorDetails().errorMessage() ?: message("codewhisperer.trigger.error.server_side")
420420
} else {
@@ -525,7 +525,7 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
525525
// TODO: may have bug when it's a mix of auto-trigger + manual trigger
526526
val hasAtLeastOneValid = checkRecommendationsValidity(nextStates, true)
527527
val allSuggestions = ongoingRequests.values.filterNotNull().flatMap { it.recommendationContext.details }
528-
val valid = allSuggestions.filter { !it.isDiscarded }.size
528+
val valid = allSuggestions.count { !it.isDiscarded }
529529
LOG.debug { "Suggestions status: valid: $valid, discarded: ${allSuggestions.size - valid}" }
530530

531531
// If there are no recommendations at all in this session, we need to manually send the user decision event here
@@ -770,8 +770,8 @@ class CodeWhispererServiceNew(private val cs: CoroutineScope) : Disposable {
770770
"Left context of current line: ${requestContext.fileContextInfo.caretContext.leftContextOnCurrentLine}, " +
771771
"Cursor line: ${requestContext.caretPosition.line}, " +
772772
"Caret offset: ${requestContext.caretPosition.offset}, " +
773-
(latency?.let { "Latency: $latency, " } ?: "") +
774-
(exceptionType?.let { "Exception Type: $it, " } ?: "") +
773+
latency?.let { "Latency: $latency, " }.orEmpty() +
774+
exceptionType?.let { "Exception Type: $it, " }.orEmpty() +
775775
"Recommendations: \n${recommendationLogs ?: "None"}"
776776
}
777777
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererFileContextProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class DefaultCodeWhispererFileContextProvider(private val project: Project) : Fi
272272

273273
@VisibleForTesting
274274
suspend fun fetchProjectContext(query: String, psiFile: PsiFile, targetContext: FileContextInfo): SupplementalContextInfo {
275-
val response = ProjectContextController.getInstance(project).queryInline(query, psiFile.virtualFile?.path ?: "")
275+
val response = ProjectContextController.getInstance(project).queryInline(query, psiFile.virtualFile?.path.orEmpty())
276276

277277
return SupplementalContextInfo(
278278
isUtg = false,

plugins/core/core/src/software/aws/toolkits/core/telemetry/MetricEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
package software.aws.toolkits.core.telemetry
55

66
import software.amazon.awssdk.services.toolkittelemetry.model.AWSProduct
7+
import software.amazon.awssdk.services.toolkittelemetry.model.MetricUnit
78
import software.aws.toolkits.core.telemetry.MetricEvent.Companion.illegalCharsRegex
89
import software.aws.toolkits.core.utils.getLogger
910
import software.aws.toolkits.core.utils.warn
1011
import java.time.Instant
11-
import software.amazon.awssdk.services.toolkittelemetry.model.Unit as MetricUnit
1212

1313
interface MetricEvent {
1414
val createTime: Instant

plugins/core/jetbrains-community/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ idea {
3232
}
3333

3434
val generateTelemetry = tasks.register<GenerateTelemetry>("generateTelemetry") {
35-
inputFiles = listOf(file("${project.projectDir}/resources/telemetryOverride.json"))
36-
outputDirectory = generatedSrcDir.get().asFile
35+
inputFiles.setFrom(file("${project.projectDir}/resources/telemetryOverride.json"))
36+
outputDirectory.set(generatedSrcDir)
3737

3838
doFirst {
39-
outputDirectory.deleteRecursively()
39+
outputDirectory.get().asFile.deleteRecursively()
4040
}
4141
}
4242

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/ToolkitAuthManager.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.intellij.openapi.progress.ProcessCanceledException
1010
import com.intellij.openapi.project.Project
1111
import migration.software.aws.toolkits.jetbrains.services.telemetry.TelemetryService
1212
import software.amazon.awssdk.services.ssooidc.model.SsoOidcException
13+
import software.amazon.awssdk.services.toolkittelemetry.model.MetricUnit
1314
import software.aws.toolkits.core.ClientConnectionSettings
1415
import software.aws.toolkits.core.ConnectionSettings
1516
import software.aws.toolkits.core.TokenConnectionSettings
@@ -374,7 +375,7 @@ private fun recordLoginWithBrowser(
374375
TelemetryService.getInstance().record(null as Project?) {
375376
datum("aws_loginWithBrowser") {
376377
createTime(Instant.now())
377-
unit(software.amazon.awssdk.services.toolkittelemetry.model.Unit.NONE)
378+
unit(MetricUnit.NONE)
378379
value(1.0)
379380
passive(false)
380381
credentialSourceId?.let { metadata("credentialSourceId", it.toString()) }
@@ -398,7 +399,7 @@ private fun recordAddConnection(
398399
TelemetryService.getInstance().record(null as Project?) {
399400
datum("auth_addConnection") {
400401
createTime(Instant.now())
401-
unit(software.amazon.awssdk.services.toolkittelemetry.model.Unit.NONE)
402+
unit(MetricUnit.NONE)
402403
value(1.0)
403404
passive(false)
404405
credentialSourceId?.let { metadata("credentialSourceId", it.toString()) }

0 commit comments

Comments
 (0)