From 898dc7060b33f931129d33e649a79e0089c7294f Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Wed, 15 Jun 2022 14:27:45 -0400 Subject: [PATCH] Writer fixes (#1469) * Fixes for RustWriter bugs #1465 & #1459 * Fix behavior causing extra newlines in docs --- .../amazon/smithy/rust/codegen/rustlang/RustWriter.kt | 6 +++--- .../smithy/generators/client/FluentClientDecorator.kt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustWriter.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustWriter.kt index af20e97b99..8faddc40b5 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustWriter.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustWriter.kt @@ -253,6 +253,9 @@ fun RustWriter.containerDocs(text: String, vararg args: Any): RustWriter { * - Empty newlines are removed */ fun > T.docs(text: String, vararg args: Any, newlinePrefix: String = "/// "): T { + // Because writing docs relies on the newline prefix, ensure that there was a new line written + // before we write the docs + this.ensureNewline() pushState() setNewlinePrefix(newlinePrefix) val cleaned = text.lines() @@ -260,9 +263,6 @@ fun > T.docs(text: String, vararg args: Any, newlinePr // Rustdoc warns on tabs in documentation it.trimStart().replace("\t", " ") } - // Because writing docs relies on the newline prefix, ensure that there was a new line written - // before we write the docs - this.ensureNewline() write(cleaned, *args) popState() return this diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/client/FluentClientDecorator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/client/FluentClientDecorator.kt index 2884ceb381..8f2146af39 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/client/FluentClientDecorator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/client/FluentClientDecorator.kt @@ -448,7 +448,7 @@ class FluentClientGenerator( Fluent builders are created through the [`Client`](crate::client::Client) by calling one if its operation methods. After parameters are set using the builder methods, the `send` method can be called to initiate the request. - """, + """.trim(), newlinePrefix = "//! " ) operations.forEach { operation ->