From d11f60454d91174fcc57455127c8f0d0fe6d7784 Mon Sep 17 00:00:00 2001 From: tony Date: Sun, 17 Nov 2024 18:29:42 +0100 Subject: [PATCH] allow selection of editor(s) --- src/main.rs | 20 ++++++++++++++++++++ src/tui.rs | 17 +++++++++++++---- template/.helix/languages.toml | 7 +++++++ template/.vscode/settings.json | 3 ++- 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 template/.helix/languages.toml diff --git a/src/main.rs b/src/main.rs index 82c0d4b..9f282c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -162,6 +162,26 @@ static OPTIONS: &[GeneratorOptionItem] = &[ }), ], }), + GeneratorOptionItem::Category(GeneratorOptionCategory { + name: "editor", + display_name: "Optional editor config files for rust-analyzer", + options: &[ + GeneratorOptionItem::Option(GeneratorOption { + name: "helix", + display_name: "Rust-Analyzer settings for Helix Editor", + enables: &[], + disables: &[], + chips: &[], + }), + GeneratorOptionItem::Option(GeneratorOption { + name: "vscode", + display_name: "Rust-Analyzer settings for Visual Studio Code", + enables: &[], + disables: &[], + chips: &[], + }), + ], + }), ]; #[derive(Parser, Debug)] diff --git a/src/tui.rs b/src/tui.rs index c76afe9..042cce9 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -69,7 +69,10 @@ impl Repository { let currently_selected = self.selected.clone(); for option in currently_selected { - let option = find_option(option, self.options).unwrap(); + let Some(option) = find_option(&option, self.options) else { + ratatui::restore(); + panic!("option not found"); + }; for enable in option.enables { if !self.selected.contains(&enable.to_string()) { self.selected.push(enable.to_string()); @@ -77,7 +80,10 @@ impl Repository { } for disable in option.disables { if self.selected.contains(&disable.to_string()) { - let idx = self.selected.iter().position(|v| v == disable).unwrap(); + let Some(idx) = self.selected.iter().position(|v| v == disable) else { + ratatui::restore(); + panic!("disable option not found"); + }; self.selected.remove(idx); } } @@ -122,13 +128,16 @@ impl Repository { } fn find_option( - option: String, + option: &str, options: &'static [GeneratorOptionItem], ) -> Option<&'static GeneratorOption> { for item in options { match item { GeneratorOptionItem::Category(category) => { - return find_option(option, category.options) + let found_option = find_option(option, category.options); + if found_option.is_some() { + return found_option; + } } GeneratorOptionItem::Option(item) => { if item.name == option { diff --git a/template/.helix/languages.toml b/template/.helix/languages.toml new file mode 100644 index 0000000..c223c02 --- /dev/null +++ b/template/.helix/languages.toml @@ -0,0 +1,7 @@ +#INCLUDEFILE helix +[[language]] +name = "rust" + +[language-server.rust-analyzer.config] +check.allTargets = false +cargo.target = "riscv32imac-unknown-none-elf" diff --git a/template/.vscode/settings.json b/template/.vscode/settings.json index be03535..019dd55 100644 --- a/template/.vscode/settings.json +++ b/template/.vscode/settings.json @@ -1,5 +1,6 @@ +//INCLUDEFILE vscode { "rust-analyzer.cargo.allTargets": false, //REPLACE riscv32imac-unknown-none-elf rust_target "rust-analyzer.cargo.target": "riscv32imac-unknown-none-elf", -} \ No newline at end of file +}