Skip to content

Commit 8306dd7

Browse files
committed
Handle wildcard imports in index completions
1 parent 109f91e commit 8306dd7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

server/src/main/kotlin/org/javacs/kt/completion/Completions.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,22 @@ fun completions(file: CompiledFile, cursor: Int, index: SymbolIndex, config: Com
8282

8383
/** Finds completions in the global symbol index, for potentially unimported symbols. */
8484
private fun indexCompletionItems(parsedFile: KtFile, index: SymbolIndex, partial: String): Sequence<CompletionItem> {
85-
val importedNames = parsedFile.importDirectives.mapNotNull { it.importedFqName?.shortName() }.toSet()
85+
val imports = parsedFile.importDirectives
86+
// TODO: Deal with alias imports
87+
val wildcardPackages = imports
88+
.mapNotNull { it.importPath }
89+
.filter { it.isAllUnder }
90+
.map { it.fqName }
91+
.toSet()
92+
val importedNames = imports
93+
.mapNotNull { it.importedFqName?.shortName() }
94+
.toSet()
8695

8796
return index
8897
.query(partial, limit = MAX_COMPLETION_ITEMS)
8998
.asSequence()
9099
.filter { it.kind != Symbol.Kind.MODULE } // Ignore global module/package name completions for now, since they cannot be 'imported'
91-
.filter { it.fqName.shortName() !in importedNames }
100+
.filter { it.fqName.shortName() !in importedNames && it.fqName.parent() !in wildcardPackages }
92101
.filter {
93102
// TODO: Visibility checker should be less liberal
94103
it.visibility == Symbol.Visibility.PUBLIC

0 commit comments

Comments
 (0)