@@ -4,6 +4,7 @@ use std::borrow::Cow;
4
4
use std:: io:: Write as _;
5
5
use std:: sync:: { atomic, Mutex } ;
6
6
7
+ use annotate_snippets:: Annotation ;
7
8
use annotate_snippets:: AnnotationKind ;
8
9
use annotate_snippets:: Group ;
9
10
use annotate_snippets:: Level ;
@@ -162,15 +163,11 @@ fn typo_to_group<'t>(msg: &'t Typo<'t>) -> Group<'t> {
162
163
Some ( Context :: File ( context) ) => {
163
164
let path = context. path . as_os_str ( ) . to_string_lossy ( ) ;
164
165
let line = String :: from_utf8_lossy ( msg. buffer . as_ref ( ) ) ;
165
- let span_start = msg. byte_offset ;
166
- let span_end = span_start + msg. typo . len ( ) ;
167
- let span = span_start..span_end;
168
- group. element (
169
- Snippet :: source ( line)
170
- . path ( path)
171
- . line_start ( context. line_num )
172
- . annotation ( AnnotationKind :: Primary . span ( span) ) ,
173
- )
166
+ let snippet = Snippet :: source ( line)
167
+ . path ( path)
168
+ . line_start ( context. line_num ) ;
169
+ let snippet = append_corrections ( msg, 0 , snippet) ;
170
+ group. element ( snippet)
174
171
}
175
172
Some ( Context :: Path ( context) ) => {
176
173
let path = context
@@ -180,16 +177,26 @@ fn typo_to_group<'t>(msg: &'t Typo<'t>) -> Group<'t> {
180
177
. join ( "" ) ;
181
178
let path = path. as_os_str ( ) . to_string_lossy ( ) ;
182
179
let line = context. path . as_os_str ( ) . to_string_lossy ( ) ;
183
- let span_start = msg. byte_offset + path. len ( ) ;
184
- let span_end = span_start + msg. typo . len ( ) ;
185
- let span = span_start..span_end;
186
- group. element ( Snippet :: source ( line) . annotation ( AnnotationKind :: Primary . span ( span) ) )
180
+ let snippet = Snippet :: source ( line) ;
181
+ let snippet = append_corrections ( msg, path. len ( ) , snippet) ;
182
+ group. element ( snippet)
187
183
}
188
184
Some ( _) | None => group,
189
185
} ;
190
186
group
191
187
}
192
188
189
+ fn append_corrections < ' t > (
190
+ msg : & ' t Typo < ' t > ,
191
+ offset : usize ,
192
+ snippet : Snippet < ' t , Annotation < ' t > > ,
193
+ ) -> Snippet < ' t , Annotation < ' t > > {
194
+ let span_start = msg. byte_offset + offset;
195
+ let span_end = span_start + msg. typo . len ( ) ;
196
+ let span = span_start..span_end;
197
+ snippet. annotation ( AnnotationKind :: Primary . span ( span) )
198
+ }
199
+
193
200
fn error_to_group < ' e > ( error : & ' e Error < ' e > ) -> Group < ' e > {
194
201
let group = Group :: with_title ( Level :: ERROR . primary_title ( & error. msg ) ) ;
195
202
match & error. context {
0 commit comments