From 62ba5783273d94946c52fc22fbe210c15ce21f5b Mon Sep 17 00:00:00 2001 From: Stephan Boyer Date: Thu, 28 Nov 2024 14:13:11 -0800 Subject: [PATCH] Fix the toastfile --- src/generate_typescript.rs | 17 +++++++++----- src/schema_loader.rs | 2 +- toast.yml | 45 +++++++++++++++++++++++--------------- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/generate_typescript.rs b/src/generate_typescript.rs index 6c32f28d..2c24b7a3 100644 --- a/src/generate_typescript.rs +++ b/src/generate_typescript.rs @@ -1603,7 +1603,14 @@ fn write_type( } }, schema::TypeVariant::Custom(import, name) => { - write_custom_type(buffer, imports, namespace, import, name, Some(direction))?; + write_custom_type( + buffer, + imports, + namespace, + import.as_ref(), + name, + Some(direction), + )?; } schema::TypeVariant::F64 => { write!(buffer, "number")?; @@ -1642,7 +1649,7 @@ fn write_custom_type( buffer: &mut T, imports: &BTreeMap, namespace: &schema::Namespace, - import: &Option, + import: Option<&Identifier>, name: &Identifier, direction: Option, ) -> Result<(), fmt::Error> { @@ -1855,7 +1862,7 @@ fn write_atlas_calculation( schema::TypeVariant::Custom(import, name) => { write_indentation(buffer, indentation)?; write!(buffer, "payloadAtlas = ")?; - write_custom_type(buffer, imports, namespace, import, name, None)?; + write_custom_type(buffer, imports, namespace, import.as_ref(), name, None)?; writeln!(buffer, ".atlas(payload);") } schema::TypeVariant::F64 => { @@ -2089,7 +2096,7 @@ fn write_serialization_invocation( schema::TypeVariant::Custom(import, name) => { write_indentation(buffer, indentation)?; write!(buffer, "offset = ")?; - write_custom_type(buffer, imports, namespace, import, name, None)?; + write_custom_type(buffer, imports, namespace, import.as_ref(), name, None)?; writeln!( buffer, ".serializeWithAtlasUnsafe(dataView, offset, payload, payloadAtlas);", @@ -2409,7 +2416,7 @@ fn write_deserialization_invocation( schema::TypeVariant::Custom(import, name) => { write_indentation(buffer, indentation)?; write!(buffer, "let payload = ")?; - write_custom_type(buffer, imports, namespace, import, name, None)?; + write_custom_type(buffer, imports, namespace, import.as_ref(), name, None)?; writeln!(buffer, ".deserializeUnsafe(dataView);")?; write_indentation(buffer, indentation)?; writeln!(buffer, "offset = dataView.byteLength;") diff --git a/src/schema_loader.rs b/src/schema_loader.rs index 87cfaa6b..4dbdb435 100644 --- a/src/schema_loader.rs +++ b/src/schema_loader.rs @@ -130,7 +130,7 @@ pub fn load_schemas( // Perform a depth-first traversal of the transitive dependencies. while let Some((namespace, path, origin)) = schemas_to_load.pop() { // Read the file. - let contents = match read_to_string(&base_path.join(&path)) { + let contents = match read_to_string(base_path.join(&path)) { Ok(contents) => contents, Err(error) => { let message = format!("Unable to load {}.", path.to_string_lossy().code_str()); diff --git a/toast.yml b/toast.yml index 41b5dab6..c19fc1be 100644 --- a/toast.yml +++ b/toast.yml @@ -191,10 +191,10 @@ tasks: for SCENARIO in benchmarks/rust examples/rust integration_tests/rust; do echo "Validating $SCENARIO..." ( - cd "$SCENARIO" && \ - cargo-offline check && \ - cargo-offline clippy --all-features --all-targets --workspace && \ - cargo-fmt --check && \ + cd "$SCENARIO" + cargo-offline check + cargo-offline clippy --all-features --all-targets --workspace + cargo-fmt --check cargo-offline run ) done @@ -218,7 +218,12 @@ tasks: integration_tests/typescript_web do echo "Validating $SCENARIO..." - (cd "$SCENARIO" && npm ci && npm run main && npm run lint) + ( + cd "$SCENARIO" + npm ci + npm run main + npm run lint + ) done # Validate the data from the integration test. @@ -247,19 +252,19 @@ tasks: # Lint the Rust projects. for PROJECT_PATH in . benchmarks/rust examples/rust integration_tests/rust; do ( - cd "$PROJECT_PATH" && + cd "$PROJECT_PATH" # Lint the code with Clippy. - cargo-offline clippy --all-features --all-targets --workspace && + cargo-offline clippy --all-features --all-targets --workspace # Check code formatting with Rustfmt. See [ref:format_macros] for an explanation of the # `rg` commands. - rg --type rust --files-with-matches '' src | xargs sed -i 's/!(/_(/g' && - rg --type rust --files-with-matches '' src | xargs sed -i 's/^\([^ (]*\)_(/\1!(/g' && + rg --type rust --files-with-matches '' src | xargs sed -i 's/!(/_(/g' + rg --type rust --files-with-matches '' src | xargs sed -i 's/^\([^ (]*\)_(/\1!(/g' if ! cargo-fmt --check; then echo 'ERROR: Please correct the formatting errors above.' 1>&2 exit 1 - fi && + fi rg --type rust --files-with-matches '' src | xargs sed -i 's/_(/!(/g' # Forbid unconsolidated `use` declarations. @@ -287,9 +292,9 @@ tasks: integration_tests/typescript_web do ( - cd "$PROJECT_PATH" && - npm ci && - npm run lint + cd "$PROJECT_PATH" + npm ci + npm run ) done @@ -331,13 +336,13 @@ tasks: # Format the Rust projects. for PROJECT_PATH in . benchmarks/rust examples/rust integration_tests/rust; do ( - cd "$PROJECT_PATH" && + cd "$PROJECT_PATH" # We temporarily convert macro invocations into function calls so Rustfmt's # `trailing_comma` feature applies to macro arguments [tag:format_macros]. - rg --type rust --files-with-matches '' src | xargs sed -i 's/!(/_(/g' && - rg --type rust --files-with-matches '' src | xargs sed -i 's/^\([^ (]*\)_(/\1!(/g' && - cargo-fmt && + rg --type rust --files-with-matches '' src | xargs sed -i 's/!(/_(/g' + rg --type rust --files-with-matches '' src | xargs sed -i 's/^\([^ (]*\)_(/\1!(/g' + cargo-fmt rg --type rust --files-with-matches '' src | xargs sed -i 's/_(/!(/g' ) done @@ -349,7 +354,11 @@ tasks: integration_tests/typescript_node \ integration_tests/typescript_web do - (cd "$PROJECT_PATH" && npm ci && npm run format) + ( + cd "$PROJECT_PATH" + npm ci + npm run format + ) done release: