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.rs40
1 files changed, 30 insertions, 10 deletions
diff --git a/helix-term/src/handlers/completion/path.rs b/helix-term/src/handlers/completion/path.rs
index db04c456..21dc9c31 100644
--- a/helix-term/src/handlers/completion/path.rs
+++ b/helix-term/src/handlers/completion/path.rs
@@ -3,22 +3,23 @@ use std::{
fs,
path::{Path, PathBuf},
str::FromStr as _,
+ sync::Arc,
};
-use futures_util::{future::BoxFuture, FutureExt as _};
use helix_core::{self as core, completion::CompletionProvider, Selection, Transaction};
use helix_event::TaskHandle;
use helix_stdx::path::{self, canonicalize, fold_home_dir, get_path_suffix};
-use helix_view::Document;
+use helix_view::{document::SavePoint, handlers::completion::ResponseContext, Document};
use url::Url;
-use super::item::CompletionItem;
+use crate::handlers::completion::{item::CompletionResponse, CompletionItem, CompletionItems};
pub(crate) fn path_completion(
selection: Selection,
doc: &Document,
handle: TaskHandle,
-) -> Option<BoxFuture<'static, anyhow::Result<Vec<CompletionItem>>>> {
+ savepoint: Arc<SavePoint>,
+) -> Option<impl FnOnce() -> CompletionResponse> {
if !doc.path_completion_enabled() {
return None;
}
@@ -67,9 +68,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()),
+ provider: CompletionProvider::Path,
+ context: ResponseContext {
+ is_incomplete: false,
+ priority: PRIORITY,
+ savepoint,
+ },
+ };
};
let edit_diff = typed_file_name
@@ -77,7 +88,7 @@ pub(crate) fn path_completion(
.map(|s| s.chars().count())
.unwrap_or_default();
- read_dir
+ let res: Vec<_> = read_dir
.filter_map(Result::ok)
.filter_map(|dir_entry| {
dir_entry
@@ -106,10 +117,19 @@ pub(crate) fn path_completion(
provider: CompletionProvider::Path,
}))
})
- .collect::<Vec<_>>()
- });
+ .collect();
+ CompletionResponse {
+ items: CompletionItems::Other(res),
+ provider: CompletionProvider::Path,
+ context: ResponseContext {
+ is_incomplete: false,
+ priority: PRIORITY,
+ savepoint,
+ },
+ }
+ };
- Some(async move { Ok(future.await?) }.boxed())
+ Some(future)
}
#[cfg(unix)]