Skip to content

Commit 67a2ef9

Browse files
authored
codewhisperer: enable complete .py .js .jsx .ts .tsx crossfile support (#3816)
1 parent f73ab51 commit 67a2ef9

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "feature",
3+
"description" : "CodeWhisperer: Improve file context fetching for Python Typescript Javascript source files"
4+
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererFileContextProvider.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import software.aws.toolkits.core.utils.warn
2323
import software.aws.toolkits.jetbrains.services.codewhisperer.editor.CodeWhispererEditorUtil
2424
import software.aws.toolkits.jetbrains.services.codewhisperer.language.CodeWhispererProgrammingLanguage
2525
import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererJava
26+
import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererJavaScript
27+
import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererJsx
28+
import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererPython
29+
import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererTsx
30+
import software.aws.toolkits.jetbrains.services.codewhisperer.language.languages.CodeWhispererTypeScript
2631
import software.aws.toolkits.jetbrains.services.codewhisperer.language.programmingLanguage
2732
import software.aws.toolkits.jetbrains.services.codewhisperer.model.Chunk
2833
import software.aws.toolkits.jetbrains.services.codewhisperer.model.FileContextInfo
@@ -43,6 +48,7 @@ private val codewhispererCodeChunksIndex = GistManager.getInstance()
4348
FileContextProvider.getInstance(psiFile.project).extractCodeChunksFromFiles(psiFile, fileProducers)
4449
}
4550
}
51+
4652
private object CodeWhispererCodeChunkExternalizer : DataExternalizer<List<Chunk>> {
4753
override fun save(out: DataOutput, value: List<Chunk>) {
4854
out.writeInt(value.size)
@@ -282,7 +288,13 @@ class DefaultCodeWhispererFileContextProvider(private val project: Project) : Fi
282288
}
283289

284290
return when (language) {
285-
is CodeWhispererJava -> true
291+
is CodeWhispererJava,
292+
is CodeWhispererPython,
293+
is CodeWhispererJavaScript,
294+
is CodeWhispererTypeScript,
295+
is CodeWhispererJsx,
296+
is CodeWhispererTsx -> true
297+
286298
else -> userGroup == CodeWhispererUserGroup.CrossFile
287299
}
288300
}

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,44 +124,38 @@ class CodeWhispererFileContextProviderTest {
124124
fun `shouldFetchCrossfileContext - fully support`() {
125125
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererJava.INSTANCE, CodeWhispererUserGroup.CrossFile)).isTrue
126126
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererJava.INSTANCE, CodeWhispererUserGroup.Control)).isTrue
127-
}
128127

129-
@Test
130-
fun `shouldFetchCrossfileContext - partially support`() {
131-
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererPython.INSTANCE, CodeWhispererUserGroup.Control)).isFalse
132128
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererPython.INSTANCE, CodeWhispererUserGroup.CrossFile)).isTrue
129+
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererPython.INSTANCE, CodeWhispererUserGroup.Control)).isTrue
133130

134-
assertThat(
135-
DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(
136-
CodeWhispererJavaScript.INSTANCE,
137-
CodeWhispererUserGroup.Control
138-
)
139-
).isFalse
140131
assertThat(
141132
DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(
142133
CodeWhispererJavaScript.INSTANCE,
143134
CodeWhispererUserGroup.CrossFile
144135
)
145136
).isTrue
137+
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererJavaScript.INSTANCE, CodeWhispererUserGroup.Control)).isTrue
146138

147-
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererJsx.INSTANCE, CodeWhispererUserGroup.Control)).isFalse
148139
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererJsx.INSTANCE, CodeWhispererUserGroup.CrossFile)).isTrue
140+
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererJsx.INSTANCE, CodeWhispererUserGroup.Control)).isTrue
149141

150-
assertThat(
151-
DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(
152-
CodeWhispererTypeScript.INSTANCE,
153-
CodeWhispererUserGroup.Control
154-
)
155-
).isFalse
156142
assertThat(
157143
DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(
158144
CodeWhispererTypeScript.INSTANCE,
159145
CodeWhispererUserGroup.CrossFile
160146
)
161147
).isTrue
148+
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererTypeScript.INSTANCE, CodeWhispererUserGroup.Control)).isTrue
162149

163-
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererTsx.INSTANCE, CodeWhispererUserGroup.Control)).isFalse
164150
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererTsx.INSTANCE, CodeWhispererUserGroup.CrossFile)).isTrue
151+
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererTsx.INSTANCE, CodeWhispererUserGroup.Control)).isTrue
152+
}
153+
154+
@Ignore("Reenable this once we have any partial support language")
155+
@Test
156+
fun `shouldFetchCrossfileContext - partially support`() {
157+
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererPython.INSTANCE, CodeWhispererUserGroup.Control)).isFalse
158+
assertThat(DefaultCodeWhispererFileContextProvider.shouldFetchCrossfileContext(CodeWhispererPython.INSTANCE, CodeWhispererUserGroup.CrossFile)).isTrue
165159
}
166160

167161
@Test

0 commit comments

Comments
 (0)