|
1 | 1 | package cc.unitmesh.devti.language.completion
|
2 | 2 |
|
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 |
4 | 6 | import com.intellij.codeInsight.lookup.LookupElementBuilder
|
5 | 7 | import com.intellij.ide.presentation.VirtualFilePresentation
|
6 | 8 | import com.intellij.openapi.fileEditor.impl.EditorHistoryManager
|
7 | 9 | import com.intellij.openapi.project.guessProjectDir
|
| 10 | +import com.intellij.openapi.roots.ProjectFileIndex |
8 | 11 | import com.intellij.util.ProcessingContext
|
9 | 12 | import java.io.File
|
10 | 13 |
|
@@ -33,5 +36,22 @@ class FileReferenceLanguageProvider : CompletionProvider<CompletionParameters>()
|
33 | 36 |
|
34 | 37 | result.addElement(element)
|
35 | 38 | }
|
| 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 | + } |
36 | 56 | }
|
37 | 57 | }
|
0 commit comments