Skip to content

Commit

Permalink
refactor(code-index): rename ATTRIBUTE_COMMIT to COMMIT for clari…
Browse files Browse the repository at this point in the history
…ty and consistency (#3670)
  • Loading branch information
wsxiaoys authored Jan 10, 2025
1 parent 9099062 commit 0fbb3d5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
8 changes: 5 additions & 3 deletions crates/tabby-common/src/index/code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ use super::{corpus, IndexSchema};
use crate::api::code::CodeSearchQuery;

pub mod fields {
pub const ATTRIBUTE_COMMIT: &str = "commit";
// === Doc level fields ===
/// commit ref of the file being indexed.
pub const COMMIT: &str = "commit";

// === Chunk level fields ===
pub const CHUNK_GIT_URL: &str = "chunk_git_url";
pub const CHUNK_FILEPATH: &str = "chunk_filepath";
pub const CHUNK_LANGUAGE: &str = "chunk_language";
pub const CHUNK_BODY: &str = "chunk_body";

// Optional field, when None, it means this chunk contains entire content of the file.
/// Optional, when None, it means this chunk contains entire content of the file.
pub const CHUNK_START_LINE: &str = "chunk_start_line";
}

Expand Down
2 changes: 1 addition & 1 deletion crates/tabby-index/src/code/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async fn backfill_commit_in_doc_if_needed(
commit: &str,
path: &Path,
) -> Result<()> {
if indexer.has_attribute_field(id, code::fields::ATTRIBUTE_COMMIT) {
if indexer.has_attribute_field(id, code::fields::COMMIT) {
return Ok(());
}

Expand Down
2 changes: 1 addition & 1 deletion crates/tabby-index/src/code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl CodeBuilder {
impl IndexAttributeBuilder<SourceCode> for CodeBuilder {
async fn build_attributes(&self, source_code: &SourceCode) -> serde_json::Value {
json!({
code::fields::ATTRIBUTE_COMMIT: source_code.commit,
code::fields::COMMIT: source_code.commit,
})
}

Expand Down
8 changes: 2 additions & 6 deletions crates/tabby/src/services/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,8 @@ async fn get_commit(reader: &IndexReader, id: &str) -> Option<String> {
}

let doc = reader.searcher().doc(doc[0].1).ok()?;
get_json_text_field_optional(
&doc,
schema.field_attributes,
code::fields::ATTRIBUTE_COMMIT,
)
.map(|s| s.to_owned())
get_json_text_field_optional(&doc, schema.field_attributes, code::fields::COMMIT)
.map(|s| s.to_owned())
}

fn get_text(doc: &TantivyDocument, field: schema::Field) -> &str {
Expand Down

0 comments on commit 0fbb3d5

Please sign in to comment.