@@ -593,40 +593,6 @@ impl Completions {
593593 }
594594 self . add_opt ( render_struct_pat ( RenderContext :: new ( ctx) , pattern_ctx, strukt, local_name) ) ;
595595 }
596-
597- /// Sort the suggestions with `new` like functions first.
598- /// That means:
599- /// fn with no param that returns itself
600- /// fn with param that returns itself
601- pub ( crate ) fn sort_new_first ( & mut self ) {
602- // ToDo: Ensure these fn returns Self
603- fn maybe_new ( item : & CompletionItem ) -> bool {
604- item. detail . as_ref ( ) . map ( |d| d. starts_with ( "fn() -> " ) ) . unwrap_or_default ( )
605- }
606- fn maybe_new_with_args ( item : & CompletionItem ) -> bool {
607- item. detail
608- . as_ref ( )
609- . map ( |d| d. starts_with ( "fn(" ) && d. contains ( "->" ) && !d. contains ( "&self" ) )
610- . unwrap_or_default ( )
611- }
612-
613- fn maybe_builder ( item : & CompletionItem ) -> bool {
614- item. detail
615- . as_ref ( )
616- . map ( |d| d. starts_with ( "fn() -> " ) && d. contains ( "Builder" ) )
617- . unwrap_or_default ( )
618- }
619-
620- for item in self . buf . iter_mut ( ) {
621- if maybe_new ( & item) {
622- item. bump_relevance_by ( 30 ) ;
623- } else if maybe_builder ( & item) {
624- item. bump_relevance_by ( 20 ) ;
625- } else if maybe_new_with_args ( & item) {
626- item. bump_relevance_by ( 10 ) ;
627- }
628- }
629- }
630596}
631597
632598/// Calls the callback for each variant of the provided enum with the path to the variant.
@@ -730,7 +696,7 @@ pub(super) fn complete_name_ref(
730696 snippet:: complete_expr_snippet ( acc, ctx, path_ctx, expr_ctx) ;
731697
732698 if matches ! ( ctx. token. kind( ) , syntax:: SyntaxKind :: COLON2 ) {
733- acc . sort_new_first ( ) ;
699+ bump_relevance_for_new_like_fns ( acc ) ;
734700 }
735701 }
736702 PathKind :: Type { location } => {
@@ -805,3 +771,37 @@ fn complete_patterns(
805771 pattern:: complete_pattern ( acc, ctx, pattern_ctx) ;
806772 record:: complete_record_pattern_fields ( acc, ctx, pattern_ctx) ;
807773}
774+
775+ /// Sort the suggestions with `new` like functions first.
776+ /// That means:
777+ /// fn with no param that returns itself
778+ /// fn with param that returns itself
779+ pub ( crate ) fn bump_relevance_for_new_like_fns ( acc : & mut Completions ) {
780+ // ToDo: Ensure these fn returns Self
781+ fn maybe_new ( item : & CompletionItem ) -> bool {
782+ item. detail . as_ref ( ) . map ( |d| d. starts_with ( "fn() -> " ) ) . unwrap_or_default ( )
783+ }
784+ fn maybe_new_with_args ( item : & CompletionItem ) -> bool {
785+ item. detail
786+ . as_ref ( )
787+ . map ( |d| d. starts_with ( "fn(" ) && d. contains ( "->" ) && !d. contains ( "&self" ) )
788+ . unwrap_or_default ( )
789+ }
790+
791+ fn maybe_builder ( item : & CompletionItem ) -> bool {
792+ item. detail
793+ . as_ref ( )
794+ . map ( |d| d. starts_with ( "fn() -> " ) && d. contains ( "Builder" ) )
795+ . unwrap_or_default ( )
796+ }
797+
798+ for item in acc. buf . iter_mut ( ) {
799+ if maybe_new ( & item) {
800+ item. bump_relevance_by ( 30 ) ;
801+ } else if maybe_builder ( & item) {
802+ item. bump_relevance_by ( 20 ) ;
803+ } else if maybe_new_with_args ( & item) {
804+ item. bump_relevance_by ( 10 ) ;
805+ }
806+ }
807+ }
0 commit comments