@@ -12,7 +12,6 @@ use ide_db::{
1212use stdx:: never;
1313use syntax:: {
1414 ast:: { self , make, AstNode , AstToken } ,
15- format_smolstr,
1615SyntaxKind :: { BLOCK_EXPR , EXPR_STMT , FOR_EXPR , IF_EXPR , LOOP_EXPR , STMT_LIST , WHILE_EXPR } ,
1716TextRange , TextSize ,
1817} ;
@@ -56,11 +55,10 @@ pub(crate) fn complete_postfix(
5655None => return ,
5756} ;
5857
59- let postfix_snippet =
60- match build_postfix_snippet_builder ( ctx, cap, dot_receiver, & receiver_text) {
61- Some ( it) => it,
62- None => return ,
63- } ;
58+ let postfix_snippet = match build_postfix_snippet_builder ( ctx, cap, dot_receiver) {
59+ Some ( it) => it,
60+ None => return ,
61+ } ;
6462
6563if let Some ( drop_trait) = ctx. famous_defs ( ) . core_ops_Drop ( ) {
6664if receiver_ty. impls_trait ( ctx. db , drop_trait, & [ ] ) {
@@ -175,11 +173,10 @@ pub(crate) fn complete_postfix(
175173let ( dot_receiver, node_to_replace_with) = include_references ( dot_receiver) ;
176174let receiver_text =
177175get_receiver_text ( & node_to_replace_with, receiver_is_ambiguous_float_literal) ;
178- let postfix_snippet =
179- match build_postfix_snippet_builder ( ctx, cap, & dot_receiver, & receiver_text) {
180- Some ( it) => it,
181- None => return ,
182- } ;
176+ let postfix_snippet = match build_postfix_snippet_builder ( ctx, cap, & dot_receiver) {
177+ Some ( it) => it,
178+ None => return ,
179+ } ;
183180
184181if !ctx. config . snippets . is_empty ( ) {
185182add_custom_postfix_completions ( acc, ctx, & postfix_snippet, & receiver_text) ;
@@ -320,7 +317,6 @@ fn build_postfix_snippet_builder<'ctx>(
320317ctx : & ' ctx CompletionContext < ' _ > ,
321318cap : SnippetCap ,
322319receiver : & ' ctx ast:: Expr ,
323- receiver_text : & ' ctx str ,
324320) -> Option < impl Fn ( & str , & str , & str ) -> Builder + ' ctx > {
325321let receiver_range = ctx. sema . original_range_opt ( receiver. syntax ( ) ) ?. range ;
326322if ctx. source_range ( ) . end ( ) < receiver_range. start ( ) {
@@ -336,16 +332,13 @@ fn build_postfix_snippet_builder<'ctx>(
336332fn build < ' ctx > (
337333ctx : & ' ctx CompletionContext < ' _ > ,
338334cap : SnippetCap ,
339- receiver_text : & ' ctx str ,
340335delete_range : TextRange ,
341336) -> impl Fn ( & str , & str , & str ) -> Builder + ' ctx {
342337move |label, detail, snippet| {
343338let edit = TextEdit :: replace ( delete_range, snippet. to_owned ( ) ) ;
344- let mut item = CompletionItem :: new ( CompletionItemKind :: Snippet , delete_range, label) ;
339+ let mut item =
340+ CompletionItem :: new ( CompletionItemKind :: Snippet , ctx. source_range ( ) , label) ;
345341 item. detail ( detail) . snippet_edit ( cap, edit) ;
346- // Editors may filter completion item with the text within delete_range, so we need to
347- // include the receiver text in the lookup for editors to find the completion item.
348- item. lookup_by ( format_smolstr ! ( "{}.{}" , receiver_text, label) ) ;
349342let postfix_match = if ctx. original_token . text ( ) == label {
350343 cov_mark:: hit!( postfix_exact_match_is_high_priority) ;
351344Some ( CompletionRelevancePostfixMatch :: Exact )
@@ -358,7 +351,7 @@ fn build_postfix_snippet_builder<'ctx>(
358351 item
359352}
360353}
361- Some ( build ( ctx, cap, receiver_text , delete_range) )
354+ Some ( build ( ctx, cap, delete_range) )
362355}
363356
364357fn add_custom_postfix_completions (
@@ -519,7 +512,7 @@ fn main() {
519512#[ test]
520513fn option_iflet ( ) {
521514check_edit (
522- "bar. ifl" ,
515+ "ifl" ,
523516r#"
524517//- minicore: option
525518fn main() {
@@ -541,7 +534,7 @@ fn main() {
541534#[ test]
542535fn option_letelse ( ) {
543536check_edit (
544- "bar. lete" ,
537+ "lete" ,
545538r#"
546539//- minicore: option
547540fn main() {
564557#[ test]
565558fn result_match ( ) {
566559check_edit (
567- "bar. match" ,
560+ "match" ,
568561r#"
569562//- minicore: result
570563fn main() {
@@ -586,13 +579,13 @@ fn main() {
586579
587580#[ test]
588581fn postfix_completion_works_for_ambiguous_float_literal ( ) {
589- check_edit ( "42. refm" , r#"fn main() { 42.$0 }"# , r#"fn main() { &mut 42 }"# )
582+ check_edit ( "refm" , r#"fn main() { 42.$0 }"# , r#"fn main() { &mut 42 }"# )
590583}
591584
592585#[ test]
593586fn works_in_simple_macro ( ) {
594587check_edit (
595- "bar. dbg" ,
588+ "dbg" ,
596589r#"
597590macro_rules! m { ($e:expr) => { $e } }
598591fn main() {
@@ -612,10 +605,10 @@ fn main() {
612605
613606#[ test]
614607fn postfix_completion_for_references ( ) {
615- check_edit ( "&&42. dbg" , r#"fn main() { &&42.$0 }"# , r#"fn main() { dbg!(&&42) }"# ) ;
616- check_edit ( "42. refm" , r#"fn main() { &&42.$0 }"# , r#"fn main() { &&&mut 42 }"# ) ;
608+ check_edit ( "dbg" , r#"fn main() { &&42.$0 }"# , r#"fn main() { dbg!(&&42) }"# ) ;
609+ check_edit ( "refm" , r#"fn main() { &&42.$0 }"# , r#"fn main() { &&&mut 42 }"# ) ;
617610check_edit (
618- "bar. ifl" ,
611+ "ifl" ,
619612r#"
620613//- minicore: option
621614fn main() {
@@ -636,39 +629,35 @@ fn main() {
636629
637630#[ test]
638631fn postfix_completion_for_unsafe ( ) {
639- check_edit ( "foo.unsafe" , r#"fn main() { foo.$0 }"# , r#"fn main() { unsafe { foo } }"# ) ;
640- check_edit (
641- "{ foo }.unsafe" ,
642- r#"fn main() { { foo }.$0 }"# ,
643- r#"fn main() { unsafe { foo } }"# ,
644- ) ;
632+ check_edit ( "unsafe" , r#"fn main() { foo.$0 }"# , r#"fn main() { unsafe { foo } }"# ) ;
633+ check_edit ( "unsafe" , r#"fn main() { { foo }.$0 }"# , r#"fn main() { unsafe { foo } }"# ) ;
645634check_edit (
646- "if x { foo }. unsafe" ,
635+ "unsafe" ,
647636r#"fn main() { if x { foo }.$0 }"# ,
648637r#"fn main() { unsafe { if x { foo } } }"# ,
649638) ;
650639check_edit (
651- "loop { foo }. unsafe" ,
640+ "unsafe" ,
652641r#"fn main() { loop { foo }.$0 }"# ,
653642r#"fn main() { unsafe { loop { foo } } }"# ,
654643) ;
655644check_edit (
656- "if true {}. unsafe" ,
645+ "unsafe" ,
657646r#"fn main() { if true {}.$0 }"# ,
658647r#"fn main() { unsafe { if true {} } }"# ,
659648) ;
660649check_edit (
661- "while true {}. unsafe" ,
650+ "unsafe" ,
662651r#"fn main() { while true {}.$0 }"# ,
663652r#"fn main() { unsafe { while true {} } }"# ,
664653) ;
665654check_edit (
666- "for i in 0..10 {}. unsafe" ,
655+ "unsafe" ,
667656r#"fn main() { for i in 0..10 {}.$0 }"# ,
668657r#"fn main() { unsafe { for i in 0..10 {} } }"# ,
669658) ;
670659check_edit (
671- "if true {1} else {2}. unsafe" ,
660+ "unsafe" ,
672661r#"fn main() { let x = if true {1} else {2}.$0 }"# ,
673662r#"fn main() { let x = unsafe { if true {1} else {2} } }"# ,
674663) ;
@@ -698,7 +687,7 @@ fn main() {
698687
699688check_edit_with_config (
700689 config. clone ( ) ,
701- "42. break" ,
690+ "break" ,
702691r#"
703692//- minicore: try
704693fn main() { 42.$0 }
@@ -717,7 +706,7 @@ fn main() { ControlFlow::Break(42) }
717706// what users would see. Unescaping happens thereafter.
718707check_edit_with_config (
719708 config. clone ( ) ,
720- r#"'\\\\'. break"# ,
709+ " break",
721710r#"
722711//- minicore: try
723712fn main() { '\\'.$0 }
@@ -731,10 +720,7 @@ fn main() { ControlFlow::Break('\\\\') }
731720
732721check_edit_with_config (
733722 config,
734- r#"match true {
735- true => "\${1:placeholder}",
736- false => "\\\$",
737- }.break"# ,
723+ "break" ,
738724r#"
739725//- minicore: try
740726fn main() {
@@ -760,47 +746,39 @@ fn main() {
760746#[ test]
761747fn postfix_completion_for_format_like_strings ( ) {
762748check_edit (
763- r#""{some_var:?}". format"# ,
749+ " format",
764750r#"fn main() { "{some_var:?}".$0 }"# ,
765751r#"fn main() { format!("{some_var:?}") }"# ,
766752) ;
767753check_edit (
768- r#""Panic with {a}". panic"# ,
754+ " panic",
769755r#"fn main() { "Panic with {a}".$0 }"# ,
770756r#"fn main() { panic!("Panic with {a}") }"# ,
771757) ;
772758check_edit (
773- r#""{ 2+2 } { SomeStruct { val: 1, other: 32 } :?}". println"# ,
759+ " println",
774760r#"fn main() { "{ 2+2 } { SomeStruct { val: 1, other: 32 } :?}".$0 }"# ,
775761r#"fn main() { println!("{} {:?}", 2+2, SomeStruct { val: 1, other: 32 }) }"# ,
776762) ;
777763check_edit (
778- r#""{2+2}". loge"# ,
764+ " loge",
779765r#"fn main() { "{2+2}".$0 }"# ,
780766r#"fn main() { log::error!("{}", 2+2) }"# ,
781767) ;
782768check_edit (
783- r#""{2+2}". logt"# ,
769+ " logt",
784770r#"fn main() { "{2+2}".$0 }"# ,
785771r#"fn main() { log::trace!("{}", 2+2) }"# ,
786772) ;
787773check_edit (
788- r#""{2+2}". logd"# ,
774+ " logd",
789775r#"fn main() { "{2+2}".$0 }"# ,
790776r#"fn main() { log::debug!("{}", 2+2) }"# ,
791777) ;
778+ check_edit ( "logi" , r#"fn main() { "{2+2}".$0 }"# , r#"fn main() { log::info!("{}", 2+2) }"# ) ;
779+ check_edit ( "logw" , r#"fn main() { "{2+2}".$0 }"# , r#"fn main() { log::warn!("{}", 2+2) }"# ) ;
792780check_edit (
793- r#""{2+2}".logi"# ,
794- r#"fn main() { "{2+2}".$0 }"# ,
795- r#"fn main() { log::info!("{}", 2+2) }"# ,
796- ) ;
797- check_edit (
798- r#""{2+2}".logw"# ,
799- r#"fn main() { "{2+2}".$0 }"# ,
800- r#"fn main() { log::warn!("{}", 2+2) }"# ,
801- ) ;
802- check_edit (
803- r#""{2+2}".loge"# ,
781+ "loge" ,
804782r#"fn main() { "{2+2}".$0 }"# ,
805783r#"fn main() { log::error!("{}", 2+2) }"# ,
806784) ;
@@ -822,21 +800,21 @@ fn main() {
822800
823801check_edit_with_config (
824802CompletionConfig { snippets : vec ! [ snippet. clone( ) ] , ..TEST_CONFIG } ,
825- "&&42. ok" ,
803+ "ok" ,
826804r#"fn main() { &&42.o$0 }"# ,
827805r#"fn main() { Ok(&&42) }"# ,
828806) ;
829807
830808check_edit_with_config (
831809CompletionConfig { snippets : vec ! [ snippet. clone( ) ] , ..TEST_CONFIG } ,
832- "&&42. ok" ,
810+ "ok" ,
833811r#"fn main() { &&42.$0 }"# ,
834812r#"fn main() { Ok(&&42) }"# ,
835813) ;
836814
837815check_edit_with_config (
838816CompletionConfig { snippets : vec ! [ snippet] , ..TEST_CONFIG } ,
839- "&a.a. ok" ,
817+ "ok" ,
840818r#"
841819struct A {
842820 a: i32,
0 commit comments