Skip to content

Commit 18d7ffa

Browse files
committed
Prepare ./x setup to handle more IDEs; make minor improvements
* Order IDEs alphabetically so that manually searching for an IDE is easier, both when running `./x setup` and when editing the source code behind `./x setup` * Prepare for IDEs with spaces in their names * Allow explicitly typing 'none' for the IDE * Change capitalization of `Vscode` to the more standard `VsCode` * Make minor efficiency improvements * Add `'static` annotations where they apply
1 parent 608e228 commit 18d7ffa

File tree

1 file changed

+35
-31
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+35
-31
lines changed

src/bootstrap/src/core/build_steps/setup.rs

+35-31
Original file line numberDiff line numberDiff line change
@@ -523,48 +523,59 @@ undesirable, simply delete the `pre-push` file from .git/hooks."
523523
/// Handles editor-specific setup differences
524524
#[derive(Clone, Debug, Eq, PartialEq)]
525525
enum EditorKind {
526-
Vscode,
527-
Vim,
528526
Emacs,
529527
Helix,
528+
Vim,
529+
VsCode,
530530
}
531531

532532
impl EditorKind {
533533
fn prompt_user() -> io::Result<Option<EditorKind>> {
534534
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
539539
540540
Select which editor you would like to set up [default: None]: ";
541541

542542
let mut input = String::new();
543543
loop {
544544
print!("{}", prompt_str);
545545
io::stdout().flush()?;
546-
input.clear();
547546
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),
554556
_ => {
555557
eprintln!("ERROR: unrecognized option '{}'", input.trim());
556558
eprintln!("NOTE: press Ctrl+C to exit");
557559
}
558-
};
560+
}
561+
562+
input.clear();
559563
}
560564
}
561565

562566
/// A list of historical hashes of each LSP settings file
563567
/// New entries should be appended whenever this is updated so we can detect
564568
/// outdated vs. user-modified settings files.
565-
fn hashes(&self) -> Vec<&str> {
569+
fn hashes(&self) -> &'static [&'static str] {
566570
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 => &[
568579
"ea67e259dedf60d4429b6c349a564ffcd1563cf41c920a856d1f5b16b4701ac8",
569580
"56e7bf011c71c5d81e0bf42e84938111847a810eee69d906bba494ea90b51922",
570581
"af1b5efe196aed007577899db9dae15d6dbc923d6fa42fa0934e68617ba9bbe0",
@@ -576,13 +587,6 @@ Select which editor you would like to set up [default: None]: ";
576587
"4eecb58a2168b252077369da446c30ed0e658301efe69691979d1ef0443928f4",
577588
"c394386e6133bbf29ffd32c8af0bb3d4aac354cba9ee051f29612aa9350f8f8d",
578589
],
579-
EditorKind::Emacs => vec![
580-
"51068d4747a13732440d1a8b8f432603badb1864fa431d83d0fd4f8fa57039e0",
581-
"d29af4d949bbe2371eac928a3c31cf9496b1701aa1c45f11cd6c759865ad5c45",
582-
],
583-
EditorKind::Helix => {
584-
vec!["2d3069b8cf1b977e5d4023965eb6199597755e6c96c185ed5f2854f98b83d233"]
585-
}
586590
}
587591
}
588592

@@ -592,29 +596,29 @@ Select which editor you would like to set up [default: None]: ";
592596

593597
fn settings_short_path(&self) -> PathBuf {
594598
self.settings_folder().join(match self {
595-
EditorKind::Vscode => "settings.json",
596-
EditorKind::Vim => "coc-settings.json",
597599
EditorKind::Emacs => ".dir-locals.el",
598600
EditorKind::Helix => "languages.toml",
601+
EditorKind::Vim => "coc-settings.json",
602+
EditorKind::VsCode => "settings.json",
599603
})
600604
}
601605

602606
fn settings_folder(&self) -> PathBuf {
603607
match self {
604-
EditorKind::Vscode => PathBuf::from(".vscode"),
605-
EditorKind::Vim => PathBuf::from(".vim"),
606608
EditorKind::Emacs => PathBuf::new(),
607609
EditorKind::Helix => PathBuf::from(".helix"),
610+
EditorKind::Vim => PathBuf::from(".vim"),
611+
EditorKind::VsCode => PathBuf::from(".vscode"),
608612
}
609613
}
610614

611-
fn settings_template(&self) -> &str {
615+
fn settings_template(&self) -> &'static str {
612616
match self {
613-
EditorKind::Vscode | EditorKind::Vim => {
614-
include_str!("../../../../etc/rust_analyzer_settings.json")
615-
}
616617
EditorKind::Emacs => include_str!("../../../../etc/rust_analyzer_eglot.el"),
617618
EditorKind::Helix => include_str!("../../../../etc/rust_analyzer_helix.toml"),
619+
EditorKind::Vim | EditorKind::VsCode => {
620+
include_str!("../../../../etc/rust_analyzer_settings.json")
621+
}
618622
}
619623
}
620624

0 commit comments

Comments
 (0)