Skip to content

Commit

Permalink
Handle large file preview properly and various minor refactorings (#1110
Browse files Browse the repository at this point in the history
)

* Various minor improvements

* Refactor on_move

* Minor refactorings

* Handle large file preview properly

* .

* Update pyo3

* Fix test

* .

* Use utils::io::*

* .

* .

* .

* .

* .

* .

* Introduce FileClass

* Fix lost cached events

* clippy fixes

* files: try previewing if input is empty

* .
  • Loading branch information
liuchengxu authored Dec 28, 2024
1 parent 515e464 commit 1d1810e
Show file tree
Hide file tree
Showing 56 changed files with 2,048 additions and 956 deletions.
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ chrono = { version = "0.4", features = ["serde"] }
chrono-humanize = "0.2.3"
clap = { version = "4.2", features = ["derive"] }
colors-transform = "0.2.11"
content_inspector = "0.2.4"
criterion = "0.5"
directories = "4.0"
futures = "0.3"
Expand All @@ -63,6 +64,7 @@ indicatif = "0.16"
itertools = "0.10"
lsp = { package = "lsp-types", version = "0.94" }
memchr = "2.5"
memmap2 = "0.9.5"
num_cpus = "1.13"
once_cell = "1.7"
parking_lot = "0.12"
Expand Down
2 changes: 1 addition & 1 deletion autoload/clap/picker.vim
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function! clap#picker#update(update_info) abort

call clap#sign#ensure_exists()

if has_key(update_info, 'preview')
if has_key(update_info, 'preview') && update_info.preview isnot v:null
if !empty(update_info.preview)
call clap#picker#update_preview(update_info.preview)
endif
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rayon::prelude::*;
use std::io::BufRead;
use std::sync::Arc;
use types::ClapItem;
use utils::line_count;
use utils::io::line_count;

fn prepare_source_items() -> Vec<SourceItem> {
let largest_cache = find_largest_cache_digest().expect("Cache is empty");
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/blines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Blines {
filter::dyn_run(
&self.query,
filter_context,
SequentialSource::List(blines_item_stream()),
SequentialSource::Iterator(blines_item_stream()),
)?;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use maple_core::dirs::Dirs;
use std::fs::read_dir;
use std::io::Write;
use std::path::{PathBuf, MAIN_SEPARATOR};
use utils::remove_dir_contents;
use utils::io::remove_dir_contents;

/// List and remove all the cached contents.
#[derive(Subcommand, Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/ctags/recursive_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl RecursiveTags {
filter::dyn_run(
self.query.as_deref().unwrap_or_default(),
filter_context,
SequentialSource::List(ctags_cmd.tag_item_iter()?.map(|tag_item| {
SequentialSource::Iterator(ctags_cmd.tag_item_iter()?.map(|tag_item| {
let item: Arc<dyn ClapItem> = Arc::new(tag_item);
item
})),
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/command/filter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::app::Args;
use anyhow::Result;
use clap::Parser;
use filter::{filter_sequential, FilterContext, ParallelSource, SequentialSource};
use filter::{filter_sequential, FilterContext, ParallelInputSource, SequentialSource};
use maple_core::paths::AbsPathBuf;
use matcher::{Bonus, FuzzyAlgorithm, MatchScope, MatcherBuilder};
use printer::Printer;
Expand Down Expand Up @@ -101,21 +101,21 @@ impl Filter {
}
}

fn generate_par_source(&self) -> ParallelSource {
fn generate_parallel_input_source(&self) -> ParallelInputSource {
if let Some(ref cmd_str) = self.cmd {
let exec = if let Some(ref dir) = self.cmd_dir {
Exec::shell(cmd_str).cwd(dir)
} else {
Exec::shell(cmd_str)
};
ParallelSource::Exec(Box::new(exec))
ParallelInputSource::Exec(Box::new(exec))
} else {
let file = self
.input
.as_ref()
.map(|i| i.deref().clone())
.expect("Only File and Exec source can be parallel");
ParallelSource::File(file)
ParallelInputSource::File(file)
}
}

Expand Down Expand Up @@ -165,7 +165,7 @@ impl Filter {
filter::par_dyn_run(
&self.query,
FilterContext::new(icon, number, winwidth, matcher_builder),
self.generate_par_source(),
self.generate_parallel_input_source(),
)?;
} else {
filter::dyn_run::<std::iter::Empty<_>>(
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/command/grep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod live_grep;
use crate::app::Args;
use anyhow::Result;
use clap::Parser;
use filter::{ParallelSource, SequentialSource};
use filter::{ParallelInputSource, SequentialSource};
use maple_core::tools::rg::{refresh_cache, rg_shell_command};
use matcher::MatchScope;
use std::path::PathBuf;
Expand Down Expand Up @@ -109,13 +109,13 @@ impl Grep {

if self.par_run {
let par_source = if let Some(cache) = maybe_usable_cache {
ParallelSource::File(cache)
ParallelInputSource::File(cache)
} else if let Some(ref tempfile) = self.input {
ParallelSource::File(tempfile.clone())
ParallelInputSource::File(tempfile.clone())
} else if let Some(ref dir) = self.cmd_dir {
ParallelSource::Exec(Box::new(Exec::shell(RG_EXEC_CMD).cwd(dir)))
ParallelInputSource::Exec(Box::new(Exec::shell(RG_EXEC_CMD).cwd(dir)))
} else {
ParallelSource::Exec(Box::new(Exec::shell(RG_EXEC_CMD)))
ParallelInputSource::Exec(Box::new(Exec::shell(RG_EXEC_CMD)))
};

// TODO: Improve the responsiveness of ripgrep as it can emit the items after some time.
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/helptags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::Parser;
use maple_core::helptags::generate_tag_lines;
use maple_core::paths::AbsPathBuf;
use std::io::Write;
use utils::read_lines;
use utils::io::read_lines;

/// Parse and display Vim helptags.
#[derive(Parser, Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use maple_core::process::ShellCommand;
use printer::{println_json, println_json_with_length};
use std::path::{Path, PathBuf};
use std::process::Command as StdCommand;
use utils::{line_count, read_first_lines};
use utils::io::{line_count, read_first_lines};

#[derive(Debug, Clone)]
#[allow(unused)]
Expand Down
4 changes: 2 additions & 2 deletions crates/filter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use std::sync::Arc;
use types::{ClapItem, FileNameItem, GrepItem};

pub use self::parallel_worker::{
par_dyn_run, par_dyn_run_inprocess, par_dyn_run_list, BestItems, ParallelSource,
StdioProgressor,
par_dyn_run, par_dyn_run_inprocess, par_dyn_run_list, ParallelInputSource, StdioProgressor,
TopMatches,
};
pub use self::sequential_source::{filter_sequential, SequentialSource};
pub use self::sequential_worker::dyn_run;
Expand Down
Loading

0 comments on commit 1d1810e

Please sign in to comment.