@@ -4,6 +4,7 @@ use std::borrow::Cow;
44use std:: io:: Write as _;
55use std:: sync:: { atomic, Mutex } ;
66
7+ use annotate_snippets:: Annotation ;
78use annotate_snippets:: AnnotationKind ;
89use annotate_snippets:: Group ;
910use annotate_snippets:: Level ;
@@ -162,15 +163,11 @@ fn typo_to_group<'t>(msg: &'t Typo<'t>) -> Group<'t> {
162163 Some ( Context :: File ( context) ) => {
163164 let path = context. path . as_os_str ( ) . to_string_lossy ( ) ;
164165 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)
174171 }
175172 Some ( Context :: Path ( context) ) => {
176173 let path = context
@@ -180,16 +177,26 @@ fn typo_to_group<'t>(msg: &'t Typo<'t>) -> Group<'t> {
180177 . join ( "" ) ;
181178 let path = path. as_os_str ( ) . to_string_lossy ( ) ;
182179 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)
187183 }
188184 Some ( _) | None => group,
189185 } ;
190186 group
191187}
192188
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+
193200fn error_to_group < ' e > ( error : & ' e Error < ' e > ) -> Group < ' e > {
194201 let group = Group :: with_title ( Level :: ERROR . primary_title ( & error. msg ) ) ;
195202 match & error. context {
0 commit comments