Skip to content

Commit 5f74b1e

Browse files
authored
Fix detekt source override dropping all source (#5049)
In CI, the override just drops all the source because all paths contain `/codebuild` ``` > Task :plugin-amazonq:codewhisperer:jetbrains-community:detektMain NO-SOURCE Skipping task ':plugin-amazonq:codewhisperer:jetbrains-community:detektMain' as it has no source files and no previous output files. Resolve mutations for :plugin-core:jetbrains-community:compileTestFixturesJava (Thread[#144,Execution worker Thread 4,5,main]) started. :plugin-core:jetbrains-community:compileTestFixturesJava (Thread[#144,Execution worker Thread 4,5,main]) started. ```
1 parent 06181dd commit 5f74b1e

File tree

8 files changed

+52
-47
lines changed

8 files changed

+52
-47
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
}

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/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/otel/OtelBase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ abstract class AbstractBaseSpan<SpanType : AbstractBaseSpan<SpanType>>(internal
228228
if (missingFields.isNotEmpty()) {
229229
when {
230230
ApplicationManager.getApplication().isUnitTestMode -> error(message())
231-
isDeveloperMode() -> LOG.error(block = message)
232-
else -> LOG.error(block = message)
231+
isDeveloperMode() -> LOG.error { message() }
232+
else -> LOG.error { message() }
233233
}
234234
}
235235
}

plugins/toolkit/jetbrains-core/src-243+/software/aws/toolkits/jetbrains/services/lambda/python/PyCharmSdkSelectionPanel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PyCharmSdkSelectionPanel(private val projectLocation: TextFieldWithBrowseB
3030
NewProjectWizardBaseData.KEY,
3131
object : NewProjectWizardBaseData {
3232
override val nameProperty = graph.property("")
33-
override val pathProperty = graph.property(projectLocation?.text?.trim() ?: "")
33+
override val pathProperty = graph.property(projectLocation?.text?.trim().orEmpty())
3434

3535
override var name by nameProperty
3636
override var path by pathProperty

0 commit comments

Comments
 (0)