Skip to content

Commit dcd5ce5

Browse files
committed
fix(completion): offer snippets while indexing
Contributed snippets were missing from completion while the project was indexed: the contributor wasn't dumb-aware, so the platform skipped it. Installing an extension changes file types, which starts indexing, so a snippet test that ran first in its class sometimes got an empty lookup on CI. Snippets are data in their packages and need no index, so they are now offered during indexing too, as VS Code always does. Refs #86
1 parent f2e0dd6 commit dcd5ce5

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/runtime/backend/src/main/kotlin/me/helvert/codebridge/language/CodeBridgeSnippetCompletion.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.intellij.codeInsight.lookup.LookupElement
99
import com.intellij.codeInsight.lookup.LookupElementBuilder
1010
import com.intellij.icons.AllIcons
1111
import com.intellij.openapi.components.service
12+
import com.intellij.openapi.project.DumbAware
1213
import com.intellij.openapi.util.text.StringUtil
1314
import kotlinx.serialization.json.JsonPrimitive
1415
import kotlinx.serialization.json.booleanOrNull
@@ -27,8 +28,11 @@ import me.helvert.codebridge.exthost.protocol.payload.CompletionItem
2728
* Where they rank follows `editor.snippetSuggestions` -- `top`, `bottom`, `inline` among the rest,
2829
* or `none` -- and `editor.suggest.showSnippets` turns them off, as in VS Code. Both are read from the
2930
* workspace settings the extension host has, so they apply once it is running.
31+
*
32+
* Snippets are data in their packages, needing no index, so they are offered while the project is
33+
* indexed too -- which installing an extension starts, by changing file types.
3034
*/
31-
internal class CodeBridgeSnippetCompletion : CompletionContributor() {
35+
internal class CodeBridgeSnippetCompletion : CompletionContributor(), DumbAware {
3236

3337
override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) {
3438
if (parameters.completionType != CompletionType.BASIC) return

‎src/runtime/backend/src/test/kotlin/me/helvert/codebridge/ide/SnippetCompletionTest.kt‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.intellij.openapi.extensions.DefaultPluginDescriptor
99
import com.intellij.openapi.extensions.ExtensionPointName
1010
import com.intellij.openapi.extensions.PluginId
1111
import com.intellij.openapi.vfs.LocalFileSystem
12+
import com.intellij.testFramework.DumbModeTestUtils
1213
import kotlinx.serialization.json.*
1314
import me.helvert.codebridge.extensions.ExtensionInstallationService
1415
import me.helvert.codebridge.language.CodeBridgeSnippetCompletion
@@ -80,6 +81,19 @@ class SnippetCompletionTest : EditorFixture() {
8081
assertEquals(listOf("forr"), fixture.lookupElementStrings)
8182
}
8283

84+
@Test
85+
fun `a snippet is offered while the project is indexed`() = onEdt {
86+
open("fo", "main.snip.txt")
87+
88+
// Installing an extension changes file types, which has the project indexed again.
89+
DumbModeTestUtils.runInDumbModeSynchronously(fixture.project) {
90+
fixture.completeBasic()
91+
92+
// Looked at before the indexing ends, which asks for the lookup again.
93+
assertEquals(listOf("forr"), fixture.lookupElementStrings)
94+
}
95+
}
96+
8397
@Test
8498
fun `a language's snippet is not offered in a file of another language`() = onEdt {
8599
open("fo", "notes.txt")

0 commit comments

Comments
 (0)