1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! Fancy diagnostics support using `ariadne`.
//!
//! This module provides convenient methods to convert errors carrying `SourcePosMixin`
//! (such as `LexWarningWithRange`, `ParseWarningWithRange`, `AstBuildWarningWithRange`,
//! `AstParseWarningWithRange`, and the aggregated `BmsWarning`) to `ariadne::Report`
//! without modifying existing error type definitions.
//!
//! Since `SourcePosMixin` contains index span information (start/end byte offsets), this module
//! lets ariadne automatically handle row/column calculations for display purposes.
//!
//! # Usage Example
//!
//! ```rust
//! # #[cfg(feature = "diagnostics")]
//! # {
//! use bms_rs::{
//! bms::{BmsWarning, default_config, command::channel::mapper::KeyLayoutBeat, parse_bms},
//! diagnostics::emit_bms_warnings,
//! };
//!
//! // Parse BMS file
//! let bms_source = "#TITLE Test\n#ARTIST Composer\n#INVALID command\n";
//! let output = parse_bms(bms_source, default_config());
//!
//! // Output all warnings
//! emit_bms_warnings("test.bms", bms_source, &output.warnings);
//! # }
//! ```
use ;
/// Simple source container that holds the filename and source text.
/// Ariadne will automatically handle row/column calculations from byte offsets.
///
/// # Usage Example
///
/// ```rust
/// use bms_rs::diagnostics::SimpleSource;
///
/// // Create source container
/// let source_text = "#TITLE test\n#ARTIST composer\n";
/// let source = SimpleSource::new("test.bms", source_text);
///
/// // Get source text
/// assert_eq!(source.text(), source_text);
/// ```
/// Trait for converting positioned errors to `ariadne::Report`.
///
/// # Usage Example
///
/// ```rust
/// use bms_rs::{diagnostics::{SimpleSource, ToAriadne, emit_bms_warnings}, bms::BmsWarning};
/// use ariadne::Source;
///
/// // Assume there are warnings generated during BMS parsing
/// let warnings: Vec<BmsWarning> = vec![/* warnings obtained from parsing */];
/// let source_text = "#TITLE test\n#ARTIST composer\n";
///
/// // Simpler way: use convenience function
/// emit_bms_warnings("test.bms", source_text, &warnings);
///
/// // Or handle each warning manually:
/// let source = SimpleSource::new("test.bms", source_text);
/// let ariadne_source = Source::from(source_text);
///
/// for warning in &warnings {
/// let report = warning.to_report(&source);
/// // Use ariadne to render the report - ariadne will automatically handle row/column calculation
/// let _ = report.print(("test.bms".to_string(), ariadne_source.clone()));
/// }
/// ```
/// Helper to build a styled ariadne `Report` consistently.
///
/// This reduces duplication across multiple `ToAriadne` implementations.
/// Convenience method: batch render `BmsWarning` list.
///
/// This function automatically creates `SimpleSource` and generates beautiful diagnostic output for each warning.
/// Ariadne will automatically handle row/column calculations from the provided byte ranges.
///
/// # Usage Example
///
/// ```rust
/// use bms_rs::{diagnostics::emit_bms_warnings, bms::BmsWarning};
///
/// // BMS source text
/// let bms_source = "#TITLE My Song\n#ARTIST Composer\n#BPM 120\n";
///
/// // Assume warning list obtained from parsing
/// let warnings: Vec<BmsWarning> = vec![/* parsing warnings */];
///
/// // Batch output all warnings - ariadne will automatically calculate row/column positions
/// emit_bms_warnings("my_song.bms", bms_source, &warnings);
/// ```
///
/// # Parameters
/// * `name` - Name of the source file, used for display in diagnostic information
/// * `source` - Complete BMS source text
/// * `warnings` - List of warnings to display
/// Collect `ariadne::Report` instances for a list of `BmsWarning` without printing.
///
/// This is useful in tests to verify diagnostics can be generated while keeping test output clean.
/// Examples continue to use `emit_bms_warnings` to render reports to the terminal.