From b87cdc91487593e58d3e9b56a72e89be09abb97c Mon Sep 17 00:00:00 2001 From: Jackson Chen <541898146chen@gmail.com> Date: Tue, 12 Nov 2024 16:35:54 -0600 Subject: [PATCH] chore: Normalize file paths in code search query --- crates/tabby-common/src/api/code.rs | 10 ++-------- crates/tabby-common/src/index/code/mod.rs | 23 ++++------------------- crates/tabby/src/services/completion.rs | 1 + 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/crates/tabby-common/src/api/code.rs b/crates/tabby-common/src/api/code.rs index daf696ae883f..a23aea756caa 100644 --- a/crates/tabby-common/src/api/code.rs +++ b/crates/tabby-common/src/api/code.rs @@ -55,6 +55,7 @@ pub enum CodeSearchError { } pub struct CodeSearchQuery { + // filepath in code search query always normalize to unix style. pub filepath: Option, pub language: Option, pub content: String, @@ -68,15 +69,8 @@ impl CodeSearchQuery { content: String, source_id: String, ) -> Self { - debug!("CodeSearchQuery::new - Original filepath: {:?}", filepath); - let normalized = normalize_path(filepath).unwrap_or(None); - debug!( - "CodeSearchQuery::new - Normalized filepath: {:?}", - normalized - ); - Self { - filepath: normalized, + filepath: normalize_path(filepath).unwrap_or(None), language, content, source_id, diff --git a/crates/tabby-common/src/index/code/mod.rs b/crates/tabby-common/src/index/code/mod.rs index ac57c84caa52..bdde9bb1aaf2 100644 --- a/crates/tabby-common/src/index/code/mod.rs +++ b/crates/tabby-common/src/index/code/mod.rs @@ -50,17 +50,9 @@ pub fn body_query(tokens: &[String]) -> Box { } fn filepath_query(filepath: &str) -> Box { - debug!("filepath_query - Input filepath: {}", filepath); let schema = IndexSchema::instance(); let mut term = Term::from_field_json_path(schema.field_chunk_attributes, fields::CHUNK_FILEPATH, false); - // normalize the path base on the platform. - let filepath = normalize_path(Some(filepath.to_string())) - .ok() - .flatten() - .unwrap_or_else(|| filepath.to_string()); - debug!("filepath_query - Normalized filepath: {}", filepath); - term.append_type_and_str(&filepath); Box::new(TermQuery::new(term, IndexRecordOption::Basic)) } @@ -93,17 +85,10 @@ pub fn code_search_query( // When filepath presents, we exclude the file from the search. if let Some(filepath) = &query.filepath { - debug!("code_search_query - Original filepath: {}", filepath); - if let Ok(Some(normalized_path)) = normalize_path(Some(filepath.clone())) { - debug!( - "code_search_query - Normalized filepath: {}", - normalized_path - ); - subqueries.push(( - Occur::MustNot, - Box::new(ConstScoreQuery::new(filepath_query(&normalized_path), 0.0)), - )); - } + subqueries.push(( + Occur::MustNot, + Box::new(ConstScoreQuery::new(filepath_query(filepath), 0.0)), + )); } BooleanQuery::new(subqueries) diff --git a/crates/tabby/src/services/completion.rs b/crates/tabby/src/services/completion.rs index b771bf82d909..c74db00e91e6 100644 --- a/crates/tabby/src/services/completion.rs +++ b/crates/tabby/src/services/completion.rs @@ -113,6 +113,7 @@ pub struct Segments { suffix: Option, /// The relative path of the file that is being edited. + /// The filepath will keep the same format as the original file path base on the platform. /// - When [Segments::git_url] is set, this is the path of the file in the git repository. /// - When [Segments::git_url] is empty, this is the path of the file in the workspace. filepath: Option,