From e3f78b87937df2f16f32a905358f13a18785faaa Mon Sep 17 00:00:00 2001 From: Lee Wonjoon Date: Tue, 30 Jul 2024 13:28:41 +0000 Subject: [PATCH] Keep forward slash when autocomplete on Windows (#13321) Related #7044 # Description When autocomplete path with `/` on Windows, paths keep with slash instead of backslash(`\`). If mixed both, path completion uses a last path seperator. ![image](https://github.com/nushell/nushell/assets/4014016/b09633fd-0e4a-4cd9-9c14-2bca30625804) ![image](https://github.com/nushell/nushell/assets/4014016/e1f228f8-4cce-43eb-a34a-dfa54efd2ebb) ![image](https://github.com/nushell/nushell/assets/4014016/0694443a-3017-4828-be60-5f39ffd96440) # User-Facing Changes ![completion](https://github.com/nushell/nushell/assets/4014016/03626544-6a14-4d8b-a607-21a4472f8037) # Tests + Formatting # After Submitting --- .../src/completions/completion_common.rs | 20 +- crates/nu-cli/tests/completions/mod.rs | 229 +++++++++++++----- .../support/completions_helpers.rs | 16 +- 3 files changed, 186 insertions(+), 79 deletions(-) diff --git a/crates/nu-cli/src/completions/completion_common.rs b/crates/nu-cli/src/completions/completion_common.rs index b3bca778a9..d6882da57b 100644 --- a/crates/nu-cli/src/completions/completion_common.rs +++ b/crates/nu-cli/src/completions/completion_common.rs @@ -10,9 +10,7 @@ use nu_protocol::{ levenshtein_distance, Span, }; use nu_utils::get_ls_colors; -use std::path::{ - is_separator, Component, Path, PathBuf, MAIN_SEPARATOR as SEP, MAIN_SEPARATOR_STR, -}; +use std::path::{is_separator, Component, Path, PathBuf, MAIN_SEPARATOR as SEP}; use super::SortBy; @@ -93,16 +91,16 @@ enum OriginalCwd { } impl OriginalCwd { - fn apply(&self, mut p: PathBuiltFromString) -> String { + fn apply(&self, mut p: PathBuiltFromString, path_separator: char) -> String { match self { Self::None => {} Self::Home => p.parts.insert(0, "~".to_string()), Self::Prefix(s) => p.parts.insert(0, s.clone()), }; - let mut ret = p.parts.join(MAIN_SEPARATOR_STR); + let mut ret = p.parts.join(&path_separator.to_string()); if p.isdir { - ret.push(SEP); + ret.push(path_separator); } ret } @@ -133,6 +131,14 @@ pub fn complete_item( ) -> Vec<(nu_protocol::Span, String, Option