Skip to content

Commit

Permalink
Extract search_with_spinner() in Vim
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed May 28, 2024
1 parent 90ada17 commit ebebc16
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 20 deletions.
7 changes: 3 additions & 4 deletions crates/maple_core/src/stdio_server/provider/impls/blines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ impl BlinesProvider {
let search_context = ctx.search_context(stop_signal.clone());

tokio::spawn(async move {
let _ = vim.bare_exec("clap#spinner#set_busy");
crate::searcher::file::search(query, source_file, matcher, search_context)
.await;
let _ = vim.bare_exec("clap#spinner#set_idle");
let future =
crate::searcher::file::search(query, source_file, matcher, search_context);
vim.search_with_spinner(future).await;
})
};

Expand Down
6 changes: 3 additions & 3 deletions crates/maple_core/src/stdio_server/provider/impls/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ impl FilesProvider {
let vim = ctx.vim.clone();
let hidden = self.args.hidden;
tokio::spawn(async move {
let _ = vim.bare_exec("clap#spinner#set_busy");
crate::searcher::files::search(query, hidden, matcher, search_context).await;
let _ = vim.bare_exec("clap#spinner#set_idle");
let future =
crate::searcher::files::search(query, hidden, matcher, search_context);
vim.search_with_spinner(future).await;
})
};

Expand Down
5 changes: 2 additions & 3 deletions crates/maple_core/src/stdio_server/provider/impls/grep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ impl GrepProvider {
search_context.paths.extend_from_slice(&self.args.paths);
}
let join_handle = tokio::spawn(async move {
let _ = vim.bare_exec("clap#spinner#set_busy");
crate::searcher::grep::search(query, matcher, search_context).await;
let _ = vim.bare_exec("clap#spinner#set_idle");
let future = crate::searcher::grep::search(query, matcher, search_context);
vim.search_with_spinner(future).await;
});

let new_control = SearcherControl {
Expand Down
4 changes: 3 additions & 1 deletion crates/maple_core/src/stdio_server/provider/impls/igrep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ impl Grepper {

let new_control = {
let stop_signal = Arc::new(AtomicBool::new(false));
let vim = ctx.vim.clone();

let mut search_context = ctx.search_context(stop_signal.clone());
search_context.paths = vec![path];
let join_handle = tokio::spawn(async move {
crate::searcher::grep::search(query, matcher, search_context).await
let future = crate::searcher::grep::search(query, matcher, search_context);
vim.search_with_spinner(future).await
});

SearcherControl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ impl TagfilesProvider {
let join_handle = {
let search_context = ctx.search_context(stop_signal.clone());
let cwd = ctx.cwd.to_path_buf();
let vim = ctx.vim.clone();

tokio::spawn(async move {
crate::searcher::tagfiles::search(query, cwd, matcher, search_context).await;
let future =
crate::searcher::tagfiles::search(query, cwd, matcher, search_context);
vim.search_with_spinner(future).await;
})
};

Expand Down
5 changes: 4 additions & 1 deletion crates/maple_core/src/stdio_server/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ impl ProviderSession {
maybe_event = self.provider_events.recv() => {
match maybe_event {
Some(event) => {
tracing::trace!(debounce = true, "[{}] Recv debounced event: {event:?}", self.id);
let event_display = format!("{event:?}");
tracing::trace!(debounce = true, "[{}] Recv debounced event: {event_display}", self.id);

match event {
ProviderEvent::Internal(internal_event) => {
Expand All @@ -216,6 +217,7 @@ impl ProviderSession {
}
}
}
tracing::trace!("[{}] Processed event: {event_display}", self.id);
}
ProviderEvent::OnMove(params) => {
on_move.replace(params);
Expand All @@ -229,6 +231,7 @@ impl ProviderSession {
if let Err(err) = self.provider.on_key_event(&mut self.ctx, key_event).await {
tracing::error!(?err, "Failed to process key_event");
}
tracing::trace!("[{}] Processed event: {event_display}", self.id);
}
ProviderEvent::Exit => {
self.handle_exit();
Expand Down
7 changes: 7 additions & 0 deletions crates/maple_core/src/stdio_server/vim.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::stdio_server::provider::ProviderId;
use futures::Future;
use once_cell::sync::{Lazy, OnceCell};
use paths::AbsPathBuf;
use rpc::vim::RpcClient;
Expand Down Expand Up @@ -536,6 +537,12 @@ impl Vim {
let value: Value = self.call("buf_is_valid", [buf]).await?;
Ok(from_vim_bool(value))
}

pub async fn search_with_spinner(&self, future: impl Future<Output = ()>) {
let _ = self.bare_exec("clap#spinner#set_busy");
future.await;
let _ = self.bare_exec("clap#spinner#set_idle");
}
}

#[cfg(test)]
Expand Down
9 changes: 2 additions & 7 deletions crates/types/src/source_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ impl<'a> FuzzyText<'a> {
/// The location that a match should look in.
///
/// Given a query, the match scope can refer to a full string or a substring.
#[derive(Debug, Clone, Copy)]
#[derive(Default, Debug, Clone, Copy)]
pub enum MatchScope {
#[default]
Full,
/// `:Clap tags`, `:Clap proj_tags`
TagName,
Expand All @@ -52,12 +53,6 @@ pub enum MatchScope {
GrepLine,
}

impl Default for MatchScope {
fn default() -> Self {
Self::Full
}
}

impl std::str::FromStr for MatchScope {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand Down

0 comments on commit ebebc16

Please sign in to comment.