@@ -523,48 +523,59 @@ undesirable, simply delete the `pre-push` file from .git/hooks."
523
523
/// Handles editor-specific setup differences
524
524
#[ derive( Clone , Debug , Eq , PartialEq ) ]
525
525
enum EditorKind {
526
- Vscode ,
527
- Vim ,
528
526
Emacs ,
529
527
Helix ,
528
+ Vim ,
529
+ VsCode ,
530
530
}
531
531
532
532
impl EditorKind {
533
533
fn prompt_user ( ) -> io:: Result < Option < EditorKind > > {
534
534
let prompt_str = "Available editors:
535
- 1. vscode
536
- 2. vim
537
- 3. emacs
538
- 4. helix
535
+ 1. Emacs
536
+ 2. Helix
537
+ 3. Vim
538
+ 4. VS Code
539
539
540
540
Select which editor you would like to set up [default: None]: " ;
541
541
542
542
let mut input = String :: new ( ) ;
543
543
loop {
544
544
print ! ( "{}" , prompt_str) ;
545
545
io:: stdout ( ) . flush ( ) ?;
546
- input. clear ( ) ;
547
546
io:: stdin ( ) . read_line ( & mut input) ?;
548
- match input. trim ( ) . to_lowercase ( ) . as_str ( ) {
549
- "1" | "vscode" => return Ok ( Some ( EditorKind :: Vscode ) ) ,
550
- "2" | "vim" => return Ok ( Some ( EditorKind :: Vim ) ) ,
551
- "3" | "emacs" => return Ok ( Some ( EditorKind :: Emacs ) ) ,
552
- "4" | "helix" => return Ok ( Some ( EditorKind :: Helix ) ) ,
553
- "" => return Ok ( None ) ,
547
+
548
+ let mut modified_input = input. to_lowercase ( ) ;
549
+ modified_input. retain ( |ch| !ch. is_whitespace ( ) ) ;
550
+ match modified_input. as_str ( ) {
551
+ "1" | "emacs" => return Ok ( Some ( EditorKind :: Emacs ) ) ,
552
+ "2" | "helix" => return Ok ( Some ( EditorKind :: Helix ) ) ,
553
+ "3" | "vim" => return Ok ( Some ( EditorKind :: Vim ) ) ,
554
+ "4" | "vscode" => return Ok ( Some ( EditorKind :: VsCode ) ) ,
555
+ "" | "none" => return Ok ( None ) ,
554
556
_ => {
555
557
eprintln ! ( "ERROR: unrecognized option '{}'" , input. trim( ) ) ;
556
558
eprintln ! ( "NOTE: press Ctrl+C to exit" ) ;
557
559
}
558
- } ;
560
+ }
561
+
562
+ input. clear ( ) ;
559
563
}
560
564
}
561
565
562
566
/// A list of historical hashes of each LSP settings file
563
567
/// New entries should be appended whenever this is updated so we can detect
564
568
/// outdated vs. user-modified settings files.
565
- fn hashes ( & self ) -> Vec < & str > {
569
+ fn hashes ( & self ) -> & ' static [ & ' static str ] {
566
570
match self {
567
- EditorKind :: Vscode | EditorKind :: Vim => vec ! [
571
+ EditorKind :: Emacs => & [
572
+ "51068d4747a13732440d1a8b8f432603badb1864fa431d83d0fd4f8fa57039e0" ,
573
+ "d29af4d949bbe2371eac928a3c31cf9496b1701aa1c45f11cd6c759865ad5c45" ,
574
+ ] ,
575
+ EditorKind :: Helix => {
576
+ & [ "2d3069b8cf1b977e5d4023965eb6199597755e6c96c185ed5f2854f98b83d233" ]
577
+ }
578
+ EditorKind :: Vim | EditorKind :: VsCode => & [
568
579
"ea67e259dedf60d4429b6c349a564ffcd1563cf41c920a856d1f5b16b4701ac8" ,
569
580
"56e7bf011c71c5d81e0bf42e84938111847a810eee69d906bba494ea90b51922" ,
570
581
"af1b5efe196aed007577899db9dae15d6dbc923d6fa42fa0934e68617ba9bbe0" ,
@@ -576,13 +587,6 @@ Select which editor you would like to set up [default: None]: ";
576
587
"4eecb58a2168b252077369da446c30ed0e658301efe69691979d1ef0443928f4" ,
577
588
"c394386e6133bbf29ffd32c8af0bb3d4aac354cba9ee051f29612aa9350f8f8d" ,
578
589
] ,
579
- EditorKind :: Emacs => vec ! [
580
- "51068d4747a13732440d1a8b8f432603badb1864fa431d83d0fd4f8fa57039e0" ,
581
- "d29af4d949bbe2371eac928a3c31cf9496b1701aa1c45f11cd6c759865ad5c45" ,
582
- ] ,
583
- EditorKind :: Helix => {
584
- vec ! [ "2d3069b8cf1b977e5d4023965eb6199597755e6c96c185ed5f2854f98b83d233" ]
585
- }
586
590
}
587
591
}
588
592
@@ -592,29 +596,29 @@ Select which editor you would like to set up [default: None]: ";
592
596
593
597
fn settings_short_path ( & self ) -> PathBuf {
594
598
self . settings_folder ( ) . join ( match self {
595
- EditorKind :: Vscode => "settings.json" ,
596
- EditorKind :: Vim => "coc-settings.json" ,
597
599
EditorKind :: Emacs => ".dir-locals.el" ,
598
600
EditorKind :: Helix => "languages.toml" ,
601
+ EditorKind :: Vim => "coc-settings.json" ,
602
+ EditorKind :: VsCode => "settings.json" ,
599
603
} )
600
604
}
601
605
602
606
fn settings_folder ( & self ) -> PathBuf {
603
607
match self {
604
- EditorKind :: Vscode => PathBuf :: from ( ".vscode" ) ,
605
- EditorKind :: Vim => PathBuf :: from ( ".vim" ) ,
606
608
EditorKind :: Emacs => PathBuf :: new ( ) ,
607
609
EditorKind :: Helix => PathBuf :: from ( ".helix" ) ,
610
+ EditorKind :: Vim => PathBuf :: from ( ".vim" ) ,
611
+ EditorKind :: VsCode => PathBuf :: from ( ".vscode" ) ,
608
612
}
609
613
}
610
614
611
- fn settings_template ( & self ) -> & str {
615
+ fn settings_template ( & self ) -> & ' static str {
612
616
match self {
613
- EditorKind :: Vscode | EditorKind :: Vim => {
614
- include_str ! ( "../../../../etc/rust_analyzer_settings.json" )
615
- }
616
617
EditorKind :: Emacs => include_str ! ( "../../../../etc/rust_analyzer_eglot.el" ) ,
617
618
EditorKind :: Helix => include_str ! ( "../../../../etc/rust_analyzer_helix.toml" ) ,
619
+ EditorKind :: Vim | EditorKind :: VsCode => {
620
+ include_str ! ( "../../../../etc/rust_analyzer_settings.json" )
621
+ }
618
622
}
619
623
}
620
624
0 commit comments