Skip to content

Commit 8d4e0e5

Browse files
committed
release(statum): prepare 0.8.3
1 parent 08a8260 commit 8d4e0e5

31 files changed

Lines changed: 764 additions & 126 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Statum targets stable Rust and currently supports Rust `1.93+`.
3434

3535
```toml
3636
[dependencies]
37-
statum = "0.8.2"
37+
statum = "0.8.3"
3838
```
3939

4040
## 60-Second Example

statum-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ name = "statum-core"
2020
readme = "README.md"
2121
repository = "https://github.com/eboody/statum"
2222
rust-version = "1.93"
23-
version = "0.8.2"
23+
version = "0.8.3"
2424

2525
[package.metadata.modum]
2626
weak_modules = [

statum-examples/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ version = "0.8"
2121

2222
[dependencies.statum]
2323
path = "../statum"
24-
version = "0.8.2"
24+
version = "0.8.3"
2525

2626
[dependencies.tokio]
2727
features = ["full"]
@@ -37,7 +37,7 @@ license = "MIT"
3737
name = "statum-examples"
3838
publish = false
3939
rust-version = "1.93"
40-
version = "0.8.2"
40+
version = "0.8.3"
4141

4242
[package.metadata.modum]
4343
weak_modules = [

statum-macros/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ trybuild = "1.0"
2222

2323
[dev-dependencies.statum-core]
2424
path = "../statum-core"
25-
version = "0.8.2"
25+
version = "0.8.3"
2626

2727
[features]
2828
default = []
@@ -48,4 +48,4 @@ name = "statum-macros"
4848
readme = "README.md"
4949
repository = "https://github.com/eboody/statum"
5050
rust-version = "1.93"
51-
version = "0.8.2"
51+
version = "0.8.3"

statum-macros/src/analysis.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ pub struct StructEntry {
1818
pub attrs: Vec<String>,
1919
}
2020

21+
/// Type alias entry extracted from a parsed source file.
22+
#[derive(Clone)]
23+
pub struct TypeAliasEntry {
24+
pub item: syn::ItemType,
25+
pub line_number: usize,
26+
}
27+
2128
/// Impl entry extracted from a parsed source file.
2229
#[allow(dead_code)]
2330
#[derive(Clone)]
@@ -32,13 +39,15 @@ pub struct ImplEntry {
3239
pub struct FileAnalysis {
3340
pub enums: Vec<EnumEntry>,
3441
pub structs: Vec<StructEntry>,
42+
pub type_aliases: Vec<TypeAliasEntry>,
3543
pub impls: Vec<ImplEntry>,
3644
}
3745

3846
#[derive(Default)]
3947
struct DeclarationLines {
4048
enums: VecDeque<usize>,
4149
structs: VecDeque<usize>,
50+
type_aliases: VecDeque<usize>,
4251
impls: VecDeque<usize>,
4352
}
4453

@@ -96,6 +105,12 @@ fn collect_items(
96105
item: item_struct,
97106
});
98107
}
108+
syn::Item::Type(item_type) => {
109+
analysis.type_aliases.push(TypeAliasEntry {
110+
line_number: lines.type_aliases.pop_front()?,
111+
item: item_type,
112+
});
113+
}
99114
syn::Item::Impl(item_impl) => {
100115
analysis.impls.push(ImplEntry {
101116
attrs: attribute_names(&item_impl.attrs),
@@ -131,6 +146,7 @@ fn scan_declaration_lines(content: &str) -> DeclarationLines {
131146
match keyword.as_str() {
132147
"enum" => lines.enums.push_back(token.line),
133148
"struct" => lines.structs.push_back(token.line),
149+
"type" => lines.type_aliases.push_back(token.line),
134150
"impl" => lines.impls.push_back(token.line),
135151
"mod" => {
136152
if matches!(

statum-macros/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ pub fn machine(_attr: TokenStream, item: TokenStream) -> TokenStream {
129129
///
130130
/// Apply `#[transition]` to an `impl Machine<CurrentState>` block. Each method
131131
/// must consume `self` and return a legal `Machine<NextState>` shape or a
132-
/// supported wrapper around it, such as `Result<Machine<NextState>, E>`,
132+
/// source-declared type alias that expands to that shape, or a supported
133+
/// wrapper around it, such as `Result<Machine<NextState>, E>`,
133134
/// `Option<Machine<NextState>>`, or
134135
/// `statum::Branch<Machine<Left>, Machine<Right>>`.
135136
#[proc_macro_attribute]

statum-macros/src/pathing.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ pub fn module_path_from_file_with_root(file_path: &str, module_root: &Path) -> S
8484
}
8585

8686
/// Maps a module path (e.g. `crate::foo::bar`) to a source file.
87-
#[cfg(test)]
88-
pub fn module_path_to_file(
87+
pub(crate) fn module_path_to_file(
8988
module_path: &str,
9089
current_file: &str,
9190
module_root: &Path,

statum-macros/src/query.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ pub struct ItemCandidate {
1616
pub module_path: String,
1717
}
1818

19+
/// A type alias discovered in source with its resolved module path.
20+
#[derive(Clone)]
21+
pub struct TypeAliasCandidate {
22+
pub item: syn::ItemType,
23+
pub line_number: usize,
24+
pub module_path: String,
25+
}
26+
1927
/// Returns candidates of `kind` in `module_path`, optionally requiring `required_attr`.
2028
pub fn candidates_in_module(
2129
file_path: &str,
@@ -84,6 +92,45 @@ pub fn plain_item_line_in_module(
8492
}
8593
}
8694

95+
/// Returns type aliases of `alias_name` declared in `module_path`.
96+
pub fn type_aliases_in_module(
97+
file_path: &str,
98+
module_path: &str,
99+
alias_name: &str,
100+
) -> Vec<TypeAliasCandidate> {
101+
let Some(analysis) = get_file_analysis(file_path) else {
102+
return Vec::new();
103+
};
104+
105+
let mut candidates = analysis
106+
.type_aliases
107+
.iter()
108+
.filter(|entry| entry.item.ident == alias_name)
109+
.filter_map(|entry| {
110+
let resolved_module = module_path_for_line(file_path, entry.line_number)?;
111+
(resolved_module == module_path).then(|| TypeAliasCandidate {
112+
item: entry.item.clone(),
113+
line_number: entry.line_number,
114+
module_path: resolved_module,
115+
})
116+
})
117+
.collect::<Vec<_>>();
118+
candidates.sort_by(|left, right| {
119+
left.item
120+
.ident
121+
.to_string()
122+
.cmp(&right.item.ident.to_string())
123+
.then(left.module_path.cmp(&right.module_path))
124+
.then(left.line_number.cmp(&right.line_number))
125+
});
126+
candidates.dedup_by(|left, right| {
127+
left.item.ident == right.item.ident
128+
&& left.module_path == right.module_path
129+
&& left.line_number == right.line_number
130+
});
131+
candidates
132+
}
133+
87134
/// Formats candidates for user-facing diagnostics.
88135
pub fn format_candidates(candidates: &[ItemCandidate]) -> String {
89136
candidates

0 commit comments

Comments
 (0)