Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/handlers/completion/path.rs')
| -rw-r--r-- | helix-term/src/handlers/completion/path.rs | 54 |
1 files changed, 23 insertions, 31 deletions
diff --git a/helix-term/src/handlers/completion/path.rs b/helix-term/src/handlers/completion/path.rs index c2ffa5ef..a16a0d5c 100644 --- a/helix-term/src/handlers/completion/path.rs +++ b/helix-term/src/handlers/completion/path.rs @@ -3,29 +3,27 @@ use std::{ fs, path::{Path, PathBuf}, str::FromStr as _, - sync::Arc, }; -use helix_core::{self as core, completion::CompletionProvider, Selection, Transaction}; +use helix_core::Transaction; +use helix_core::{self as core, completion::CompletionProvider}; use helix_event::TaskHandle; use helix_stdx::path::{self, canonicalize, fold_home_dir, get_path_suffix}; -use helix_view::{document::SavePoint, handlers::completion::ResponseContext, Document}; +use helix_view::Document; use url::Url; use crate::handlers::completion::{item::CompletionResponse, CompletionItem, CompletionItems}; pub(crate) fn path_completion( - selection: Selection, + cursor: usize, + text: core::Rope, doc: &Document, handle: TaskHandle, - savepoint: Arc<SavePoint>, -) -> Option<impl FnOnce() -> CompletionResponse> { +) -> Option<impl Fn() -> CompletionResponse> { if !doc.path_completion_enabled() { return None; } - let text = doc.text().clone(); - let cursor = selection.primary().cursor(text.slice(..)); let cur_line = text.char_to_line(cursor); let start = text.line_to_char(cur_line).max(cursor.saturating_sub(1000)); let line_until_cursor = text.slice(start..cursor); @@ -74,20 +72,12 @@ pub(crate) fn path_completion( let Ok(read_dir) = std::fs::read_dir(&dir_path) else { return CompletionResponse { items: CompletionItems::Other(Vec::new()), - provider: CompletionProvider::Path, - context: ResponseContext { - is_incomplete: false, - priority: PRIORITY, - savepoint, - }, + incomplete: false, + provider: CompletionProvider::PathCompletions, + priority: PRIORITY, // TODO: hand }; }; - let edit_diff = typed_file_name - .as_ref() - .map(|s| s.chars().count()) - .unwrap_or_default(); - let res: Vec<_> = read_dir .filter_map(Result::ok) .filter_map(|dir_entry| { @@ -104,28 +94,30 @@ pub(crate) fn path_completion( let kind = path_kind(&md); let documentation = path_documentation(&md, &dir_path.join(&file_name), kind); - let transaction = Transaction::change_by_selection(&text, &selection, |range| { - let cursor = range.cursor(text.slice(..)); - (cursor - edit_diff, cursor, Some((&file_name).into())) - }); + let edit_diff = typed_file_name + .as_ref() + .map(|f| f.len()) + .unwrap_or_default(); + + let transaction = Transaction::change( + &text, + std::iter::once((cursor - edit_diff, cursor, Some((&file_name).into()))), + ); Some(CompletionItem::Other(core::CompletionItem { kind: Cow::Borrowed(kind), label: file_name.into(), transaction, - documentation: Some(documentation), - provider: CompletionProvider::Path, + documentation, + provider: CompletionProvider::PathCompletions, })) }) .collect(); CompletionResponse { items: CompletionItems::Other(res), - provider: CompletionProvider::Path, - context: ResponseContext { - is_incomplete: false, - priority: PRIORITY, - savepoint, - }, + incomplete: false, + provider: CompletionProvider::PathCompletions, + priority: PRIORITY, // TODO: hand } }; |