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 | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/helix-term/src/handlers/completion/path.rs b/helix-term/src/handlers/completion/path.rs index e92be51c..a16a0d5c 100644 --- a/helix-term/src/handlers/completion/path.rs +++ b/helix-term/src/handlers/completion/path.rs @@ -5,22 +5,21 @@ use std::{ str::FromStr as _, }; -use futures_util::{future::BoxFuture, FutureExt as _}; -use helix_core as core; 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; use url::Url; -use super::item::CompletionItem; +use crate::handlers::completion::{item::CompletionResponse, CompletionItem, CompletionItems}; pub(crate) fn path_completion( cursor: usize, text: core::Rope, doc: &Document, handle: TaskHandle, -) -> Option<BoxFuture<'static, anyhow::Result<Vec<CompletionItem>>>> { +) -> Option<impl Fn() -> CompletionResponse> { if !doc.path_completion_enabled() { return None; } @@ -67,12 +66,19 @@ pub(crate) fn path_completion( return None; } - let future = tokio::task::spawn_blocking(move || { + // TODO: handle properly in the future + const PRIORITY: i8 = 1; + let future = move || { let Ok(read_dir) = std::fs::read_dir(&dir_path) else { - return Vec::new(); + return CompletionResponse { + items: CompletionItems::Other(Vec::new()), + incomplete: false, + provider: CompletionProvider::PathCompletions, + priority: PRIORITY, // TODO: hand + }; }; - read_dir + let res: Vec<_> = read_dir .filter_map(Result::ok) .filter_map(|dir_entry| { dir_entry @@ -103,12 +109,19 @@ pub(crate) fn path_completion( label: file_name.into(), transaction, documentation, + provider: CompletionProvider::PathCompletions, })) }) - .collect::<Vec<_>>() - }); + .collect(); + CompletionResponse { + items: CompletionItems::Other(res), + incomplete: false, + provider: CompletionProvider::PathCompletions, + priority: PRIORITY, // TODO: hand + } + }; - Some(async move { Ok(future.await?) }.boxed()) + Some(future) } #[cfg(unix)] |