@@ -495,90 +495,6 @@ impl<'a> Toolchain<'a> {
495
495
Ok ( ( ) )
496
496
} )
497
497
}
498
- // Distributable only. Installed only.
499
- fn get_component_suggestion (
500
- & self ,
501
- component : & Component ,
502
- manifest : & Manifest ,
503
- only_installed : bool ,
504
- ) -> Option < String > {
505
- use strsim:: damerau_levenshtein;
506
-
507
- // Suggest only for very small differences
508
- // High number can result in inaccurate suggestions for short queries e.g. `rls`
509
- const MAX_DISTANCE : usize = 3 ;
510
-
511
- let distributable = DistributableToolchain :: new ( & self ) ;
512
- let components = distributable. ok ( ) . map ( |d| d. list_components ( ) ) ;
513
- if let Some ( Ok ( components) ) = components {
514
- let short_name_distance = components
515
- . iter ( )
516
- . filter ( |c| !only_installed || c. installed )
517
- . map ( |c| {
518
- (
519
- damerau_levenshtein (
520
- & c. component . name ( manifest) [ ..] ,
521
- & component. name ( manifest) [ ..] ,
522
- ) ,
523
- c,
524
- )
525
- } )
526
- . min_by_key ( |t| t. 0 )
527
- . expect ( "There should be always at least one component" ) ;
528
-
529
- let long_name_distance = components
530
- . iter ( )
531
- . filter ( |c| !only_installed || c. installed )
532
- . map ( |c| {
533
- (
534
- damerau_levenshtein (
535
- & c. component . name_in_manifest ( ) [ ..] ,
536
- & component. name ( manifest) [ ..] ,
537
- ) ,
538
- c,
539
- )
540
- } )
541
- . min_by_key ( |t| t. 0 )
542
- . expect ( "There should be always at least one component" ) ;
543
-
544
- let mut closest_distance = short_name_distance;
545
- let mut closest_match = short_name_distance. 1 . component . short_name ( manifest) ;
546
-
547
- // Find closer suggestion
548
- if short_name_distance. 0 > long_name_distance. 0 {
549
- closest_distance = long_name_distance;
550
-
551
- // Check if only targets differ
552
- if closest_distance. 1 . component . short_name_in_manifest ( )
553
- == component. short_name_in_manifest ( )
554
- {
555
- closest_match = long_name_distance. 1 . component . target ( ) ;
556
- } else {
557
- closest_match = long_name_distance
558
- . 1
559
- . component
560
- . short_name_in_manifest ( )
561
- . to_string ( ) ;
562
- }
563
- } else {
564
- // Check if only targets differ
565
- if closest_distance. 1 . component . short_name ( manifest)
566
- == component. short_name ( manifest)
567
- {
568
- closest_match = short_name_distance. 1 . component . target ( ) ;
569
- }
570
- }
571
-
572
- // If suggestion is too different don't suggest anything
573
- if closest_distance. 0 > MAX_DISTANCE {
574
- None
575
- } else {
576
- Some ( closest_match)
577
- }
578
- } else {
579
- None
580
- }
581
- }
582
498
// Distributable and Custom. Installed only.
583
499
pub fn binary_file ( & self , name : & str ) -> PathBuf {
584
500
let mut path = self . path . clone ( ) ;
@@ -691,8 +607,7 @@ impl<'a> DistributableToolchain<'a> {
691
607
return Err ( ErrorKind :: UnknownComponent (
692
608
self . 0 . name . to_string ( ) ,
693
609
component. description ( & manifest) ,
694
- self . 0
695
- . get_component_suggestion ( & component, & manifest, false ) ,
610
+ self . get_component_suggestion ( & component, & manifest, false ) ,
696
611
)
697
612
. into ( ) ) ;
698
613
}
@@ -719,6 +634,90 @@ impl<'a> DistributableToolchain<'a> {
719
634
}
720
635
}
721
636
637
+ // Installed only?
638
+ fn get_component_suggestion (
639
+ & self ,
640
+ component : & Component ,
641
+ manifest : & Manifest ,
642
+ only_installed : bool ,
643
+ ) -> Option < String > {
644
+ use strsim:: damerau_levenshtein;
645
+
646
+ // Suggest only for very small differences
647
+ // High number can result in inaccurate suggestions for short queries e.g. `rls`
648
+ const MAX_DISTANCE : usize = 3 ;
649
+
650
+ let components = self . list_components ( ) ;
651
+ if let Ok ( components) = components {
652
+ let short_name_distance = components
653
+ . iter ( )
654
+ . filter ( |c| !only_installed || c. installed )
655
+ . map ( |c| {
656
+ (
657
+ damerau_levenshtein (
658
+ & c. component . name ( manifest) [ ..] ,
659
+ & component. name ( manifest) [ ..] ,
660
+ ) ,
661
+ c,
662
+ )
663
+ } )
664
+ . min_by_key ( |t| t. 0 )
665
+ . expect ( "There should be always at least one component" ) ;
666
+
667
+ let long_name_distance = components
668
+ . iter ( )
669
+ . filter ( |c| !only_installed || c. installed )
670
+ . map ( |c| {
671
+ (
672
+ damerau_levenshtein (
673
+ & c. component . name_in_manifest ( ) [ ..] ,
674
+ & component. name ( manifest) [ ..] ,
675
+ ) ,
676
+ c,
677
+ )
678
+ } )
679
+ . min_by_key ( |t| t. 0 )
680
+ . expect ( "There should be always at least one component" ) ;
681
+
682
+ let mut closest_distance = short_name_distance;
683
+ let mut closest_match = short_name_distance. 1 . component . short_name ( manifest) ;
684
+
685
+ // Find closer suggestion
686
+ if short_name_distance. 0 > long_name_distance. 0 {
687
+ closest_distance = long_name_distance;
688
+
689
+ // Check if only targets differ
690
+ if closest_distance. 1 . component . short_name_in_manifest ( )
691
+ == component. short_name_in_manifest ( )
692
+ {
693
+ closest_match = long_name_distance. 1 . component . target ( ) ;
694
+ } else {
695
+ closest_match = long_name_distance
696
+ . 1
697
+ . component
698
+ . short_name_in_manifest ( )
699
+ . to_string ( ) ;
700
+ }
701
+ } else {
702
+ // Check if only targets differ
703
+ if closest_distance. 1 . component . short_name ( manifest)
704
+ == component. short_name ( manifest)
705
+ {
706
+ closest_match = short_name_distance. 1 . component . target ( ) ;
707
+ }
708
+ }
709
+
710
+ // If suggestion is too different don't suggest anything
711
+ if closest_distance. 0 > MAX_DISTANCE {
712
+ None
713
+ } else {
714
+ Some ( closest_match)
715
+ }
716
+ } else {
717
+ None
718
+ }
719
+ }
720
+
722
721
// Installed only.
723
722
fn get_manifest ( & self ) -> Result < Option < Manifest > > {
724
723
if !self . 0 . exists ( ) {
@@ -854,7 +853,7 @@ impl<'a> DistributableToolchain<'a> {
854
853
return Err ( ErrorKind :: UnknownComponent (
855
854
self . 0 . name . to_string ( ) ,
856
855
component. description ( & manifest) ,
857
- self . 0 . get_component_suggestion ( & component, & manifest, true ) ,
856
+ self . get_component_suggestion ( & component, & manifest, true ) ,
858
857
)
859
858
. into ( ) ) ;
860
859
}
0 commit comments