Skip to content

Commit

Permalink
Added docs, changed defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee committed Dec 4, 2024
1 parent 54cf575 commit 4c505d2
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fun CompilerConfiguration.strictModeAggregator(): StrictModeAggregator {
stateFlow = get(StrictModeConfigurationKeys.STATE_FLOW, StrictMode.WARNING),
sharedFlow = get(StrictModeConfigurationKeys.SHARED_FLOW, StrictMode.WARNING),
nestedFlow = get(StrictModeConfigurationKeys.NESTED_FLOW, StrictMode.WARNING),
streamScopedFunctions = get(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, StrictMode.WARNING),
suspendingServerStreaming = get(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, StrictMode.WARNING),
streamScopedFunctions = get(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, StrictMode.NONE),
suspendingServerStreaming = get(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, StrictMode.NONE),
notTopLevelServerFlow = get(StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, StrictMode.WARNING),
fields = get(StrictModeConfigurationKeys.FIELDS, StrictMode.WARNING),
)
Expand Down
55 changes: 53 additions & 2 deletions gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,71 @@ import org.gradle.kotlin.dsl.newInstance
import javax.inject.Inject

open class RpcExtension @Inject constructor(objects: ObjectFactory) {
/**
* Strict mode settings.
* Allows configuring the reporting state of deprecated features.
*/
val strict: RpcStrictModeExtension = objects.newInstance<RpcStrictModeExtension>()

/**
* Strict mode settings.
* Allows configuring the reporting state of deprecated features.
*/
fun strict(configure: Action<RpcStrictModeExtension>) {
configure.execute(strict)
}
}

open class RpcStrictModeExtension @Inject constructor(objects: ObjectFactory) {
/**
* `StateFlow`s in RPC services are deprecated,
* due to their error-prone nature.
*
* Consider using plain flows and converting them to state on the application side.
*/
val stateFlow: Property<RpcStrictMode> = objects.strictModeProperty()

/**
* `SharedFlow`s in RPC services are deprecated,
* due to their error-prone nature.
*
* Consider using plain flows and converting them to state on the application side.
*/
val sharedFlow: Property<RpcStrictMode> = objects.strictModeProperty()

/**
* Nested flows in RPC services are deprecated,
* due to their error-prone nature.
*
* Consider using plain flows and converting them to state on the application side.
*/
val nestedFlow: Property<RpcStrictMode> = objects.strictModeProperty()
val streamScopedFunctions: Property<RpcStrictMode> = objects.strictModeProperty()
val suspendingServerStreaming: Property<RpcStrictMode> = objects.strictModeProperty()

/**
* WIP
* Will be enabled later, when an alternative is ready.
*/
private val streamScopedFunctions: Property<RpcStrictMode> = objects.strictModeProperty(RpcStrictMode.NONE)

/**
* WIP
* Will be enabled later, when an alternative is ready.
*/
private val suspendingServerStreaming: Property<RpcStrictMode> = objects.strictModeProperty(RpcStrictMode.NONE)

/**
* Not top-level flows in the return value are deprecated in RPC for streaming.
*
* Consider returning a Flow and requesting other data in a different method.
*/
val notTopLevelServerFlow: Property<RpcStrictMode> = objects.strictModeProperty()

/**
* Fields in RPC services are deprecated,
* due to its error-prone nature.
*
* Consider using regular streaming.
*/
val fields: Property<RpcStrictMode> = objects.strictModeProperty()

private fun ObjectFactory.strictModeProperty(
Expand Down
10 changes: 5 additions & 5 deletions gradle-plugin/src/main/kotlin/kotlinx/rpc/compilerPlugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class CompilerPluginCli : KotlinCompilerPluginSupportPlugin by compilerPlugin({
SubpluginOption("strict-stateFlow", strict.stateFlow.get().toCompilerArg()),
SubpluginOption("strict-sharedFlow", strict.sharedFlow.get().toCompilerArg()),
SubpluginOption("strict-nested-flow", strict.nestedFlow.get().toCompilerArg()),
SubpluginOption("strict-stream-scope", strict.streamScopedFunctions.get().toCompilerArg()),
SubpluginOption(
"strict-suspending-server-streaming",
strict.suspendingServerStreaming.get().toCompilerArg()
),
// SubpluginOption("strict-stream-scope", strict.streamScopedFunctions.get().toCompilerArg()),
// SubpluginOption(
// "strict-suspending-server-streaming",
// strict.suspendingServerStreaming.get().toCompilerArg()
// ),
SubpluginOption("strict-not-top-level-server-flow", strict.notTopLevelServerFlow.get().toCompilerArg()),
SubpluginOption("strict-fields", strict.fields.get().toCompilerArg()),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package kotlinx.rpc.codegen.test.services
import kotlinx.rpc.codegen.StrictMode
import kotlinx.rpc.codegen.StrictModeConfigurationKeys
import kotlinx.rpc.codegen.registerRpcExtensions
import kotlinx.rpc.codegen.toStrictMode
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ FILE: a.kt

}
Module: main
FILE: module_main_strictMode.kt
FILE: b.kt
@FILE:R|kotlin/OptIn|(markerClass = vararg(<getClass>(Q|kotlinx/rpc/internal/utils/ExperimentalRpcApi|)))
@R|kotlinx/serialization/Serializable|() public final data class InnerFlow : R|kotlin/Any| {
public constructor(flow: R|@R|kotlinx/serialization/Contextual|() kotlinx/coroutines/flow/Flow<kotlin/Int>|): R|InnerFlow| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface MyServiceWithStateFlow {
}

// MODULE: main
// RPC_STRICT_MODE: warning
// FILE: b.kt

@file:OptIn(ExperimentalRpcApi::class)

Expand Down

0 comments on commit 4c505d2

Please sign in to comment.