feat: pass search length to the search url domain

This commit is contained in:
Jed 2026-06-15 22:05:44 +02:00
parent 21ed8e0167
commit d95d323a89

View file

@ -1,4 +1,4 @@
use std::process::Stdio; use std::{fmt::format, process::Stdio};
use anyhow::Result; use anyhow::Result;
use tokio::{ use tokio::{
@ -22,7 +22,7 @@ pub fn rg(opt: RgOpt) -> Result<UnboundedReceiver<File>> {
.args(["--color=never", "--no-heading", "--column", "--smart-case"]) .args(["--color=never", "--no-heading", "--column", "--smart-case"])
.arg(if opt.hidden { "--hidden" } else { "--no-hidden" }) .arg(if opt.hidden { "--hidden" } else { "--no-hidden" })
.args(opt.args) .args(opt.args)
.arg(opt.subject) .arg(opt.subject.clone())
.current_dir(&*opt.cwd.as_url().unified_path()) .current_dir(&*opt.cwd.as_url().unified_path())
.kill_on_drop(true) .kill_on_drop(true)
.stdout(Stdio::piped()) .stdout(Stdio::piped())
@ -42,7 +42,9 @@ pub fn rg(opt: RgOpt) -> Result<UnboundedReceiver<File>> {
let Some((file_path, line, col)) = parse_rg_line(&search_line) else { continue }; let Some((file_path, line, col)) = parse_rg_line(&search_line) else { continue };
if current_file != file_path { if current_file != file_path {
let Some(url) = build_file_url(opt.cwd.clone(), &current_file, &current_occurrences) else { let Some(url) =
build_file_url(opt.cwd.clone(), opt.subject.clone(), &current_file, &current_occurrences)
else {
continue; continue;
}; };
@ -57,7 +59,7 @@ pub fn rg(opt: RgOpt) -> Result<UnboundedReceiver<File>> {
} }
if current_occurrences.len() > 0 { if current_occurrences.len() > 0 {
match build_file_url(opt.cwd, &current_file, &current_occurrences) { match build_file_url(opt.cwd, opt.subject, &current_file, &current_occurrences) {
Some(url) => { Some(url) => {
if let Ok(file) = File::new(url).await { if let Ok(file) = File::new(url).await {
tx.send(file).ok(); tx.send(file).ok();
@ -73,10 +75,16 @@ pub fn rg(opt: RgOpt) -> Result<UnboundedReceiver<File>> {
Ok(rx) Ok(rx)
} }
fn build_file_url(cwd: UrlBuf, file_path: &str, occurences: &Vec<(u32, u32)>) -> Option<UrlBuf> { fn build_file_url(
cwd: UrlBuf,
subject: String,
file_path: &str,
occurences: &Vec<(u32, u32)>,
) -> Option<UrlBuf> {
let occurrences_str = let occurrences_str =
occurences.iter().map(|(line, col)| format!("{line}-{col}")).collect::<Vec<_>>().join(","); occurences.iter().map(|(line, col)| format!("{line}-{col}")).collect::<Vec<_>>().join(",");
let url = cwd.try_join(file_path).ok().and_then(|u| u.into_search(occurrences_str).ok()); let search_str = format!("{}~{}", subject.len(), occurrences_str);
let url = cwd.try_join(file_path).ok().and_then(|u| u.into_search(search_str).ok());
url url
} }