Skip to content

Commit 32bf931

Browse files
committed
feat(completion): improve file reference provider with project file index #101
The completion provider for file references has been enhanced to use the project file index, which allows for more accurate and efficient completion suggestions. This change ensures that only relevant files within the project are considered, improving the user experience.
1 parent a2e96b6 commit 32bf931

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package cc.unitmesh.devti.language.completion
22

3-
import com.intellij.codeInsight.completion.*
3+
import com.intellij.codeInsight.completion.CompletionParameters
4+
import com.intellij.codeInsight.completion.CompletionProvider
5+
import com.intellij.codeInsight.completion.CompletionResultSet
46
import com.intellij.codeInsight.lookup.LookupElementBuilder
57
import com.intellij.ide.presentation.VirtualFilePresentation
68
import com.intellij.openapi.fileEditor.impl.EditorHistoryManager
79
import com.intellij.openapi.project.guessProjectDir
10+
import com.intellij.openapi.roots.ProjectFileIndex
811
import com.intellij.util.ProcessingContext
912
import java.io.File
1013

@@ -33,5 +36,22 @@ class FileReferenceLanguageProvider : CompletionProvider<CompletionParameters>()
3336

3437
result.addElement(element)
3538
}
39+
40+
val projectFileIndex = ProjectFileIndex.getInstance(project)
41+
projectFileIndex.iterateContent {
42+
val removePrefix = it.path.removePrefix(basePath)
43+
val relativePath: String = removePrefix.removePrefix(File.separator)
44+
45+
val element = LookupElementBuilder.create(relativePath)
46+
.withIcon(VirtualFilePresentation.getIcon(it))
47+
.withInsertHandler { context, _ ->
48+
context.editor.caretModel.moveCaretRelatively(
49+
1, 0, false, false, false
50+
)
51+
}
52+
53+
result.addElement(element)
54+
true
55+
}
3656
}
3757
}

0 commit comments

Comments
 (0)