Skip to content

Commit

Permalink
Merge pull request #1041 from Kotlin/ide-declaration-resolve-fix
Browse files Browse the repository at this point in the history
Map transformed calls and generated properties to their origin
  • Loading branch information
koperagen authored Jan 31, 2025
2 parents e493477 + 48dab7a commit a6a11ab
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.kotlinx.dataframe.plugin.extensions

import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlinx.dataframe.plugin.extensions.impl.SchemaProperty
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirDeclarationDataKey
Expand All @@ -9,7 +10,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
sealed interface CallShapeData {
class Schema(val columns: List<SchemaProperty>) : CallShapeData

class Scope(val columns: List<SchemaProperty>) : CallShapeData
class Scope(val columns: List<SchemaProperty>, val source: KtSourceElement?) : CallShapeData

class RefinedType(val scopes: List<FirRegularClassSymbol>) : CallShapeData
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class FunctionCallTransformer(
return if (element is FirResolvedNamedReference) {
@Suppress("UNCHECKED_CAST")
buildResolvedNamedReference {
source = call.calleeReference.source
this.name = element.name
resolvedSymbol = originalSymbol
} as E
Expand Down Expand Up @@ -555,7 +556,7 @@ class FunctionCallTransformer(
}
}
schema.callShapeData = CallShapeData.Schema(properties)
scope.callShapeData = CallShapeData.Scope(properties)
scope.callShapeData = CallShapeData.Scope(properties, call.calleeReference.source)
val schemaApi = DataSchemaApi(schema, scope)
dataSchemaApis.add(schemaApi)
return schemaApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ class TokenGenerator(session: FirSession) : FirDeclarationGenerationExtension(se
val callableId = CallableId(k.classId, propertyName.identifier)
val dataRowExtension = generateExtensionProperty(
callableId = callableId,
symbol = k,
receiverType = ConeClassLikeTypeImpl(
ConeClassLikeLookupTagImpl(Names.DATA_ROW_CLASS_ID),
typeArguments = arrayOf(schemaProperty.marker),
isNullable = false
),
propertyName = propertyName,
returnTypeRef = schemaProperty.dataRowReturnType.toFirResolvedTypeRef(),
effectiveVisibility = EffectiveVisibility.Local
symbol = k,
effectiveVisibility = EffectiveVisibility.Local,
source = callShapeData.source
)

val columnContainerExtension = generateExtensionProperty(
Expand All @@ -80,7 +81,8 @@ class TokenGenerator(session: FirSession) : FirDeclarationGenerationExtension(se
propertyName = propertyName,
returnTypeRef = schemaProperty.columnContainerReturnType.toFirResolvedTypeRef(),
symbol = k,
effectiveVisibility = EffectiveVisibility.Local
effectiveVisibility = EffectiveVisibility.Local,
source = callShapeData.source
)
propertyName.identifier to listOf(dataRowExtension, columnContainerExtension)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class TopLevelExtensionsGenerator(session: FirSession) : FirDeclarationGeneratio
isNullable = false
),
propertyName = PropertyName.of(name, columnName?.let { PropertyName.buildAnnotation(it) }),
returnTypeRef = resolvedReturnTypeRef
returnTypeRef = resolvedReturnTypeRef,
source = owner.source
)

val columnReturnType = when {
Expand All @@ -142,7 +143,8 @@ class TopLevelExtensionsGenerator(session: FirSession) : FirDeclarationGeneratio
isNullable = false
),
propertyName = PropertyName.of(name, columnName?.let { PropertyName.buildAnnotation(it) }),
returnTypeRef = columnReturnType
returnTypeRef = columnReturnType,
source = owner.source
)
listOf(rowExtension.symbol, columnsContainerExtension.symbol)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.kotlinx.dataframe.plugin.utils

import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.descriptors.EffectiveVisibility
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibilities
Expand Down Expand Up @@ -30,10 +31,12 @@ internal fun FirDeclarationGenerationExtension.generateExtensionProperty(
propertyName: PropertyName,
returnTypeRef: FirResolvedTypeRef,
symbol: FirClassSymbol<*>? = null,
effectiveVisibility: EffectiveVisibility = EffectiveVisibility.Public
effectiveVisibility: EffectiveVisibility = EffectiveVisibility.Public,
source: KtSourceElement?
): FirProperty {
val firPropertySymbol = FirPropertySymbol(callableId)
return buildProperty {
this.source = source
propertyName.columnNameAnnotation?.let {
annotations += it
}
Expand Down

0 comments on commit a6a11ab

Please sign in to comment.