@@ -11,6 +11,7 @@ pub mod mark;
1111mod fixture;
1212
1313use std:: {
14+ convert:: TryInto ,
1415 env, fs,
1516 path:: { Path , PathBuf } ,
1617} ;
@@ -168,8 +169,10 @@ pub fn extract_annotations(text: &str) -> Vec<(TextRange, String)> {
168169 for line in lines_with_ends ( text) {
169170 if let Some ( idx) = line. find ( "//^" ) {
170171 let offset = prev_line_start. unwrap ( ) + TextSize :: of ( & line[ ..idx + "//" . len ( ) ] ) ;
171- let data = line[ idx + "//^" . len ( ) ..] . trim ( ) . to_string ( ) ;
172- res. push ( ( TextRange :: at ( offset, 1 . into ( ) ) , data) )
172+ let marker_and_data = & line[ idx + "//" . len ( ) ..] ;
173+ let len = marker_and_data. chars ( ) . take_while ( |& it| it == '^' ) . count ( ) ;
174+ let data = marker_and_data[ len..] . trim ( ) . to_string ( ) ;
175+ res. push ( ( TextRange :: at ( offset, len. try_into ( ) . unwrap ( ) ) , data) )
173176 }
174177 prev_line_start = Some ( line_start) ;
175178 line_start += TextSize :: of ( line) ;
@@ -184,15 +187,15 @@ fn test_extract_annotations() {
184187fn main() {
185188 let x = 92;
186189 //^ def
187- z + 1
188- } //^ i32
190+ zoo + 1
191+ } //^^^ i32
189192 "# ,
190193 ) ;
191194 let res = extract_annotations ( & text)
192195 . into_iter ( )
193196 . map ( |( range, ann) | ( & text[ range] , ann) )
194197 . collect :: < Vec < _ > > ( ) ;
195- assert_eq ! ( res, vec![ ( "x" , "def" . into( ) ) , ( "z " , "i32" . into( ) ) , ] ) ;
198+ assert_eq ! ( res, vec![ ( "x" , "def" . into( ) ) , ( "zoo " , "i32" . into( ) ) , ] ) ;
196199}
197200
198201// Comparison functionality borrowed from cargo:
0 commit comments