Skip to content

Commit 1d2e422

Browse files
committed
feat(completion): improve file reference completion support #101
The completion system for the DevInT language has been enhanced to provide better support for file references. The previous approach, which used a regex-based pattern matching, has been replaced with a more robust and specific pattern that captures file references. This change ensures that completion suggestions are more accurate and relevant to the user's context. Additionally, a new provider class, `FileReferenceLanguageProvider`, has been introduced to handle the completion of file references. This class is responsible for providing a list of possible file names based on a predefined list, which is a common scenario in many programming languages. The new provider is more efficient and easier to maintain, as it separates the logic for file reference completion from the general completion logic.
1 parent a3b37a1 commit 1d2e422

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

exts/devin-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/DevInCompletionContributor.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ class DevInCompletionContributor : CompletionContributor() {
1717
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.LANGUAGE_ID), CodeFenceLanguageProvider())
1818
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.VARIABLE_ID), CustomVariableProvider())
1919
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DevInTypes.AGENT_ID), BuiltinAgentProvider())
20-
extend(CompletionType.BASIC, filePattern(), CodeFenceLanguageProvider())
20+
extend(
21+
CompletionType.BASIC,
22+
valuePattern(FileReferenceLanguageProvider.REF_TYPE),
23+
FileReferenceLanguageProvider()
24+
)
2125
}
2226

2327
override fun beforeCompletion(context: CompletionInitializationContext) {
@@ -34,8 +38,11 @@ class DevInCompletionContributor : CompletionContributor() {
3438
PlatformPatterns.psiElement()
3539
.inside(psiElement<DevInUsed>())
3640

37-
private fun filePattern(): PsiElementPattern.Capture<PsiElement> =
41+
private fun valuePattern(text: String): PsiElementPattern.Capture<PsiElement> =
3842
baseUsedPattern()
39-
.withElementType(DevInTypes.COLON)
40-
43+
.withElementType(DevInTypes.PROPERTY_VALUE)
44+
.afterLeafSkipping(
45+
PlatformPatterns.psiElement(DevInTypes.COLON),
46+
PlatformPatterns.psiElement().withText(text)
47+
)
4148
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cc.unitmesh.devti.language.completion
2+
3+
import com.intellij.codeInsight.completion.CompletionParameters
4+
import com.intellij.codeInsight.completion.CompletionProvider
5+
import com.intellij.codeInsight.completion.CompletionResultSet
6+
import com.intellij.codeInsight.lookup.LookupElementBuilder
7+
import com.intellij.util.ProcessingContext
8+
9+
class FileReferenceLanguageProvider : CompletionProvider<CompletionParameters>() {
10+
companion object {
11+
const val REF_TYPE = "file"
12+
}
13+
14+
override fun addCompletions(
15+
parameters: CompletionParameters,
16+
context: ProcessingContext,
17+
result: CompletionResultSet,
18+
) {
19+
// sample file: "file1", "file2"
20+
listOf("file1", "file2").forEach {
21+
result.addElement(
22+
LookupElementBuilder.create(it)
23+
.withTypeText("file", true)
24+
)
25+
}
26+
}
27+
28+
}

0 commit comments

Comments
 (0)