Skip to content

Commit 6082169

Browse files
authored
Merge branch 'main' into manodnyb/adduiclicksignout
2 parents 690432d + c8cec7f commit 6082169

File tree

8 files changed

+71
-126
lines changed

8 files changed

+71
-126
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix error occuring when Amazon Q attempts to show UI hints on manually triggerred inline suggestion (#4929)"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix 'Slow operations are prohibited on EDT.' when Amazon Q is determining if a file supports inline suggestions (#4823)"
4+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ tasks.runIde {
7070
systemProperty("ide.plugins.snapshot.on.unload.fail", true)
7171
systemProperty("memory.snapshots.path", project.rootDir)
7272
systemProperty("idea.auto.reload.plugins", false)
73+
74+
val home = project.layout.buildDirectory.dir("USER_HOME").get()
75+
systemProperty("user.home", home)
76+
environment("HOME", home)
7377
}

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.intellij.openapi.editor.event.DocumentEvent
88
import com.intellij.openapi.editor.event.EditorFactoryEvent
99
import com.intellij.openapi.editor.event.EditorFactoryListener
1010
import com.intellij.openapi.editor.impl.EditorImpl
11-
import com.intellij.psi.PsiDocumentManager
11+
import com.intellij.openapi.fileEditor.FileDocumentManager
1212
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.isCodeWhispererEnabled
1313
import software.aws.toolkits.jetbrains.services.codewhisperer.language.programmingLanguage
1414
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatus
@@ -17,27 +17,26 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeWhis
1717
class CodeWhispererEditorListener : EditorFactoryListener {
1818
override fun editorCreated(event: EditorFactoryEvent) {
1919
val editor = (event.editor as? EditorImpl) ?: return
20-
editor.project?.let { project ->
21-
PsiDocumentManager.getInstance(project).getPsiFile(editor.document)?.programmingLanguage() ?. let { language ->
22-
// If language is not supported by CodeWhisperer, no action needed
23-
if (!language.isCodeCompletionSupported()) return
24-
// If language is supported, install document listener for CodeWhisperer service
25-
editor.document.addDocumentListener(
26-
object : BulkAwareDocumentListener {
27-
// TODO: Track only deletion changes within the current 5-min interval which will give
28-
// the most accurate code percentage data.
29-
override fun documentChanged(event: DocumentEvent) {
30-
if (!isCodeWhispererEnabled(project)) return
31-
CodeWhispererInvocationStatus.getInstance().documentChanged()
32-
CodeWhispererCodeCoverageTracker.getInstance(project, language).apply {
33-
activateTrackerIfNotActive()
34-
documentChanged(event)
35-
}
36-
}
37-
},
38-
editor.disposable
39-
)
40-
}
41-
}
20+
val project = editor.project ?: return
21+
22+
val language = FileDocumentManager.getInstance().getFile(editor.document)?.programmingLanguage() ?: return
23+
// If language is not supported by CodeWhisperer, no action needed
24+
if (!language.isCodeCompletionSupported()) return
25+
// If language is supported, install document listener for CodeWhisperer service
26+
editor.document.addDocumentListener(
27+
object : BulkAwareDocumentListener {
28+
// TODO: Track only deletion changes within the current 5-min interval which will give
29+
// the most accurate code percentage data.
30+
override fun documentChanged(event: DocumentEvent) {
31+
if (!isCodeWhispererEnabled(project)) return
32+
CodeWhispererInvocationStatus.getInstance().documentChanged()
33+
CodeWhispererCodeCoverageTracker.getInstance(project, language).apply {
34+
activateTrackerIfNotActive()
35+
documentChanged(event)
36+
}
37+
}
38+
},
39+
editor.disposable
40+
)
4241
}
4342
}

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,8 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
409409
if (requestContext.triggerTypeInfo.triggerType == CodewhispererTriggerType.OnDemand) {
410410
// We should only show error hint when CodeWhisperer popup is not visible,
411411
// and make it silent if CodeWhisperer popup is showing.
412-
runInEdt {
413-
if (!CodeWhispererInvocationStatus.getInstance().isPopupActive()) {
414-
showCodeWhispererErrorHint(requestContext.editor, displayMessage)
415-
}
412+
if (!CodeWhispererInvocationStatus.getInstance().isPopupActive()) {
413+
showCodeWhispererErrorHint(requestContext.editor, displayMessage)
416414
}
417415
}
418416
}
@@ -754,12 +752,16 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
754752
return true
755753
}
756754

757-
fun showCodeWhispererInfoHint(editor: Editor, message: String) {
758-
HintManager.getInstance().showInformationHint(editor, message, HintManager.UNDER)
755+
private fun showCodeWhispererInfoHint(editor: Editor, message: String) {
756+
runInEdt {
757+
HintManager.getInstance().showInformationHint(editor, message, HintManager.UNDER)
758+
}
759759
}
760760

761-
fun showCodeWhispererErrorHint(editor: Editor, message: String) {
762-
HintManager.getInstance().showErrorHint(editor, message, HintManager.UNDER)
761+
private fun showCodeWhispererErrorHint(editor: Editor, message: String) {
762+
runInEdt {
763+
HintManager.getInstance().showErrorHint(editor, message, HintManager.UNDER)
764+
}
763765
}
764766

765767
override fun dispose() {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ object CodeWhispererConstants {
133133
}
134134
object CrossFile {
135135
const val CHUNK_SIZE = 60
136-
const val NUMBER_OF_LINE_IN_CHUNK = 10
136+
const val NUMBER_OF_LINE_IN_CHUNK = 50
137137
const val NUMBER_OF_CHUNK_TO_FETCH = 3
138138
}
139139

plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererUtilTest.kt

Lines changed: 20 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.junit.Test
1414
import software.amazon.awssdk.regions.Region
1515
import software.amazon.awssdk.services.codewhispererruntime.model.OptOutPreference
1616
import software.amazon.awssdk.services.ssooidc.SsoOidcClient
17+
import software.aws.toolkits.core.utils.test.aStringWithLineCount
1718
import software.aws.toolkits.jetbrains.core.MockClientManagerRule
1819
import software.aws.toolkits.jetbrains.core.credentials.LegacyManagedBearerSsoConnection
1920
import software.aws.toolkits.jetbrains.core.credentials.sono.Q_SCOPES
@@ -119,83 +120,45 @@ class CodeWhispererUtilTest {
119120

120121
@Test
121122
fun `toCodeChunk case_2`() {
122-
val psiFile = fixture.configureByText("Sample.java", codeSample33Lines)
123+
val fakeCodeWith210Lines = aStringWithLineCount(210)
124+
val psiFile = fixture.configureByText("Sample.java", fakeCodeWith210Lines)
123125

124126
val result = runBlocking {
125127
psiFile.virtualFile.toCodeChunk("fake/path")
126128
}.toList()
127129

128-
assertThat(result).hasSize(5)
130+
// 210 / 50 + 2
131+
assertThat(result).hasSize(6)
129132

130133
// 0th
131-
assertThat(result[0].content).isEqualTo(
132-
"""public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
133-
| int middle = low + ((high - low) / 2);
134-
""".trimMargin()
135-
)
134+
assertThat(result[0].content).isEqualTo(aStringWithLineCount(3))
136135
assertThat(result[0].path).isEqualTo("fake/path")
137-
assertThat(result[0].nextChunk).isEqualTo(result[1].content)
136+
assertThat(result[0].nextChunk).isEqualTo(aStringWithLineCount(50, start = 0))
138137

139138
// 1st
140-
assertThat(result[1].content).isEqualTo(
141-
"""|public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
142-
| int middle = low + ((high - low) / 2);
143-
|
144-
| if (high < low) {
145-
| return -1;
146-
| }
147-
|
148-
| if (key == sortedArray[middle]) {
149-
| return middle;
150-
| } else if (key < sortedArray[middle]) {
151-
""".trimMargin()
152-
)
139+
assertThat(result[1].content).isEqualTo(aStringWithLineCount(50, start = 0))
153140
assertThat(result[1].path).isEqualTo("fake/path")
154-
assertThat(result[1].nextChunk).isEqualTo(result[2].content)
141+
assertThat(result[1].nextChunk).isEqualTo(aStringWithLineCount(50, start = 50))
155142

156143
// 2nd
157-
assertThat(result[2].content).isEqualTo(
158-
"""| return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
159-
| } else {
160-
| return runBinarySearchRecursively(sortedArray, key, middle + 1, high);
161-
| }
162-
|}
163-
|
164-
|public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) {
165-
| int index = Integer.MAX_VALUE;
166-
|
167-
| while (low <= high) {
168-
""".trimMargin()
169-
)
144+
assertThat(result[2].content).isEqualTo(aStringWithLineCount(50, start = 50))
170145
assertThat(result[2].path).isEqualTo("fake/path")
171-
assertThat(result[2].nextChunk).isEqualTo(result[3].content)
146+
assertThat(result[2].nextChunk).isEqualTo(aStringWithLineCount(50, start = 100))
172147

173148
// 3rd
174-
assertThat(result[3].content).isEqualTo(
175-
"""| int mid = low + ((high - low) / 2);
176-
| if (sortedArray[mid] < key) {
177-
| low = mid + 1;
178-
| } else if (sortedArray[mid] > key) {
179-
| high = mid - 1;
180-
| } else if (sortedArray[mid] == key) {
181-
| index = mid;
182-
| break;
183-
| }
184-
| }
185-
""".trimMargin()
186-
)
149+
assertThat(result[3].content).isEqualTo(aStringWithLineCount(50, start = 100))
187150
assertThat(result[3].path).isEqualTo("fake/path")
188-
assertThat(result[3].nextChunk).isEqualTo(result[4].content)
151+
assertThat(result[3].nextChunk).isEqualTo(aStringWithLineCount(50, start = 150))
189152

190153
// 4th
191-
assertThat(result[4].content).isEqualTo(
192-
"""|
193-
| return index;
194-
|}
195-
""".trimMargin()
196-
)
154+
assertThat(result[4].content).isEqualTo(aStringWithLineCount(50, start = 150))
197155
assertThat(result[4].path).isEqualTo("fake/path")
198-
assertThat(result[4].nextChunk).isEqualTo(result[4].content)
156+
assertThat(result[4].nextChunk).isEqualTo(aStringWithLineCount(10, start = 200))
157+
158+
// 5th
159+
assertThat(result[5].content).isEqualTo(aStringWithLineCount(10, start = 200))
160+
assertThat(result[5].path).isEqualTo("fake/path")
161+
assertThat(result[5].nextChunk).isEqualTo(aStringWithLineCount(10, start = 200))
199162
}
200163

201164
@Test
@@ -230,40 +193,3 @@ class CodeWhispererUtilTest {
230193
assertThat(getTelemetryOptOutPreference()).isEqualTo(OptOutPreference.OPTOUT)
231194
}
232195
}
233-
234-
private val codeSample33Lines =
235-
"""public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
236-
| int middle = low + ((high - low) / 2);
237-
|
238-
| if (high < low) {
239-
| return -1;
240-
| }
241-
|
242-
| if (key == sortedArray[middle]) {
243-
| return middle;
244-
| } else if (key < sortedArray[middle]) {
245-
| return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
246-
| } else {
247-
| return runBinarySearchRecursively(sortedArray, key, middle + 1, high);
248-
| }
249-
|}
250-
|
251-
|public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) {
252-
| int index = Integer.MAX_VALUE;
253-
|
254-
| while (low <= high) {
255-
| int mid = low + ((high - low) / 2);
256-
| if (sortedArray[mid] < key) {
257-
| low = mid + 1;
258-
| } else if (sortedArray[mid] > key) {
259-
| high = mid - 1;
260-
| } else if (sortedArray[mid] == key) {
261-
| index = mid;
262-
| break;
263-
| }
264-
| }
265-
|
266-
| return index;
267-
|}
268-
|
269-
""".trimMargin()

plugins/core/core/tst/software/aws/toolkits/core/utils/test/TestUtils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import kotlin.random.Random
1111

1212
fun aString(length: Int = Random.nextInt(5, 30)): String = UUID.randomUUID().toString().substring(length)
1313

14+
fun aStringWithLineCount(lineCount: Int, start: Int = 0): String = buildString {
15+
for (i in start until start + lineCount) {
16+
append("line$i\n")
17+
}
18+
}.trimEnd()
19+
1420
fun retryableAssert(
1521
timeout: Duration? = null,
1622
maxAttempts: Int? = null,

0 commit comments

Comments
 (0)