Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into rli/add-otel
Browse files Browse the repository at this point in the history
 Conflicts:
	plugins/core/jetbrains-community/build.gradle.kts
	plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/otel/OtelBase.kt
	plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/telemetry/otel/OtelBaseTest.kt
  • Loading branch information
rli committed Nov 5, 2024
2 parents 07018b2 + 06181dd commit 890089d
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 86 deletions.
8 changes: 8 additions & 0 deletions .changes/3.36.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"date" : "2024-10-30",
"version" : "3.36",
"entries" : [ {
"type" : "bugfix",
"description" : "Fix inline chat default key binding not working on windows and linux"
} ]
}
11 changes: 11 additions & 0 deletions .changes/3.37.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"date" : "2024-10-31",
"version" : "3.37",
"entries" : [ {
"type" : "bugfix",
"description" : "Amazon Q /dev: Fix the issue resulting in the first request per conversation to /dev failing"
}, {
"type" : "bugfix",
"description" : "Fix inline chat shortcut hint breaking text selection on remote editors"
} ]
}
12 changes: 6 additions & 6 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: remove unwanted dependencies
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Maximize Build Space
if: runner.os == 'Linux'
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
large-packages: false
- uses: actions/setup-java@v4
with:
distribution: 'corretto'
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# _3.37_ (2024-10-31)
- **(Bug Fix)** Amazon Q /dev: Fix the issue resulting in the first request per conversation to /dev failing
- **(Bug Fix)** Fix inline chat shortcut hint breaking text selection on remote editors

# _3.36_ (2024-10-30)
- **(Bug Fix)** Fix inline chat default key binding not working on windows and linux

# _3.35_ (2024-10-29)
- **(Feature)** Remove read-only mode on before diff of code changes generated by agent
- **(Feature)** Provide more frequent updates about code changes made by agent
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

# Toolkit Version
toolkitVersion=3.36-SNAPSHOT
toolkitVersion=3.38-SNAPSHOT

# Publish Settings
publishToken=
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[versions]
apache-commons-collections = "4.4"
apache-commons-io = "2.16.0"
apache-commons-text = "1.12.0"
assertJ = "3.26.3"
# match with <root>/settings.gradle.kts
awsSdk = "2.26.25"
Expand Down Expand Up @@ -70,6 +71,7 @@ aws-sts = { module = "software.amazon.awssdk:sts", version.ref = "awsSdk" }
commonmark = { module = "org.commonmark:commonmark", version.ref = "commonmark" }
commons-collections = { module = "org.apache.commons:commons-collections4", version.ref = "apache-commons-collections" }
commons-io = { module = "commons-io:commons-io", version.ref = "apache-commons-io" }
commons-text = {module = "org.apache.commons:commons-text", version.ref = "apache-commons-text"}
detekt-api = { module = "io.gitlab.arturbosch.detekt:detekt-api", version.ref = "detekt" }
detekt-formattingRules = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
diff-util = { module = "io.github.java-diff-utils:java-diff-utils", version.ref = "diff-util" }
Expand Down
1 change: 1 addition & 0 deletions plugins/amazonq/chat/jetbrains-community/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
// everything references codewhisperer, which is not ideal
implementation(project(":plugin-amazonq:codewhisperer:jetbrains-community"))
implementation(libs.diff.util)
implementation(libs.commons.text)

compileOnly(project(":plugin-core:jetbrains-community"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
factoryClass="software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindowFactory" icon="AwsIcons.Logos.AWS_Q" />

<postStartupActivity implementation="software.aws.toolkits.jetbrains.services.amazonq.startup.AmazonQStartupActivity"/>
<actionPromoter order="last" implementation="software.aws.toolkits.jetbrains.services.cwc.inline.InlineChatActionPromoter"/>
</extensions>

<extensions defaultExtensionNs="amazon.q">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ suspend fun FeatureDevController.onCodeGeneration(
message = message("amazonqFeatureDev.chat_message.requesting_changes"),
messageType = FeatureDevMessageType.AnswerStream,
)
val state = session.sessionState
var state = session.sessionState

var remainingIterations: Int? = state.codeGenerationRemainingIterationCount
var totalIterations: Int? = state.codeGenerationTotalIterationCount
Expand All @@ -64,6 +64,8 @@ suspend fun FeatureDevController.onCodeGeneration(

session.send(message) // Trigger code generation

state = session.sessionState

var filePaths: List<NewFileZipInfo> = emptyList()
var deletedFiles: List<DeletedFileInfo> = emptyList()
var references: List<CodeReferenceGenerated> = emptyList()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.services.cwc.inline

import com.intellij.openapi.actionSystem.ActionPromoter
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.keymap.KeymapUtil
import com.intellij.openapi.util.SystemInfo

class InlineChatActionPromoter : ActionPromoter {
// temporary until we find a better key binding
override fun promote(actions: MutableList<out AnAction>, context: DataContext): MutableList<AnAction> {
val results = actions.toMutableList()
if (context.getData(CommonDataKeys.EDITOR) == null ||
context.getData(CommonDataKeys.PROJECT) == null
) {
return results
}
val shortCut = KeymapUtil.getShortcutText("aws.toolkit.jetbrains.core.services.cwc.inline.openChat")
// only promote for the default key bindings
if (SystemInfo.isMac && shortCut != "⌘I") return results
if (!SystemInfo.isMac && shortCut != "Ctrl+I") return results

results.sortWith { a, b ->
when {
isOpenChatInputAction(a) -> -1
isOpenChatInputAction(b) -> 1
else -> 0
}
}
return results
}

private fun isOpenChatInputAction(action: AnAction): Boolean =
action is OpenChatInputAction
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.intellij.codeInsight.hint.HintUtil
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.VisualPosition
import com.intellij.openapi.keymap.KeymapUtil
import com.intellij.openapi.util.SystemInfo
import com.intellij.ui.LightweightHint
import com.intellij.ui.SimpleColoredText
import com.intellij.ui.SimpleTextAttributes
Expand Down Expand Up @@ -68,15 +67,9 @@ class InlineChatEditorHint {
coloredText.appendToComponent(component)
val shortcutComponent = HintUtil.createInformationComponent()
val shortCut = KeymapUtil.getShortcutText("aws.toolkit.jetbrains.core.services.cwc.inline.openChat")
if (!SystemInfo.isWindows && shortCut == "⌃I") {
val shortCutIcon = AwsIcons.Resources.InlineChat.AWS_Q_INLINECHAT_SHORTCUT
shortcutComponent.isIconOnTheRight = true
shortcutComponent.icon = shortCutIcon
} else {
val shortcutText =
SimpleColoredText(shortCut, SimpleTextAttributes.REGULAR_ATTRIBUTES)
shortcutText.appendToComponent(shortcutComponent)
}
val shortcutText =
SimpleColoredText(shortCut, SimpleTextAttributes.REGULAR_ATTRIBUTES)
shortcutText.appendToComponent(shortcutComponent)

val panel = JPanel(BorderLayout()).apply {
add(component, BorderLayout.WEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package software.aws.toolkits.jetbrains.services.cwc.inline.listeners

import com.intellij.idea.AppMode
import com.intellij.openapi.Disposable
import com.intellij.openapi.editor.event.SelectionEvent
import com.intellij.openapi.editor.event.SelectionListener
Expand All @@ -11,6 +12,7 @@ import software.aws.toolkits.jetbrains.services.cwc.inline.InlineChatEditorHint
class InlineChatSelectionListener : SelectionListener, Disposable {
private val inlineChatEditorHint = InlineChatEditorHint()
override fun selectionChanged(e: SelectionEvent) {
if (AppMode.isRemoteDevHost()) return
val editor = e.editor
val selectionModel = editor.selectionModel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ class DefaultCodeWhispererFileContextProvider(private val project: Project) : Fi
}

return supplementalContext?.let {
val latency = System.currentTimeMillis() - startFetchingTimestamp
if (it.contents.isNotEmpty()) {
val logStr = buildString {
append("Successfully fetched supplemental context with strategy ${it.strategy} with ${it.latency} ms")
append("Successfully fetched supplemental context with strategy ${it.strategy} with $latency ms")
it.contents.forEachIndexed { index, chunk ->
append(
"""
Expand All @@ -166,8 +167,7 @@ class DefaultCodeWhispererFileContextProvider(private val project: Project) : Fi
LOG.warn { "Failed to fetch supplemental context, empty list." }
}

// TODO: fix this latency
it.copy(latency = System.currentTimeMillis() - startFetchingTimestamp)
it.copy(latency = latency)
}
} catch (e: TimeoutCancellationException) {
LOG.debug {
Expand Down Expand Up @@ -379,8 +379,12 @@ class DefaultCodeWhispererFileContextProvider(private val project: Project) : Fi
}
}

// takeLast(11) will extract 10 lines (exclusing current line) of left context as the query parameter
fun generateQuery(fileContext: FileContextInfo) = fileContext.caretContext.leftFileContext.split("\n").takeLast(11).joinToString("\n")
// takeLast NUMBER_OF_LINE_IN_CHUNK of lines (exclusing current line) in left context as the query
fun generateQuery(fileContext: FileContextInfo) = fileContext.caretContext.leftFileContext
.split("\n")
.dropLast(1)
.takeLast(CodeWhispererConstants.CrossFile.NUMBER_OF_LINE_IN_CHUNK)
.joinToString("\n")

companion object {
private val LOG = getLogger<DefaultCodeWhispererFileContextProvider>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.mockito.kotlin.stub
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import software.aws.toolkits.core.utils.test.aStringWithLineCount
import software.aws.toolkits.jetbrains.services.amazonq.CodeWhispererFeatureConfigService
import software.aws.toolkits.jetbrains.services.amazonq.project.EncoderServer
import software.aws.toolkits.jetbrains.services.amazonq.project.InlineBm25Chunk
Expand All @@ -47,6 +48,8 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages
import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererRuby
import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererTsx
import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererTypeScript
import software.aws.toolkits.jetbrains.services.codewhisperer.model.CaretContext
import software.aws.toolkits.jetbrains.services.codewhisperer.model.FileContextInfo
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CrossFileStrategy
import software.aws.toolkits.jetbrains.services.codewhisperer.util.DefaultCodeWhispererFileContextProvider
Expand Down Expand Up @@ -94,6 +97,44 @@ class CodeWhispererFileContextProviderTest {
project.replaceService(ProjectContextController::class.java, mockProjectContext, disposableRule.disposable)
}

@Test
fun `generateQuery should use last 50 lines (excluding the current line) of left context`() {
val fileContext = FileContextInfo(
CaretContext(
leftFileContext = aStringWithLineCount(100),
rightFileContext = "",
leftContextOnCurrentLine = ""
),
"Foo.java",
CodeWhispererJava.INSTANCE,
""
)

val actual = sut.generateQuery(fileContext)
val expected = aStringWithLineCount(lineCount = 50, start = 49)
assertThat(actual).isEqualTo(expected)
assertThat(actual.split("\n").size).isEqualTo(expected.split("\n").size)
}

@Test
fun `generateQuery should use last 50 lines (excluding the current line) of left context if current caret is at the beginning of the line`() {
val fileContext = FileContextInfo(
CaretContext(
leftFileContext = aStringWithLineCount(100) + "\n",
rightFileContext = "",
leftContextOnCurrentLine = ""
),
"Foo.java",
CodeWhispererJava.INSTANCE,
""
)

val actual = sut.generateQuery(fileContext)
val expected = aStringWithLineCount(lineCount = 50, start = 50)
assertThat(actual).isEqualTo(expected)
assertThat(actual.split("\n").size).isEqualTo(expected.split("\n").size)
}

@Test
fun `extractSupplementalFileContext should timeout 50ms`() = runTest {
featureConfigService.stub { on { getInlineCompletion() } doReturn false }
Expand Down
71 changes: 24 additions & 47 deletions plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,54 +453,31 @@ export const createMynahUI = (ideApi: any, featureDevInitEnabled: boolean, codeT
content: 'Thanks for your feedback.',
})
},
onCodeBlockActionClicked: (
tabId: string,
messageId: string,
actionId: string,
data?: string,
code?: string,
type?: CodeSelectionType,
referenceTrackerInformation?: ReferenceTrackerInformation[],
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number
onCodeInsertToCursorPosition: connector.onCodeInsertToCursorPosition,
onCopyCodeToClipboard: (
tabId,
messageId,
code,
type,
referenceTrackerInfo,
eventId,
codeBlockIndex,
totalCodeBlocks
) => {
switch (actionId) {
case 'insert-to-cursor':
connector.onCodeInsertToCursorPosition(
tabId,
messageId,
code,
type,
referenceTrackerInformation,
eventId,
codeBlockIndex,
totalCodeBlocks,
responseMetadata.get(messageId)?.[0] ?? undefined,
responseMetadata.get(messageId)?.[1] ?? undefined
)
break
case 'copy':
connector.onCopyCodeToClipboard(
tabId,
messageId,
code,
type,
referenceTrackerInformation,
eventId,
codeBlockIndex,
totalCodeBlocks,
responseMetadata.get(messageId)?.[0] ?? undefined,
responseMetadata.get(messageId)?.[1] ?? undefined
)
mynahUI.notify({
type: NotificationType.SUCCESS,
content: 'Selected code is copied to clipboard',
})
break
default:
break
}
connector.onCopyCodeToClipboard(
tabId,
messageId,
code,
type,
referenceTrackerInfo,
eventId,
codeBlockIndex,
totalCodeBlocks
)
mynahUI.notify({
type: NotificationType.SUCCESS,
content: 'Selected code is copied to clipboard',
})
},
onChatItemEngagement: connector.triggerSuggestionEngagement,
onSourceLinkClick: (tabId, messageId, link, mouseEvent) => {
Expand Down

This file was deleted.

Loading

0 comments on commit 890089d

Please sign in to comment.