Skip to content

Commit

Permalink
Use utility class to resolve data type references
Browse files Browse the repository at this point in the history
  • Loading branch information
jbartok committed Feb 18, 2025
1 parent 6047401 commit d59b830
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -513,25 +513,27 @@ private class ValueFactoryIndex(storeEntry: DocumentStoreEntry) {

private fun indexValueFactories(analysisSchema: AnalysisSchema, type: DataClass, namePrefix: String): Map<FqName, List<LabelAndInsertText>> {
val factoryIndex = mutableMapOf<FqName, List<LabelAndInsertText>>()

type.memberFunctions
.filter { it.semantics is FunctionSemantics.Pure && it.returnValueType is DataTypeRef.Name }
.forEach {
val indexKey = (it.returnValueType as DataTypeRef.Name).fqName
val labelAndInsertText = LabelAndInsertText("$namePrefix${computeCompletionLabel(it)}", "$namePrefix${computeCompletionInsertText(it, analysisSchema)}")
factoryIndex.merge(indexKey, listOf(labelAndInsertText)) { oldVal, newVal -> oldVal + newVal }
}
type.properties.filter { it.valueType is DataTypeRef.Name }.forEach {
when (val propType = analysisSchema.dataClassTypesByFqName[(it.valueType as DataTypeRef.Name).fqName]) {

val typeRefContext = SchemaTypeRefContext(analysisSchema)
type.properties.forEach {
when (val propType = typeRefContext.resolveRef(it.valueType)) {
is DataClass -> {
val propName = it.name
val propIndex = indexValueFactories(analysisSchema, propType, "$namePrefix${propName}.")
propIndex.forEach { (key, value) -> factoryIndex.merge(key, value) { oldVal, newVal -> oldVal + newVal } }
}

is EnumClass -> Unit
null -> Unit
else -> Unit
}
}

return factoryIndex
}
}
Expand Down

0 comments on commit d59b830

Please sign in to comment.