Skip to content

Commit

Permalink
Editor select (#47)
Browse files Browse the repository at this point in the history
* allow selection of editor(s)

* add space to select

* Add editor selection to readme

* fix helix compile target

* add changelog
  • Loading branch information
rmsthebest authored Nov 18, 2024
1 parent 21294e7 commit f95959c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Added editor selection. Currently only helix and vscode

### Fixed

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ cargo install esp-generate
- `wokwi`: Adds support for Wokwi simulation using [VS Code Wokwi extension].
- `dev-container`: Adds support for [VS Code Dev Containers] and [GitHub Codespaces].
- `ci` Adds GitHub Actions support with some basics checks.
- `editors`: Select the editors that will be used with Rust-Analyzer:
- `helix`: The Helix Editor
- `vscode`: Visual Studio Code
[VS Code Wokwi extension]: https://marketplace.visualstudio.com/items?itemName=wokwi.wokwi-vscode
[VS Code Dev Containers]: https://code.visualstudio.com/docs/remote/containers#_quick-start-open-an-existing-folder-in-a-container
Expand Down
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
19 changes: 14 additions & 5 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 Expand Up @@ -187,7 +196,7 @@ impl App {
self.repository.up();
self.state.select(Some(0));
}
Char('l') | Right | Enter => {
Char('l') | Char(' ') | Right | Enter => {
let selected = self.state.selected().unwrap_or_default();
if self.repository.is_option(selected) {
self.repository.toggle_current(selected);
Expand Down
8 changes: 8 additions & 0 deletions template/.helix/languages.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#INCLUDEFILE helix
[[language]]
name = "rust"

[language-server.rust-analyzer.config]
check.allTargets = false
#REPLACE riscv32imac-unknown-none-elf rust_target
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 f95959c

Please sign in to comment.