@@ -8,9 +8,8 @@ use std::{
8
8
} ;
9
9
10
10
use ide:: {
11
- CompletionConfig , CompletionResolveCapability , FileId , FilePosition , FileRange , HoverAction ,
12
- HoverGotoTypeData , NavigationTarget , Query , RangeInfo , Runnable , RunnableKind , SearchScope ,
13
- TextEdit ,
11
+ CompletionResolveCapability , FileId , FilePosition , FileRange , HoverAction , HoverGotoTypeData ,
12
+ NavigationTarget , Query , RangeInfo , Runnable , RunnableKind , SearchScope , TextEdit ,
14
13
} ;
15
14
use itertools:: Itertools ;
16
15
use lsp_server:: ErrorCode ;
@@ -578,14 +577,11 @@ pub(crate) fn handle_completion(
578
577
let mut new_completion_items =
579
578
to_proto:: completion_item ( & line_index, line_endings, item. clone ( ) ) ;
580
579
581
- for new_item in & mut new_completion_items {
582
- let _ = fill_resolve_data (
583
- & mut new_item. data ,
584
- & item,
585
- & snap. config . completion ,
586
- & text_document_position,
587
- )
588
- . take ( ) ;
580
+ if snap. config . completion . resolve_additional_edits_lazily ( ) {
581
+ for new_item in & mut new_completion_items {
582
+ let _ = fill_resolve_data ( & mut new_item. data , & item, & text_document_position)
583
+ . take ( ) ;
584
+ }
589
585
}
590
586
591
587
new_completion_items
@@ -600,12 +596,12 @@ pub(crate) fn handle_completion_resolve(
600
596
snap : GlobalStateSnapshot ,
601
597
mut original_completion : CompletionItem ,
602
598
) -> Result < CompletionItem > {
603
- let _p = profile:: span ( "handle_resolve_completion " ) ;
599
+ let _p = profile:: span ( "handle_completion_resolve " ) ;
604
600
605
601
if !all_edits_are_disjoint ( & original_completion, & [ ] ) {
606
602
return Err ( LspError :: new (
607
603
ErrorCode :: InvalidParams as i32 ,
608
- "Received a completion with disjoint edits" . into ( ) ,
604
+ "Received a completion with overlapping edits, this is not LSP-compliant " . into ( ) ,
609
605
)
610
606
. into ( ) ) ;
611
607
}
@@ -635,7 +631,7 @@ pub(crate) fn handle_completion_resolve(
635
631
let line_endings = snap. file_line_endings ( file_id) ;
636
632
let offset = from_proto:: offset ( & line_index, resolve_data. position . position ) ;
637
633
638
- let mut additional_edits = snap
634
+ let additional_edits = snap
639
635
. analysis
640
636
. resolve_completion_edits (
641
637
& snap. config . completion ,
@@ -652,13 +648,14 @@ pub(crate) fn handle_completion_resolve(
652
648
if !all_edits_are_disjoint ( & original_completion, & additional_edits) {
653
649
return Err ( LspError :: new (
654
650
ErrorCode :: InternalError as i32 ,
655
- "Import edit is not disjoint with the original completion edits" . into ( ) ,
651
+ "Import edit overlaps with the original completion edits, this is not LSP-compliant"
652
+ . into ( ) ,
656
653
)
657
654
. into ( ) ) ;
658
655
}
659
656
660
657
if let Some ( original_additional_edits) = original_completion. additional_text_edits . as_mut ( ) {
661
- original_additional_edits. extend ( additional_edits. drain ( .. ) )
658
+ original_additional_edits. extend ( additional_edits. into_iter ( ) )
662
659
} else {
663
660
original_completion. additional_text_edits = Some ( additional_edits) ;
664
661
}
@@ -1634,22 +1631,19 @@ struct CompletionResolveData {
1634
1631
fn fill_resolve_data (
1635
1632
resolve_data : & mut Option < serde_json:: Value > ,
1636
1633
item : & ide:: CompletionItem ,
1637
- completion_config : & CompletionConfig ,
1638
1634
position : & TextDocumentPositionParams ,
1639
1635
) -> Option < ( ) > {
1640
- if completion_config. resolve_additional_edits_lazily ( ) {
1641
- let import_edit = item. import_to_add ( ) ?;
1642
- let full_import_path = import_edit. import_path . to_string ( ) ;
1643
- let imported_name = import_edit. import_path . segments . clone ( ) . pop ( ) ?. to_string ( ) ;
1644
-
1645
- * resolve_data = Some (
1646
- to_value ( CompletionResolveData {
1647
- position : position. to_owned ( ) ,
1648
- full_import_path,
1649
- imported_name,
1650
- } )
1651
- . unwrap ( ) ,
1652
- )
1653
- }
1636
+ let import_edit = item. import_to_add ( ) ?;
1637
+ let full_import_path = import_edit. import_path . to_string ( ) ;
1638
+ let imported_name = import_edit. import_path . segments . clone ( ) . pop ( ) ?. to_string ( ) ;
1639
+
1640
+ * resolve_data = Some (
1641
+ to_value ( CompletionResolveData {
1642
+ position : position. to_owned ( ) ,
1643
+ full_import_path,
1644
+ imported_name,
1645
+ } )
1646
+ . unwrap ( ) ,
1647
+ ) ;
1654
1648
Some ( ( ) )
1655
1649
}
0 commit comments