Skip to content

Commit 8ae9414

Browse files
authored
KRPC-167 Internal symbols are the first completion candidate in projects where kxrpc is configured (#305)
1 parent ddeab6f commit 8ae9414

File tree

51 files changed

+258
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+258
-257
lines changed

compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ internal class RpcIrContext(
169169
}
170170

171171
val dataCast by lazy {
172-
namedFunction("kotlinx.rpc.internal", "dataCast")
172+
namedFunction("kotlinx.rpc.internal", "rpcInternalDataCast")
173173
}
174174

175175
val rpcClientCall by lazy {

core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ public inline fun <@Rpc reified T : Any> serviceDescriptorOf(): RpcServiceDescri
1919

2020
@ExperimentalRpcApi
2121
public fun <@Rpc T : Any> serviceDescriptorOf(kType: KType): RpcServiceDescriptor<T> {
22-
return serviceDescriptorOf(kType.kClass())
22+
return serviceDescriptorOf(kType.rpcInternalKClass())
2323
}
2424

2525
@ExperimentalRpcApi
2626
public fun <@Rpc T : Any> serviceDescriptorOf(kClass: KClass<T>): RpcServiceDescriptor<T> {
2727
val maybeDescriptor = internalServiceDescriptorOf(kClass)
28-
?: internalError("Unable to find a service descriptor of the $kClass")
28+
?: internalRpcError("Unable to find a service descriptor of the $kClass")
2929

3030
if (maybeDescriptor is RpcServiceDescriptor<*>) {
3131
@Suppress("UNCHECKED_CAST")
3232
return maybeDescriptor as RpcServiceDescriptor<T>
3333
}
3434

35-
internalError(
35+
internalRpcError(
3636
"Located descriptor object is not of a desired type ${RpcServiceDescriptor::class}, " +
3737
"instead found $maybeDescriptor of the class " +
38-
(maybeDescriptor::class.qualifiedClassNameOrNull ?: maybeDescriptor::class)
38+
(maybeDescriptor::class.rpcInternalQualifiedClassNameOrNull ?: maybeDescriptor::class)
3939
)
4040
}
4141

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.internal
@@ -10,24 +10,24 @@ import kotlin.reflect.KType
1010

1111
@InternalRpcApi
1212
@Suppress("UNCHECKED_CAST")
13-
public fun <T : Any> KType.kClass(): KClass<T> {
13+
public fun <T : Any> KType.rpcInternalKClass(): KClass<T> {
1414
val classifier = classifier ?: error("Expected denotable type, found $this")
1515
val classifierClass = classifier as? KClass<*> ?: error("Expected class type, found $this")
1616

1717
return classifierClass as KClass<T>
1818
}
1919

2020
@InternalRpcApi
21-
public fun internalError(message: String): Nothing {
21+
public fun internalRpcError(message: String): Nothing {
2222
error("Internal kotlinx.rpc error: $message")
2323
}
2424

2525
@InternalRpcApi
26-
public expect val KClass<*>.typeName: String?
26+
public expect val KClass<*>.rpcInternalTypeName: String?
2727

2828
@InternalRpcApi
29-
public expect val KClass<*>.qualifiedClassNameOrNull: String?
29+
public expect val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
3030

3131
@InternalRpcApi
32-
public val KClass<*>.qualifiedClassName: String get() = qualifiedClassNameOrNull
32+
public val KClass<*>.rpcInternalQualifiedClassName: String get() = rpcInternalQualifiedClassNameOrNull
3333
?: error("Expected qualifiedClassName for $this")

core/src/commonMain/kotlin/kotlinx/rpc/internal/dataCast.kt renamed to core/src/commonMain/kotlin/kotlinx/rpc/internal/rpcInternalDataCast.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.internal
66

77
import kotlinx.rpc.internal.utils.InternalRpcApi
88

99
@InternalRpcApi
10-
public inline fun <reified T> Any?.dataCast(methodName: String, serviceName: String): T {
10+
public inline fun <reified T> Any?.rpcInternalDataCast(methodName: String, serviceName: String): T {
1111
return this as? T
1212
?: throw IllegalArgumentException(
1313
"Wrong data type for $methodName in service $serviceName. " +

core/src/commonMain/kotlin/kotlinx/rpc/withService.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc
66

77
import kotlinx.atomicfu.atomic
88
import kotlinx.rpc.annotations.Rpc
99
import kotlinx.rpc.descriptor.serviceDescriptorOf
10-
import kotlinx.rpc.internal.kClass
10+
import kotlinx.rpc.internal.rpcInternalKClass
1111
import kotlin.reflect.KClass
1212
import kotlin.reflect.KType
1313

@@ -33,7 +33,7 @@ public inline fun <@Rpc reified T : Any> RpcClient.withService(): T {
3333
* @return instance of the generated service.
3434
*/
3535
public fun <@Rpc T : Any> RpcClient.withService(serviceKType: KType): T {
36-
return withService(serviceKType.kClass())
36+
return withService(serviceKType.rpcInternalKClass())
3737
}
3838

3939
/**
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("detekt.MatchingDeclarationName")
@@ -10,9 +10,9 @@ import kotlinx.rpc.internal.utils.InternalRpcApi
1010
import kotlin.reflect.KClass
1111

1212
@InternalRpcApi
13-
public actual val KClass<*>.qualifiedClassNameOrNull: String?
13+
public actual val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
1414
get() = toString()
1515

1616
@InternalRpcApi
17-
public actual val KClass<*>.typeName: String?
18-
get() = qualifiedClassNameOrNull
17+
public actual val KClass<*>.rpcInternalTypeName: String?
18+
get() = rpcInternalQualifiedClassNameOrNull
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("detekt.MatchingDeclarationName")
@@ -10,9 +10,9 @@ import kotlinx.rpc.internal.utils.InternalRpcApi
1010
import kotlin.reflect.KClass
1111

1212
@InternalRpcApi
13-
public actual val KClass<*>.qualifiedClassNameOrNull: String?
13+
public actual val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
1414
get() = qualifiedName
1515

1616
@InternalRpcApi
17-
public actual val KClass<*>.typeName: String?
17+
public actual val KClass<*>.rpcInternalTypeName: String?
1818
get() = java.typeName
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("detekt.MatchingDeclarationName")
@@ -10,9 +10,9 @@ import kotlinx.rpc.internal.utils.InternalRpcApi
1010
import kotlin.reflect.KClass
1111

1212
@InternalRpcApi
13-
public actual val KClass<*>.qualifiedClassNameOrNull: String?
13+
public actual val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
1414
get() = qualifiedName
1515

1616
@InternalRpcApi
17-
public actual val KClass<*>.typeName: String?
18-
get() = qualifiedClassNameOrNull
17+
public actual val KClass<*>.rpcInternalTypeName: String?
18+
get() = rpcInternalQualifiedClassNameOrNull
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("detekt.MatchingDeclarationName")
@@ -10,9 +10,9 @@ import kotlinx.rpc.internal.utils.InternalRpcApi
1010
import kotlin.reflect.KClass
1111

1212
@InternalRpcApi
13-
public actual val KClass<*>.qualifiedClassNameOrNull: String?
13+
public actual val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
1414
get() = toString()
1515

1616
@InternalRpcApi
17-
public actual val KClass<*>.typeName: String?
18-
get() = qualifiedClassNameOrNull
17+
public actual val KClass<*>.rpcInternalTypeName: String?
18+
get() = rpcInternalQualifiedClassNameOrNull
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("detekt.MatchingDeclarationName")
@@ -10,9 +10,9 @@ import kotlinx.rpc.internal.utils.InternalRpcApi
1010
import kotlin.reflect.KClass
1111

1212
@InternalRpcApi
13-
public actual val KClass<*>.qualifiedClassNameOrNull: String?
13+
public actual val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
1414
get() = toString()
1515

1616
@InternalRpcApi
17-
public actual val KClass<*>.typeName: String?
18-
get() = qualifiedClassNameOrNull
17+
public actual val KClass<*>.rpcInternalTypeName: String?
18+
get() = rpcInternalQualifiedClassNameOrNull

krpc/krpc-client/api/krpc-client.api

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public abstract class kotlinx/rpc/krpc/client/KrpcClient : kotlinx/rpc/krpc/inte
66
protected final fun getConfig ()Lkotlinx/rpc/krpc/KrpcConfig$Client;
77
public synthetic fun getConfig ()Lkotlinx/rpc/krpc/KrpcConfig;
88
public final fun getCoroutineContext ()Lkotlin/coroutines/CoroutineContext;
9-
protected fun getLogger ()Lkotlinx/rpc/krpc/internal/logging/CommonLogger;
9+
protected final fun getLogger ()Lkotlinx/rpc/krpc/internal/logging/RpcInternalCommonLogger;
1010
}
1111

krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import kotlinx.rpc.annotations.Rpc
1515
import kotlinx.rpc.descriptor.RpcCallable
1616
import kotlinx.rpc.internal.serviceScopeOrNull
1717
import kotlinx.rpc.internal.utils.InternalRpcApi
18-
import kotlinx.rpc.internal.utils.SupervisedCompletableDeferred
18+
import kotlinx.rpc.internal.utils.RpcInternalSupervisedCompletableDeferred
1919
import kotlinx.rpc.internal.utils.getOrNull
20-
import kotlinx.rpc.internal.utils.map.ConcurrentHashMap
20+
import kotlinx.rpc.internal.utils.map.RpcInternalConcurrentHashMap
2121
import kotlinx.rpc.krpc.*
2222
import kotlinx.rpc.krpc.client.internal.KrpcClientConnector
2323
import kotlinx.rpc.krpc.internal.*
24-
import kotlinx.rpc.krpc.internal.logging.CommonLogger
24+
import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger
2525
import kotlinx.serialization.BinaryFormat
2626
import kotlinx.serialization.SerialFormat
2727
import kotlinx.serialization.StringFormat
@@ -68,7 +68,7 @@ public abstract class KrpcClient(
6868

6969
private val callCounter = atomic(0L)
7070

71-
override val logger: CommonLogger = CommonLogger.logger(objectId())
71+
final override val logger: RpcInternalCommonLogger = RpcInternalCommonLogger.logger(rpcInternalObjectId())
7272

7373
private val serverSupportedPlugins: CompletableDeferred<Set<KrpcPlugin>> = CompletableDeferred()
7474

@@ -79,7 +79,7 @@ public abstract class KrpcClient(
7979
private var clientCancelled = false
8080

8181
// callId to serviceTypeString
82-
private val cancellingRequests = ConcurrentHashMap<String, String>()
82+
private val cancellingRequests = RpcInternalConcurrentHashMap<String, String>()
8383

8484
init {
8585
coroutineContext.job.invokeOnCompletion(onCancelling = true) {
@@ -155,7 +155,7 @@ public abstract class KrpcClient(
155155
val callable = call.descriptor.getCallable(call.callableName)
156156
?: error("Unexpected callable '${call.callableName}' for ${call.descriptor.fqName} service")
157157

158-
val deferred = SupervisedCompletableDeferred<T>(serviceScope.coroutineContext.job)
158+
val deferred = RpcInternalSupervisedCompletableDeferred<T>(serviceScope.coroutineContext.job)
159159

160160
/**
161161
* Launched on the service scope (receiver)
@@ -181,7 +181,7 @@ public abstract class KrpcClient(
181181
val callable = call.descriptor.getCallable(call.callableName)
182182
?: error("Unexpected callable '${call.callableName}' for ${call.descriptor.fqName} service")
183183

184-
val callCompletableResult = SupervisedCompletableDeferred<T>()
184+
val callCompletableResult = RpcInternalSupervisedCompletableDeferred<T>()
185185
val rpcCall = call(call, callable, callCompletableResult)
186186
val result = callCompletableResult.await()
187187

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/StreamScope.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc
66

77
import kotlinx.coroutines.*
88
import kotlinx.rpc.internal.utils.ExperimentalRpcApi
99
import kotlinx.rpc.internal.utils.InternalRpcApi
10-
import kotlinx.rpc.internal.utils.map.ConcurrentHashMap
10+
import kotlinx.rpc.internal.utils.map.RpcInternalConcurrentHashMap
1111
import kotlin.contracts.ExperimentalContracts
1212
import kotlin.contracts.InvocationKind
1313
import kotlin.contracts.contract
@@ -40,7 +40,7 @@ public class StreamScope internal constructor(
4040

4141
private val scopeJob = SupervisorJob(parentContext.job)
4242

43-
private val requests = ConcurrentHashMap<String, CoroutineScope>()
43+
private val requests = RpcInternalConcurrentHashMap<String, CoroutineScope>()
4444

4545
init {
4646
scopeJob.invokeOnCompletion {

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/CancellationType.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.internal
66

7-
import kotlinx.rpc.internal.utils.IndexedEnum
7+
import kotlinx.rpc.internal.utils.RpcInternalIndexedEnum
88
import kotlinx.rpc.internal.utils.InternalRpcApi
9-
import kotlinx.rpc.krpc.internal.CancellationType.entries
109

1110
@InternalRpcApi
1211
@Suppress("detekt.MagicNumber")
13-
public enum class CancellationType(override val uniqueIndex: Int) : IndexedEnum {
12+
public enum class CancellationType(override val uniqueIndex: Int) : RpcInternalIndexedEnum {
1413
ENDPOINT(0),
1514
SERVICE(1),
1615
REQUEST(2),

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package kotlinx.rpc.krpc.internal
66

7-
import kotlinx.rpc.internal.typeName
7+
import kotlinx.rpc.internal.rpcInternalTypeName
88
import kotlinx.rpc.internal.utils.InternalRpcApi
99

1010
@InternalRpcApi
1111
public fun serializeException(cause: Throwable): SerializedException {
1212
val message = cause.message ?: "Unknown exception"
1313
val stacktrace = cause.stackElements()
1414
val serializedCause = cause.cause?.let { serializeException(it) }
15-
val className = cause::class.typeName ?: ""
15+
val className = cause::class.rpcInternalTypeName ?: ""
1616

1717
return SerializedException(cause.toString(), message, stacktrace, serializedCause, className)
1818
}

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcConnector.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import kotlinx.coroutines.sync.withLock
1212
import kotlinx.rpc.internal.utils.InternalRpcApi
1313
import kotlinx.rpc.krpc.KrpcTransport
1414
import kotlinx.rpc.krpc.KrpcTransportMessage
15-
import kotlinx.rpc.krpc.internal.logging.CommonLogger
16-
import kotlinx.rpc.krpc.internal.logging.DumpLoggerContainer
15+
import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger
16+
import kotlinx.rpc.krpc.internal.logging.RpcInternalDumpLoggerContainer
1717
import kotlinx.serialization.*
1818

1919
@InternalRpcApi
@@ -47,14 +47,14 @@ public class KrpcConnector<SubscriptionKey>(
4747
private val getKey: KrpcMessage.() -> SubscriptionKey,
4848
) : KrpcMessageSender, CoroutineScope by transport {
4949
private val role = if (isServer) SERVER_ROLE else CLIENT_ROLE
50-
private val logger = CommonLogger.logger(objectId(role))
50+
private val logger = RpcInternalCommonLogger.logger(rpcInternalObjectId(role))
5151

5252
private val mutex = Mutex()
5353

5454
private val waiting = mutableMapOf<SubscriptionKey, MutableList<KrpcMessage>>()
5555
private val subscriptions = mutableMapOf<SubscriptionKey, KrpcMessageHandler>()
5656

57-
private val dumpLogger by lazy { DumpLoggerContainer.provide() }
57+
private val dumpLogger by lazy { RpcInternalDumpLoggerContainer.provide() }
5858

5959
override suspend fun sendMessage(message: KrpcMessage) {
6060
val transportMessage = when (serialFormat) {

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPlugin.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
package kotlinx.rpc.krpc.internal
66

7-
import kotlinx.rpc.internal.utils.IndexedEnum
7+
import kotlinx.rpc.internal.utils.RpcInternalIndexedEnum
88
import kotlinx.rpc.internal.utils.InternalRpcApi
9-
import kotlinx.rpc.internal.utils.ShortEnumKSerializer
9+
import kotlinx.rpc.internal.utils.RpcInternalShortEnumKSerializer
1010
import kotlinx.serialization.Serializable
1111

1212
/**
@@ -25,7 +25,7 @@ public enum class KrpcPlugin(
2525
* Only for maintenance purposes. Indicates when the plugin was added.
2626
*/
2727
@Suppress("unused") private val since: KrpcVersion,
28-
) : IndexedEnum {
28+
) : RpcInternalIndexedEnum {
2929
/**
3030
* Represents all unknown plugins.
3131
* Endpoint may get this value from a peer, when peer has a newer version and with it some new plugins
@@ -66,7 +66,7 @@ public enum class KrpcPlugin(
6666
}
6767
}
6868

69-
private class KrpcPluginSerializer : ShortEnumKSerializer<KrpcPlugin>(
69+
private class KrpcPluginSerializer : RpcInternalShortEnumKSerializer<KrpcPlugin>(
7070
kClass = KrpcPlugin::class,
7171
unknownValue = KrpcPlugin.UNKNOWN,
7272
allValues = KrpcPlugin.ALL,

0 commit comments

Comments
 (0)