Skip to content

Commit 259606a

Browse files
authored
Revert "fix(amazonq): update Q inline cross file config (#4432)" (#4451)
This reverts commit 02fb061.
1 parent 210c322 commit 259606a

File tree

5 files changed

+49
-90
lines changed

5 files changed

+49
-90
lines changed

.changes/next-release/feature-caf242cd-5a38-4449-a801-719f48b8f7bc.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererConstants.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ object CodeWhispererConstants {
135135
}
136136
}
137137
object CrossFile {
138-
const val CHUNK_SIZE = 200
139-
const val NUMER_OF_LINE_IN_CHUNK = 50
140-
const val NUMBER_OF_CHUNK_TO_FETCH = 10
138+
const val CHUNK_SIZE = 60
141139
}
142140

143141
object Utg {

plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererUtil.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.learn.LearnCodeWhi
3232
import software.aws.toolkits.jetbrains.services.codewhisperer.model.Chunk
3333
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererService
3434
import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.isTelemetryEnabled
35-
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.CrossFile.NUMBER_OF_CHUNK_TO_FETCH
36-
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.CrossFile.NUMER_OF_LINE_IN_CHUNK
3735
import software.aws.toolkits.jetbrains.settings.AwsSettings
3836
import software.aws.toolkits.jetbrains.utils.isQExpired
3937
import software.aws.toolkits.jetbrains.utils.notifyError
@@ -113,13 +111,13 @@ suspend fun String.toCodeChunk(path: String): List<Chunk> {
113111
fun VirtualFile.toCodeChunk(path: String): Sequence<Chunk> = sequence {
114112
var prevChunk: String? = null
115113
inputStream.bufferedReader(Charsets.UTF_8).useLines {
116-
val iter = it.chunked(NUMER_OF_LINE_IN_CHUNK).iterator()
114+
val iter = it.chunked(10).iterator()
117115
while (iter.hasNext()) {
118116
val currentChunk = iter.next().joinToString("\n").trimEnd()
119117

120118
// chunk[0]
121119
if (prevChunk == null) {
122-
val first3Lines = currentChunk.split("\n").take(NUMBER_OF_CHUNK_TO_FETCH).joinToString("\n").trimEnd()
120+
val first3Lines = currentChunk.split("\n").take(3).joinToString("\n").trimEnd()
123121
yield(Chunk(content = first3Lines, path = path, nextChunk = currentChunk))
124122
} else {
125123
// chunk[1]...chunk[n-1]

plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererFileContextProviderTest.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ class CodeWhispererFileContextProviderTest {
7575
ApplicationManager.getApplication().replaceService(CodeWhispererUserGroupSettings::class.java, userGroupSetting, disposableRule.disposable)
7676

7777
whenever(userGroupSetting.getUserGroup()).thenReturn(CodeWhispererUserGroup.Control)
78-
assertThat(CodeWhispererConstants.CrossFile.CHUNK_SIZE).isEqualTo(200)
78+
assertThat(CodeWhispererConstants.CrossFile.CHUNK_SIZE).isEqualTo(60)
7979

8080
whenever(userGroupSetting.getUserGroup()).thenReturn(CodeWhispererUserGroup.CrossFile)
81-
assertThat(CodeWhispererConstants.CrossFile.CHUNK_SIZE).isEqualTo(200)
81+
assertThat(CodeWhispererConstants.CrossFile.CHUNK_SIZE).isEqualTo(60)
8282
}
8383

8484
@Test
@@ -245,7 +245,7 @@ class CodeWhispererFileContextProviderTest {
245245
}
246246

247247
@Test
248-
fun `test extractCodeChunksFromFiles should read files from file producers to get 200 chunks`() {
248+
fun `test extractCodeChunksFromFiles should read files from file producers to get 60 chunks`() {
249249
val psiFiles = setupFixture(fixture)
250250
val virtualFiles = psiFiles.mapNotNull { it.virtualFile }
251251
val javaMainPsiFile = psiFiles.first()
@@ -266,11 +266,6 @@ class CodeWhispererFileContextProviderTest {
266266
"""public class UtilClass {
267267
| public static int util() {};
268268
| public static String util2() {};
269-
| private static void helper() {};
270-
| public static final int constant1;
271-
| public static final int constant2;
272-
| public static final int constant3;
273-
|}
274269
""".trimMargin()
275270
)
276271

@@ -289,8 +284,7 @@ class CodeWhispererFileContextProviderTest {
289284
assertThat(result[2].content).isEqualTo(
290285
"""public class MyController {
291286
| @Get
292-
| public Response getRecommendation(Request: req) {}
293-
|}
287+
| public Response getRecommendation(Request: req) {}
294288
""".trimMargin()
295289
)
296290

plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererUtilTest.kt

Lines changed: 42 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class CodeWhispererUtilTest {
106106
"""public class Main {
107107
| public static void main() {
108108
| }
109-
|}
110109
""".trimMargin()
111110
)
112111
assertThat(result[1].content).isEqualTo(
@@ -120,26 +119,18 @@ class CodeWhispererUtilTest {
120119

121120
@Test
122121
fun `toCodeChunk case_2`() {
123-
val psiFile = fixture.configureByText("Sample.java", codeSample33Lines.repeat(2))
122+
val psiFile = fixture.configureByText("Sample.java", codeSample33Lines)
124123

125124
val result = runBlocking {
126125
psiFile.virtualFile.toCodeChunk("fake/path")
127126
}.toList()
128127

129-
assertThat(result).hasSize(3)
128+
assertThat(result).hasSize(5)
130129

131130
// 0th
132131
assertThat(result[0].content).isEqualTo(
133-
"""|public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
134-
| int middle = low + ((high - low) / 2);
135-
|
136-
| if (high < low) {
137-
| return -1;
138-
| }
139-
|
140-
| if (key == sortedArray[middle]) {
141-
| return middle;
142-
| } else if (key < sortedArray[middle]) {
132+
"""public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
133+
| int middle = low + ((high - low) / 2);
143134
""".trimMargin()
144135
)
145136
assertThat(result[0].path).isEqualTo("fake/path")
@@ -157,72 +148,54 @@ class CodeWhispererUtilTest {
157148
| if (key == sortedArray[middle]) {
158149
| return middle;
159150
| } else if (key < sortedArray[middle]) {
160-
| return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
161-
| } else {
162-
| return runBinarySearchRecursively(sortedArray, key, middle + 1, high);
163-
| }
164-
|}
165-
|
166-
|public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) {
167-
| int index = Integer.MAX_VALUE;
168-
|
169-
| while (low <= high) {
170-
| int mid = low + ((high - low) / 2);
171-
| if (sortedArray[mid] < key) {
172-
| low = mid + 1;
173-
| } else if (sortedArray[mid] > key) {
174-
| high = mid - 1;
175-
| } else if (sortedArray[mid] == key) {
176-
| index = mid;
177-
| break;
178-
| }
179-
| }
180-
|
181-
| return index;
182-
|}
183-
|public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
184-
| int middle = low + ((high - low) / 2);
185-
|
186-
| if (high < low) {
187-
| return -1;
188-
| }
189-
|
190-
| if (key == sortedArray[middle]) {
191-
| return middle;
192-
| } else if (key < sortedArray[middle]) {
193-
| return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
194-
| } else {
195-
| return runBinarySearchRecursively(sortedArray, key, middle + 1, high);
196-
| }
197-
|}
198-
|
199-
|public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) {
200151
""".trimMargin()
201152
)
202153
assertThat(result[1].path).isEqualTo("fake/path")
203154
assertThat(result[1].nextChunk).isEqualTo(result[2].content)
204155

205156
// 2nd
206157
assertThat(result[2].content).isEqualTo(
207-
""" | int index = Integer.MAX_VALUE;
208-
|
209-
| while (low <= high) {
210-
| int mid = low + ((high - low) / 2);
211-
| if (sortedArray[mid] < key) {
212-
| low = mid + 1;
213-
| } else if (sortedArray[mid] > key) {
214-
| high = mid - 1;
215-
| } else if (sortedArray[mid] == key) {
216-
| index = mid;
217-
| break;
218-
| }
219-
| }
220-
|
221-
| return index;
222-
|}
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) {
223168
""".trimMargin()
224169
)
225170
assertThat(result[2].path).isEqualTo("fake/path")
171+
assertThat(result[2].nextChunk).isEqualTo(result[3].content)
172+
173+
// 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+
)
187+
assertThat(result[3].path).isEqualTo("fake/path")
188+
assertThat(result[3].nextChunk).isEqualTo(result[4].content)
189+
190+
// 4th
191+
assertThat(result[4].content).isEqualTo(
192+
"""|
193+
| return index;
194+
|}
195+
""".trimMargin()
196+
)
197+
assertThat(result[4].path).isEqualTo("fake/path")
198+
assertThat(result[4].nextChunk).isEqualTo(result[4].content)
226199
}
227200

228201
@Test

0 commit comments

Comments
 (0)