From f2cf1163599bf29cbfb3d9424e9f4fe0502a5cf8 Mon Sep 17 00:00:00 2001 From: Diego Imbert <70353967+diegoimbert@users.noreply.github.com> Date: Tue, 16 Dec 2025 18:07:19 +0100 Subject: [PATCH] Allow empty lines in annotations (#7394) --- backend/windmill-macros/src/lib.rs | 4 +++- backend/windmill-macros/tests/annotations.rs | 22 ++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/backend/windmill-macros/src/lib.rs b/backend/windmill-macros/src/lib.rs index 778ac72b0f..44c4734590 100644 --- a/backend/windmill-macros/src/lib.rs +++ b/backend/windmill-macros/src/lib.rs @@ -51,13 +51,15 @@ pub fn annotations(attr: TokenStream, item: TokenStream) -> TokenStream { let mut lines = code.lines(); while let Some(line) = lines.next() { + if line.trim().is_empty() { + continue; + } if !line.starts_with(#comm_lit) { break; } let line = line[#comm_lit.len()..].trim(); let (key, value) = line.split_once('=').unwrap_or((line, "")); - match key { #( stringify!(#custom_field_names) => { diff --git a/backend/windmill-macros/tests/annotations.rs b/backend/windmill-macros/tests/annotations.rs index 395643364d..20388c41c2 100644 --- a/backend/windmill-macros/tests/annotations.rs +++ b/backend/windmill-macros/tests/annotations.rs @@ -102,12 +102,12 @@ mod annotations_tests { #[test] fn spacing_integration() { - // First line is ignored and not used + // First line is ignored { let cont = " # ann2"; - let expected = Annotations { ..Default::default() }; - assert_eq!(expected, old(cont)); + let expected = Annotations { ann2: true, ..Default::default() }; + // assert_eq!(expected, old(cont)); assert_eq!(expected, Annotations::parse(cont)); } // Wrong spacing for ann3 @@ -139,11 +139,10 @@ mod annotations_tests { # Actual annotation next line: # ann5 -# Should be ignored # ann3 "; - let expected = Annotations { ann2: true, ann5: true, ..Default::default() }; - assert_eq!(expected, old(cont)); + let expected = Annotations { ann2: true, ann5: true, ann3: true, ..Default::default() }; + // assert_eq!(expected, old(cont)); assert_eq!(expected, Annotations::parse(cont)); } @@ -168,6 +167,17 @@ mod annotations_tests { } } + #[test] + fn newline_between() { + let cont = "// ann1 + +// ann2"; + assert_eq!( + SlashedAnnotations { ann1: true, ann2: true, ann3: false, ann4: false }, + SlashedAnnotations::parse(cont) + ); + } + // // #[derive(serde_derive::Serialize, serde_derive::Deserialize, Eq, PartialEq)] // // #[annotations("#")] // // pub struct SerAnnotations {