Skip to content

Commit 2f7d008

Browse files
author
Matthew McGarvey
committed
narrow check to require companion of enums and extract method
1 parent f157463 commit 2f7d008

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private fun completeMembers(file: CompiledFile, cursor: Int, receiverExpr: KtExp
182182
val members = receiverType.memberScope.getContributedDescriptors().asSequence()
183183
val extensions = extensionFunctions(lexicalScope).filter { isExtensionFor(receiverType, it) }
184184
descriptors = members + extensions
185-
if (!DescriptorUtils.isCompanionObject(TypeUtils.getClassDescriptor(receiverType))) {
185+
if (!isCompanionOfEnum(receiverType)) {
186186
return descriptors
187187
}
188188
}
@@ -200,6 +200,15 @@ private fun completeMembers(file: CompiledFile, cursor: Int, receiverExpr: KtExp
200200
return emptySequence()
201201
}
202202

203+
private fun isCompanionOfEnum(kotlinType: KotlinType): Boolean {
204+
val classDescriptor = TypeUtils.getClassDescriptor(kotlinType)
205+
val isCompanion = DescriptorUtils.isCompanionObject(classDescriptor)
206+
if (!isCompanion) {
207+
return false
208+
}
209+
return DescriptorUtils.isEnumClass(classDescriptor?.containingDeclaration)
210+
}
211+
203212
private fun findPartialIdentifier(file: CompiledFile, cursor: Int): String {
204213
val line = file.lineBefore(cursor)
205214
if (line.matches(Regex(".*\\."))) return ""

0 commit comments

Comments
 (0)