From 9ee1eb331858d75359fc1449154db7237277613c Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 30 Oct 2024 15:11:40 +0100 Subject: [PATCH] More usability changes (#5) * feat: start selecting project paths from the output_dir * feat: Sort the entries, directories first --- asm-lsp/config_builder.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/asm-lsp/config_builder.rs b/asm-lsp/config_builder.rs index 47013314..fe0d78dc 100644 --- a/asm-lsp/config_builder.rs +++ b/asm-lsp/config_builder.rs @@ -81,7 +81,7 @@ impl TryFrom 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}", @@ -110,7 +110,7 @@ impl TryFrom 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}", @@ -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());