diff --git a/Cargo.lock b/Cargo.lock index c3d9944fea5f..c5eff5032ed8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7128,9 +7128,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.13.2" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cdcf6b66102d38821c33eea2bf1e8b7bd738072171cbf8a0683fbb46fcb8b0b" +checksum = "a89bc85084ac4e273c6bbf99050d932821af166392aaedc5038a38e1f229cdf5" dependencies = [ "smawk", "unicode-width", @@ -7516,7 +7516,7 @@ dependencies = [ "serde_yaml", "structopt 0.3.21", "tempfile", - "textwrap 0.13.2", + "textwrap 0.13.3", "which 4.0.2", ] diff --git a/language/transaction-builder/generator/Cargo.toml b/language/transaction-builder/generator/Cargo.toml index db405b296520..bc139b599330 100644 --- a/language/transaction-builder/generator/Cargo.toml +++ b/language/transaction-builder/generator/Cargo.toml @@ -13,7 +13,7 @@ anyhow = "1.0.38" heck = "0.3.2" regex = "1.4.3" structopt = "0.3.21" -textwrap = "0.13.2" +textwrap = "0.13.3" serde-reflection = "0.3.2" serde-generate = "0.18.0" serde_yaml = "0.8.17" diff --git a/language/transaction-builder/generator/src/cpp.rs b/language/transaction-builder/generator/src/cpp.rs index bfcf90df0860..8def057bb3cb 100644 --- a/language/transaction-builder/generator/src/cpp.rs +++ b/language/transaction-builder/generator/src/cpp.rs @@ -117,7 +117,7 @@ using namespace diem_types; } fn output_builder_declaration(&mut self, abi: &ScriptABI) -> Result<()> { - write!(self.out, "\n{}", Self::quote_doc(abi.doc()))?; + self.output_doc(abi.doc())?; writeln!( self.out, "Script encode_{}_script({});", @@ -134,7 +134,7 @@ using namespace diem_types; fn output_builder_definition(&mut self, abi: &ScriptABI) -> Result<()> { if self.inlined_definitions { - write!(self.out, "\n{}", Self::quote_doc(abi.doc()))?; + self.output_doc(abi.doc())?; } writeln!( self.out, @@ -167,9 +167,10 @@ using namespace diem_types; Ok(()) } - fn quote_doc(doc: &str) -> String { + fn output_doc(&mut self, doc: &str) -> Result<()> { let doc = crate::common::prepare_doc_string(doc); - textwrap::indent(&doc, "/// ").replace("\n\n", "\n///\n") + let text = textwrap::indent(&doc, "/// ").replace("\n\n", "\n///\n"); + write!(self.out, "\n{}\n", text) } fn quote_type_parameters(ty_args: &[TypeArgumentABI]) -> Vec { diff --git a/language/transaction-builder/generator/src/golang.rs b/language/transaction-builder/generator/src/golang.rs index 5d92dc4ee5ee..6884036f1dcf 100644 --- a/language/transaction-builder/generator/src/golang.rs +++ b/language/transaction-builder/generator/src/golang.rs @@ -166,7 +166,7 @@ func DecodeScript(script *diemtypes.Script) (ScriptCall, error) {{ fn output_script_encoder_function(&mut self, abi: &ScriptABI) -> Result<()> { writeln!( self.out, - "\n{}func Encode{}Script({}) diemtypes.Script {{", + "\n{}\nfunc Encode{}Script({}) diemtypes.Script {{", Self::quote_doc(abi.doc()), abi.name().to_camel_case(), [ diff --git a/language/transaction-builder/generator/src/java.rs b/language/transaction-builder/generator/src/java.rs index 71dec865d7fb..3fb6441dfa55 100644 --- a/language/transaction-builder/generator/src/java.rs +++ b/language/transaction-builder/generator/src/java.rs @@ -431,7 +431,7 @@ private static {} decode_{}_argument(TransactionArgument arg) {{ } doc = format!("{}\n@return {}", doc, return_doc); let text = textwrap::indent(&doc, " * ").replace("\n\n", "\n *\n"); - format!("/**\n{} */\n", text) + format!("/**\n{}\n */\n", text) } fn quote_type_arguments(ty_args: &[TypeArgumentABI]) -> String { diff --git a/language/transaction-builder/generator/src/rust.rs b/language/transaction-builder/generator/src/rust.rs index c4fb18f7e3f6..38d2aaf56a34 100644 --- a/language/transaction-builder/generator/src/rust.rs +++ b/language/transaction-builder/generator/src/rust.rs @@ -226,7 +226,7 @@ pub fn decode(script: &Script) -> Option {{ let prefix = " ".repeat(indentation) + "/// "; let empty_line = "\n".to_string() + &" ".repeat(indentation) + "///\n"; let text = textwrap::indent(doc, &prefix).replace("\n\n", &empty_line); - write!(self.out, "\n{}", text) + write!(self.out, "\n{}\n", text) } fn output_script_encoder_function(&mut self, abi: &ScriptABI) -> Result<()> { diff --git a/language/transaction-builder/generator/src/typescript.rs b/language/transaction-builder/generator/src/typescript.rs index 5bd0553a559b..1a70194eaa34 100644 --- a/language/transaction-builder/generator/src/typescript.rs +++ b/language/transaction-builder/generator/src/typescript.rs @@ -345,7 +345,7 @@ return new DiemTypes.Script(code, tyArgs, args);"#, fn quote_doc(doc: &str) -> String { let doc = crate::common::prepare_doc_string(doc); let text = textwrap::indent(&doc, " * ").replace("\n\n", "\n *\n"); - format!("/**\n{} */\n", text) + format!("/**\n{}\n */\n", text) } fn quote_type_parameters(ty_args: &[TypeArgumentABI]) -> Vec {