@@ -153,14 +153,12 @@ pub fn handle_on_type_formatting(
153
153
params : req:: DocumentOnTypeFormattingParams ,
154
154
) -> Result < Option < Vec < TextEdit > > > {
155
155
let _p = profile ( "handle_on_type_formatting" ) ;
156
- let file_id = params. text_document . try_conv_with ( & world) ?;
157
- let line_index = world. analysis ( ) . file_line_index ( file_id) ;
158
- let position = FilePosition {
159
- file_id,
160
- /// in `ra_ide_api`, the `on_type` invariant is that
161
- /// `text.char_at(position) == typed_char`.
162
- offset : params. position . conv_with ( & line_index) - TextUnit :: of_char ( '.' ) ,
163
- } ;
156
+ let mut position = params. text_document_position . try_conv_with ( & world) ?;
157
+ let line_index = world. analysis ( ) . file_line_index ( position. file_id ) ;
158
+
159
+ // in `ra_ide_api`, the `on_type` invariant is that
160
+ // `text.char_at(position) == typed_char`.
161
+ position. offset = position. offset - TextUnit :: of_char ( '.' ) ;
164
162
165
163
let edit = match params. ch . as_str ( ) {
166
164
"=" => world. analysis ( ) . on_eq_typed ( position) ,
@@ -407,12 +405,7 @@ pub fn handle_completion(
407
405
params : req:: CompletionParams ,
408
406
) -> Result < Option < req:: CompletionResponse > > {
409
407
let _p = profile ( "handle_completion" ) ;
410
- let position = {
411
- let file_id = params. text_document . try_conv_with ( & world) ?;
412
- let line_index = world. analysis ( ) . file_line_index ( file_id) ;
413
- let offset = params. position . conv_with ( & line_index) ;
414
- FilePosition { file_id, offset }
415
- } ;
408
+ let position = params. text_document_position . try_conv_with ( & world) ?;
416
409
let completion_triggered_after_single_colon = {
417
410
let mut res = false ;
418
411
if let Some ( ctx) = params. context {
@@ -543,9 +536,7 @@ pub fn handle_prepare_rename(
543
536
}
544
537
545
538
pub fn handle_rename ( world : WorldSnapshot , params : RenameParams ) -> Result < Option < WorkspaceEdit > > {
546
- let file_id = params. text_document . try_conv_with ( & world) ?;
547
- let line_index = world. analysis ( ) . file_line_index ( file_id) ;
548
- let offset = params. position . conv_with ( & line_index) ;
539
+ let position = params. text_document_position . try_conv_with ( & world) ?;
549
540
550
541
if params. new_name . is_empty ( ) {
551
542
return Err ( LspError :: new (
@@ -555,8 +546,7 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio
555
546
. into ( ) ) ;
556
547
}
557
548
558
- let optional_change =
559
- world. analysis ( ) . rename ( FilePosition { file_id, offset } , & * params. new_name ) ?;
549
+ let optional_change = world. analysis ( ) . rename ( position, & * params. new_name ) ?;
560
550
let change = match optional_change {
561
551
None => return Ok ( None ) ,
562
552
Some ( it) => it,
@@ -571,11 +561,10 @@ pub fn handle_references(
571
561
world : WorldSnapshot ,
572
562
params : req:: ReferenceParams ,
573
563
) -> Result < Option < Vec < Location > > > {
574
- let file_id = params. text_document . try_conv_with ( & world) ?;
575
- let line_index = world. analysis ( ) . file_line_index ( file_id) ;
576
- let offset = params. position . conv_with ( & line_index) ;
564
+ let position = params. text_document_position . try_conv_with ( & world) ?;
565
+ let line_index = world. analysis ( ) . file_line_index ( position. file_id ) ;
577
566
578
- let refs = match world. analysis ( ) . find_all_refs ( FilePosition { file_id , offset } ) ? {
567
+ let refs = match world. analysis ( ) . find_all_refs ( position ) ? {
579
568
None => return Ok ( None ) ,
580
569
Some ( refs) => refs,
581
570
} ;
0 commit comments