@@ -141,6 +141,8 @@ private fun completableElement(file: CompiledFile, cursor: Int): KtElement? {
141
141
val el = file.parseAtPoint(cursor - 1 ) ? : return null
142
142
// import x.y.?
143
143
return el.findParent<KtImportDirective >()
144
+ // package x.y.?
145
+ ? : el.findParent<KtPackageDirective >()
144
146
// :?
145
147
? : el.parent as ? KtTypeElement
146
148
// .?
@@ -168,6 +170,18 @@ private fun elementCompletions(file: CompiledFile, cursor: Int, surroundingEleme
168
170
val parentPackage = module.getPackage(FqName .fromSegments(parent.split(' .' )))
169
171
parentPackage.memberScope.getContributedDescriptors().asSequence()
170
172
}
173
+ // package x.y.?
174
+ is KtPackageDirective -> {
175
+ LOG .info(" Completing package '{}'" , surroundingElement.text)
176
+ val module = file.container.get<ModuleDescriptor >()
177
+ val match = Regex (" package ((\\ w+\\ .)*)[\\ w*]*" ).matchEntire(surroundingElement.text)
178
+ ? : return doesntLookLikePackage(surroundingElement)
179
+ val parentDot = if (match.groupValues[1 ].isNotBlank()) match.groupValues[1 ] else " ."
180
+ val parent = parentDot.substring(0 , parentDot.length - 1 )
181
+ LOG .debug(" Looking for members of package '{}'" , parent)
182
+ val parentPackage = module.getPackage(FqName .fromSegments(parent.split(' .' )))
183
+ parentPackage.memberScope.getDescriptorsFiltered(DescriptorKindFilter .PACKAGES ).asSequence()
184
+ }
171
185
// :?
172
186
is KtTypeElement -> {
173
187
// : Outer.?
@@ -474,6 +488,12 @@ private fun doesntLookLikeImport(importDirective: KtImportDirective): Sequence<D
474
488
return emptySequence()
475
489
}
476
490
491
+ private fun doesntLookLikePackage (packageDirective : KtPackageDirective ): Sequence <DeclarationDescriptor > {
492
+ LOG .debug(" {} doesn't look like package a.b..." , packageDirective.text)
493
+
494
+ return emptySequence()
495
+ }
496
+
477
497
private fun empty (message : String ): CompletionList {
478
498
LOG .debug(message)
479
499
0 commit comments