Skip to content

Commit 4c505d2

Browse files
committed
Added docs, changed defaults
1 parent 54cf575 commit 4c505d2

File tree

6 files changed

+63
-11
lines changed

6 files changed

+63
-11
lines changed

compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/StrictMode.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ fun CompilerConfiguration.strictModeAggregator(): StrictModeAggregator {
5252
stateFlow = get(StrictModeConfigurationKeys.STATE_FLOW, StrictMode.WARNING),
5353
sharedFlow = get(StrictModeConfigurationKeys.SHARED_FLOW, StrictMode.WARNING),
5454
nestedFlow = get(StrictModeConfigurationKeys.NESTED_FLOW, StrictMode.WARNING),
55-
streamScopedFunctions = get(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, StrictMode.WARNING),
56-
suspendingServerStreaming = get(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, StrictMode.WARNING),
55+
streamScopedFunctions = get(StrictModeConfigurationKeys.STREAM_SCOPED_FUNCTIONS, StrictMode.NONE),
56+
suspendingServerStreaming = get(StrictModeConfigurationKeys.SUSPENDING_SERVER_STREAMING, StrictMode.NONE),
5757
notTopLevelServerFlow = get(StrictModeConfigurationKeys.NOT_TOP_LEVEL_SERVER_FLOW, StrictMode.WARNING),
5858
fields = get(StrictModeConfigurationKeys.FIELDS, StrictMode.WARNING),
5959
)

gradle-plugin/src/main/kotlin/kotlinx/rpc/Extensions.kt

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,71 @@ import org.gradle.kotlin.dsl.newInstance
1313
import javax.inject.Inject
1414

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

22+
/**
23+
* Strict mode settings.
24+
* Allows configuring the reporting state of deprecated features.
25+
*/
1826
fun strict(configure: Action<RpcStrictModeExtension>) {
1927
configure.execute(strict)
2028
}
2129
}
2230

2331
open class RpcStrictModeExtension @Inject constructor(objects: ObjectFactory) {
32+
/**
33+
* `StateFlow`s in RPC services are deprecated,
34+
* due to their error-prone nature.
35+
*
36+
* Consider using plain flows and converting them to state on the application side.
37+
*/
2438
val stateFlow: Property<RpcStrictMode> = objects.strictModeProperty()
39+
40+
/**
41+
* `SharedFlow`s in RPC services are deprecated,
42+
* due to their error-prone nature.
43+
*
44+
* Consider using plain flows and converting them to state on the application side.
45+
*/
2546
val sharedFlow: Property<RpcStrictMode> = objects.strictModeProperty()
47+
48+
/**
49+
* Nested flows in RPC services are deprecated,
50+
* due to their error-prone nature.
51+
*
52+
* Consider using plain flows and converting them to state on the application side.
53+
*/
2654
val nestedFlow: Property<RpcStrictMode> = objects.strictModeProperty()
27-
val streamScopedFunctions: Property<RpcStrictMode> = objects.strictModeProperty()
28-
val suspendingServerStreaming: Property<RpcStrictMode> = objects.strictModeProperty()
55+
56+
/**
57+
* WIP
58+
* Will be enabled later, when an alternative is ready.
59+
*/
60+
private val streamScopedFunctions: Property<RpcStrictMode> = objects.strictModeProperty(RpcStrictMode.NONE)
61+
62+
/**
63+
* WIP
64+
* Will be enabled later, when an alternative is ready.
65+
*/
66+
private val suspendingServerStreaming: Property<RpcStrictMode> = objects.strictModeProperty(RpcStrictMode.NONE)
67+
68+
/**
69+
* Not top-level flows in the return value are deprecated in RPC for streaming.
70+
*
71+
* Consider returning a Flow and requesting other data in a different method.
72+
*/
2973
val notTopLevelServerFlow: Property<RpcStrictMode> = objects.strictModeProperty()
74+
75+
/**
76+
* Fields in RPC services are deprecated,
77+
* due to its error-prone nature.
78+
*
79+
* Consider using regular streaming.
80+
*/
3081
val fields: Property<RpcStrictMode> = objects.strictModeProperty()
3182

3283
private fun ObjectFactory.strictModeProperty(

gradle-plugin/src/main/kotlin/kotlinx/rpc/compilerPlugins.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class CompilerPluginCli : KotlinCompilerPluginSupportPlugin by compilerPlugin({
3636
SubpluginOption("strict-stateFlow", strict.stateFlow.get().toCompilerArg()),
3737
SubpluginOption("strict-sharedFlow", strict.sharedFlow.get().toCompilerArg()),
3838
SubpluginOption("strict-nested-flow", strict.nestedFlow.get().toCompilerArg()),
39-
SubpluginOption("strict-stream-scope", strict.streamScopedFunctions.get().toCompilerArg()),
40-
SubpluginOption(
41-
"strict-suspending-server-streaming",
42-
strict.suspendingServerStreaming.get().toCompilerArg()
43-
),
39+
// SubpluginOption("strict-stream-scope", strict.streamScopedFunctions.get().toCompilerArg()),
40+
// SubpluginOption(
41+
// "strict-suspending-server-streaming",
42+
// strict.suspendingServerStreaming.get().toCompilerArg()
43+
// ),
4444
SubpluginOption("strict-not-top-level-server-flow", strict.notTopLevelServerFlow.get().toCompilerArg()),
4545
SubpluginOption("strict-fields", strict.fields.get().toCompilerArg()),
4646
)

tests/compiler-plugin-tests/src/test/kotlin/kotlinx/rpc/codegen/test/services/ExtensionRegistrarConfigurator.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package kotlinx.rpc.codegen.test.services
77
import kotlinx.rpc.codegen.StrictMode
88
import kotlinx.rpc.codegen.StrictModeConfigurationKeys
99
import kotlinx.rpc.codegen.registerRpcExtensions
10-
import kotlinx.rpc.codegen.toStrictMode
1110
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
1211
import org.jetbrains.kotlin.config.CompilerConfiguration
1312
import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability

tests/compiler-plugin-tests/src/testData/diagnostics/strictMode.fir.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ FILE: a.kt
4444

4545
}
4646
Module: main
47-
FILE: module_main_strictMode.kt
47+
FILE: b.kt
4848
@FILE:R|kotlin/OptIn|(markerClass = vararg(<getClass>(Q|kotlinx/rpc/internal/utils/ExperimentalRpcApi|)))
4949
@R|kotlinx/serialization/Serializable|() public final data class InnerFlow : R|kotlin/Any| {
5050
public constructor(flow: R|@R|kotlinx/serialization/Contextual|() kotlinx/coroutines/flow/Flow<kotlin/Int>|): R|InnerFlow| {

tests/compiler-plugin-tests/src/testData/diagnostics/strictMode.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ interface MyServiceWithStateFlow {
1616
}
1717

1818
// MODULE: main
19+
// RPC_STRICT_MODE: warning
20+
// FILE: b.kt
1921

2022
@file:OptIn(ExperimentalRpcApi::class)
2123

0 commit comments

Comments
 (0)