From 381732197e7ca268ab209c12c10744c22a12b085 Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Sun, 20 Oct 2024 00:59:15 +0200 Subject: [PATCH] Address review feedback --- helix-term/src/handlers/completion.rs | 15 +++++++++------ helix-term/src/handlers/completion/path.rs | 14 ++++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/helix-term/src/handlers/completion.rs b/helix-term/src/handlers/completion.rs index ce9ed7f7c..edd54c5e3 100644 --- a/helix-term/src/handlers/completion.rs +++ b/helix-term/src/handlers/completion.rs @@ -369,13 +369,16 @@ pub fn trigger_auto_completion( }) if triggers.iter().any(|trigger| text.ends_with(trigger))) }); - let trigger_path_completion = matches!( - text.get_bytes_at(text.len_bytes()) - .and_then(|t| t.reversed().next()), - Some(b'/' | b'\\') - ) && doc.path_completion_enabled(); + let cursor_char = text + .get_bytes_at(text.len_bytes()) + .and_then(|t| t.reversed().next()); - if is_trigger_char || trigger_path_completion { + #[cfg(windows)] + let is_path_completion_trigger = matches!(cursor_char, Some(b'/' | b'\\')); + #[cfg(not(windows))] + let is_path_completion_trigger = matches!(cursor_char, Some(b'/')); + + if is_trigger_char || (is_path_completion_trigger && doc.path_completion_enabled()) { send_blocking( tx, CompletionEvent::TriggerChar { diff --git a/helix-term/src/handlers/completion/path.rs b/helix-term/src/handlers/completion/path.rs index 15e2423c6..2bd04c65f 100644 --- a/helix-term/src/handlers/completion/path.rs +++ b/helix-term/src/handlers/completion/path.rs @@ -49,7 +49,11 @@ pub(crate) fn path_completion( Some(parent_dir) if path.is_relative() => parent_dir.join(&path), _ => path.into_owned(), }; + #[cfg(windows)] let ends_with_slash = matches!(matched_path.as_bytes().last(), Some(b'/' | b'\\')); + #[cfg(not(windows))] + let ends_with_slash = matches!(matched_path.as_bytes().last(), Some(b'/')); + if ends_with_slash { Some((PathBuf::from(path.as_path()), None)) } else { @@ -81,17 +85,15 @@ pub(crate) fn path_completion( dir_entry .metadata() .ok() - .map(|md| (dir_entry.file_name(), md)) + .and_then(|md| Some((dir_entry.file_name().into_string().ok()?, md))) }) .map_while(|(file_name, md)| { if cancel.load(Ordering::Relaxed) { return None; } - let file_name_str = file_name.to_string_lossy().to_string(); - let kind = path_kind(&md); - let documentation = path_documentation(&md, &dir_path.join(file_name), kind); + let documentation = path_documentation(&md, &dir_path.join(&file_name), kind); let edit_diff = typed_file_name .as_ref() @@ -100,12 +102,12 @@ pub(crate) fn path_completion( let transaction = Transaction::change( &text, - std::iter::once((cursor - edit_diff, cursor, Some((&file_name_str).into()))), + std::iter::once((cursor - edit_diff, cursor, Some((&file_name).into()))), ); Some(CompletionItem::Other(core::CompletionItem { kind: Cow::Borrowed(kind), - label: file_name_str.into(), + label: file_name.into(), transaction, documentation, }))