Skip to content

Commit

Permalink
allow selection of editor(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmsthebest committed Nov 17, 2024
1 parent 21294e7 commit d11f604
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
17 changes: 13 additions & 4 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,21 @@ 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());
}
}
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);
}
}
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions template/.helix/languages.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#INCLUDEFILE helix
[[language]]
name = "rust"

[language-server.rust-analyzer.config]
check.allTargets = false
cargo.target = "riscv32imac-unknown-none-elf"
3 changes: 2 additions & 1 deletion template/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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",
}
}

0 comments on commit d11f604

Please sign in to comment.