Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e2e0d82
Draft implement new assert_delegate_components macro
soareschen Jun 18, 2026
01f1b04
Add pretty_format helper
soareschen Jun 18, 2026
29e4893
Use pretty_format in assert_delegate_components
soareschen Jun 18, 2026
5afa4b0
Try file-based snapshot
soareschen Jun 18, 2026
3e8c097
Inline snapshot now works
soareschen Jun 18, 2026
d057b37
Put original code first before snapshot
soareschen Jun 18, 2026
aeb39b0
Migrate more tests to assert_delegate_components
soareschen Jun 18, 2026
763616e
Rename to snapshot_delegate_components
soareschen Jun 18, 2026
691f622
Allow arbitrary expression in body
soareschen Jun 18, 2026
733b662
Add MacroSnapshot::wrap_output helper
soareschen Jun 18, 2026
7f808f7
Add snapshot_cgp_component
soareschen Jun 18, 2026
a0568d3
Add cgp-macro-test-util-lib crate
soareschen Jun 18, 2026
e0c27b8
Refactor snapshot_delegate_components macro
soareschen Jun 18, 2026
c178e42
Add back snapshot_cgp_component
soareschen Jun 18, 2026
3cddce6
Snapshot cgp_component is now working
soareschen Jun 18, 2026
96f6903
Format output as string inside macro
soareschen Jun 19, 2026
7130ee5
Implement `snapshot_cgp_impl!`
soareschen Jun 19, 2026
499a75f
Implement `snapshot_cgp_auto_getter!`
soareschen Jun 19, 2026
3841402
Move pretty_format to test-util-lib
soareschen Jun 19, 2026
419a894
AI-migrate tests
soareschen Jun 19, 2026
517fc1c
Implement `snapshot_cgp_fn!`
soareschen Jun 19, 2026
62a3187
Use fully qualified `insta::assert_snapshot!`
soareschen Jun 19, 2026
ea8fe0c
Add `snapshot_cgp_namespace!` macro
soareschen Jun 19, 2026
174f9c7
Add `snapshot_cgp_type!` macro
soareschen Jun 19, 2026
526ab3a
Add `snapshot_check_components!` and `snapshot_delegate_and_check_com…
soareschen Jun 19, 2026
7787737
Add StatementMacroSnapshot
soareschen Jun 19, 2026
e02ea72
Add AttributeMacroSnapshot
soareschen Jun 19, 2026
1907737
Remove SnapshotCgpComponent
soareschen Jun 19, 2026
110e174
Migrate all other macros
soareschen Jun 19, 2026
550ea30
Add `snapshot_cgp_provider!` macro
soareschen Jun 19, 2026
61e6d01
Fix formatting
soareschen Jun 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 150 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ members = [
"crates/macros/cgp-macro",
"crates/macros/cgp-macro-core",
"crates/macros/cgp-macro-lib",
"crates/macros/cgp-macro-test-util",
"crates/macros/cgp-macro-test-util-lib",
"crates/macros/cgp-extra-macro",
"crates/macros/cgp-extra-macro-lib",

Expand Down Expand Up @@ -68,5 +70,7 @@ cgp-async-macro = { version = "0.7.0", path = "./crates/macros/cgp-a
cgp-macro = { version = "0.7.0", path = "./crates/macros/cgp-macro" }
cgp-macro-core = { version = "0.7.0", path = "./crates/macros/cgp-macro-core" }
cgp-macro-lib = { version = "0.7.0", path = "./crates/macros/cgp-macro-lib" }
cgp-macro-test-util = { version = "0.7.0", path = "./crates/macros/cgp-macro-test-util" }
cgp-macro-test-util-lib = { version = "0.7.0", path = "./crates/macros/cgp-macro-test-util-lib" }
cgp-extra-macro = { version = "0.7.0", path = "./crates/macros/cgp-extra-macro" }
cgp-extra-macro-lib = { version = "0.7.0", path = "./crates/macros/cgp-extra-macro-lib" }
14 changes: 4 additions & 10 deletions crates/macros/cgp-macro-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ repository = { workspace = true }
authors = { workspace = true }
rust-version = { workspace = true }
keywords = { workspace = true }
description = """
Context-generic programming core component macros implemented as a library.
"""

[features]
default = []

[dependencies]
syn = { version = "2.0.95", features = [ "full", "extra-traits", "visit", "visit-mut" ] }
quote = "1.0.38"
proc-macro2 = "1.0.92"
itertools = "0.14.0"
syn = { version = "2.0.95", features = [ "full", "extra-traits", "visit", "visit-mut" ] }
quote = { version = "1.0.38" }
proc-macro2 = { version = "1.0.92" }
itertools = { version = "0.14.0" }
2 changes: 2 additions & 0 deletions crates/macros/cgp-macro-core/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod implicits;
mod is_provider_params;
mod parse_internal;
mod snake_case;
mod strip;

pub use camel_case::*;
pub use delegated_impls::*;
Expand All @@ -17,3 +18,4 @@ pub use implicits::*;
pub use is_provider_params::*;
pub use parse_internal::*;
pub use snake_case::*;
pub use strip::*;
57 changes: 2 additions & 55 deletions crates/macros/cgp-macro-core/src/functions/parse_internal.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use core::any::type_name;

use proc_macro2::{Group, TokenStream, TokenTree};
use proc_macro2::TokenStream;
use syn::parse::Parse;
use syn::spanned::Spanned;
use syn::{Error, parse2};

use crate::functions::strip_macro_prelude;
pub use crate::macros::parse_internal;

pub fn parse_internal<T>(body: TokenStream) -> Result<T, Error>
Expand All @@ -23,57 +24,3 @@ where
e
})
}

/// Strips the `::cgp::macro_prelude::` prefix from the [`TokenStream`] so the
/// error message shows the more readable, unqualified paths. The replacement is
/// done at the token level, recursing into nested groups.
fn strip_macro_prelude(body: TokenStream) -> TokenStream {
// The prefix `::cgp::macro_prelude::` is made up of the following tokens.
fn is_prefix(tokens: &[TokenTree]) -> bool {
matches!(
tokens,
[
TokenTree::Punct(p1),
TokenTree::Punct(p2),
TokenTree::Ident(cgp),
TokenTree::Punct(p3),
TokenTree::Punct(p4),
TokenTree::Ident(prelude),
TokenTree::Punct(p5),
TokenTree::Punct(p6),
] if p1.as_char() == ':'
&& p2.as_char() == ':'
&& cgp == "cgp"
&& p3.as_char() == ':'
&& p4.as_char() == ':'
&& prelude == "macro_prelude"
&& p5.as_char() == ':'
&& p6.as_char() == ':'
)
}

const PREFIX_LEN: usize = 8;

let tokens: Vec<TokenTree> = body.into_iter().collect();
let mut output = Vec::with_capacity(tokens.len());
let mut i = 0;

while i < tokens.len() {
if is_prefix(&tokens[i..(i + PREFIX_LEN).min(tokens.len())]) {
i += PREFIX_LEN;
} else {
match &tokens[i] {
TokenTree::Group(group) => {
let inner = strip_macro_prelude(group.stream());
let mut new_group = Group::new(group.delimiter(), inner);
new_group.set_span(group.span());
output.push(TokenTree::Group(new_group));
}
other => output.push(other.clone()),
}
i += 1;
}
}

output.into_iter().collect()
}
Loading
Loading