Skip to content

Commit

Permalink
More usability changes (#5)
Browse files Browse the repository at this point in the history
* feat: start selecting project paths from the output_dir

* feat: Sort the entries, directories first
  • Loading branch information
lu-zero authored and WillLillis committed Nov 3, 2024
1 parent d29af2f commit 389f18b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions asm-lsp/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl TryFrom<GenerateArgs> for GenerateOpts {
path.push("asm-lsp");
path.push(".asm-lsp.toml");
path
} else if let Some(path) = value.output_dir {
} else if let Some(path) = value.output_dir.as_ref() {
let mut canonicalized_path = path.canonicalize().map_err(|e| {
format!(
"Failed to canonicalize target path: \"{}\" -- {e}",
Expand Down Expand Up @@ -110,7 +110,7 @@ impl TryFrom<GenerateArgs> for GenerateOpts {
}
};
let project_path = {
if let Some(path) = value.project_path {
if let Some(path) = value.project_path.as_ref().or(value.output_dir.as_ref()) {
let canonicalized_path = path.canonicalize().map_err(|e| {
format!(
"Failed to canonicalize project path: \"{}\" -- {e}",
Expand Down Expand Up @@ -189,8 +189,22 @@ fn prompt_project_path(opts: &GenerateOpts) -> PathBuf {
fallback_enter(&mut true_path);
return true_path;
};

let mut dir_entries = Vec::new();
let mut file_entries = Vec::new();
for entry in dir_reader.filter_map(std::result::Result::ok) {
let entry_path = entry.path();
if entry_path.is_dir() {
dir_entries.push(entry_path);
} else {
file_entries.push(entry_path);
}
}

dir_entries.sort();
file_entries.sort();

for entry_path in dir_entries.into_iter().chain(file_entries) {
path_entries.push(entry_path.clone());
if let Some(name) = entry_path.file_name() {
display_entries.push(name.to_string_lossy().to_string());
Expand Down

0 comments on commit 389f18b

Please sign in to comment.