@@ -11,7 +11,7 @@ use ra_ap_hir_def::hir::{CaptureBy, ExprId, LabelId, MatchArm, PatId, Statement}
1111use ra_ap_ide_db:: line_index:: LineIndex ;
1212use ra_ap_ide_db:: { label, LineIndexDatabase , RootDatabase } ;
1313use ra_ap_syntax:: ast:: RangeOp ;
14- use ra_ap_syntax:: { AstNode , Edition } ;
14+ use ra_ap_syntax:: { AstNode , Edition , TextRange , TextSize } ;
1515use ra_ap_vfs:: { FileId , Vfs } ;
1616use std:: collections:: HashMap ;
1717use std:: fs;
@@ -81,11 +81,9 @@ impl CrateTranslator<'_> {
8181 . file_id ( )
8282 . map ( |f| ( f. file_id ( ) , source) )
8383 . and_then ( |( file_id, source) | self . emit_file ( file_id) . map ( |data| ( data, source) ) )
84- . and_then ( |( data, source) | {
84+ . map ( |( data, source) | {
8585 let range = source. value . text_range ( ) ;
86- let start = data. line_index . line_col ( range. start ( ) ) ;
87- let end = data. line_index . line_col ( range. end ( ) ) ;
88- Some ( self . trap . emit_location ( data. label , start, end) )
86+ self . emit_location_textrange ( data, range)
8987 } )
9088 }
9189
@@ -151,12 +149,19 @@ impl CrateTranslator<'_> {
151149 . and_then ( |( file_id, source) | self . emit_file ( file_id) . map ( |data| ( data, source) ) )
152150 . map ( |( data, source) | {
153151 let range = source. value . syntax ( ) . text_range ( ) ;
154- let start = data. line_index . line_col ( range. start ( ) ) ;
155- let end = data. line_index . line_col ( range. end ( ) ) ;
156- self . trap . emit_location ( data. label , start, end)
152+ self . emit_location_textrange ( data, range)
157153 } )
158154 }
159-
155+ fn emit_location_textrange ( & mut self , data : FileData , range : TextRange ) -> trap:: Label {
156+ let start = data. line_index . line_col ( range. start ( ) ) ;
157+ let end = data. line_index . line_col (
158+ range
159+ . end ( )
160+ . checked_sub ( TextSize :: new ( 1 ) )
161+ . unwrap_or ( range. end ( ) ) ,
162+ ) ;
163+ self . trap . emit_location ( data. label , start, end)
164+ }
160165 fn emit_label (
161166 & mut self ,
162167 label_id : LabelId ,
0 commit comments