diff --git a/crates/edit_prediction_context/src/scored_declaration.rs b/crates/edit_prediction_context/src/scored_declaration.rs index 14198e453c8c5a09e05a46cb2db8d7c230f60cd3..f6a6f0c1d0a3e3bafcb7106cbbbdfadcb90790c3 100644 --- a/crates/edit_prediction_context/src/scored_declaration.rs +++ b/crates/edit_prediction_context/src/scored_declaration.rs @@ -15,6 +15,10 @@ use crate::{ text_similarity::{IdentifierOccurrences, jaccard_similarity, weighted_overlap_coefficient}, }; +// TODO: +// +// * Consider adding declaration_file_count (n) + #[derive(Clone, Debug)] pub struct ScoredSnippet { #[allow(dead_code)] @@ -28,7 +32,7 @@ pub struct ScoredSnippet { #[derive(EnumIter, Clone, Copy, PartialEq, Eq, Hash, Debug)] pub enum SnippetStyle { Signature, - Definition, + Declaration, } impl ScoredSnippet { @@ -36,7 +40,7 @@ impl ScoredSnippet { pub fn score(&self, style: SnippetStyle) -> f32 { match style { SnippetStyle::Signature => self.scores.signature, - SnippetStyle::Definition => self.scores.definition, + SnippetStyle::Declaration => self.scores.declaration, } } @@ -77,20 +81,15 @@ fn scored_snippets( identifier_to_references .into_iter() .flat_map(|(identifier, references)| { - let definitions = index + let declarations = index .read(cx) // todo! pick a limit .declarations_for_identifier::<16>(&identifier, cx); - let definition_count = definitions.len(); - let total_file_count = definitions - .iter() - .filter_map(|definition| definition.project_entry_id(cx)) - .collect::>() - .len(); + let declaration_count = declarations.len(); - definitions + declarations .iter() - .filter_map(|definition| match definition { + .filter_map(|declaration| match declaration { Declaration::Buffer { declaration, buffer, @@ -106,44 +105,44 @@ fn scored_snippets( ) .is_none() .then(|| { - let definition_line = + let declaration_line = declaration.item_range.start.to_point(current_buffer).row; ( true, - (cursor_point.row as i32 - definition_line as i32).abs() as u32, - definition, + (cursor_point.row as i32 - declaration_line as i32).abs() + as u32, + declaration, ) }) } else { - Some((false, 0, definition)) + Some((false, 0, declaration)) } } Declaration::File { .. } => { // We can assume that a file declaration is in a different file, // because the current onemust be open - Some((false, 0, definition)) + Some((false, 0, declaration)) } }) .sorted_by_key(|&(_, distance, _)| distance) .enumerate() .map( |( - definition_line_distance_rank, - (is_same_file, definition_line_distance, definition), + declaration_line_distance_rank, + (is_same_file, declaration_line_distance, declaration), )| { - let same_file_definition_count = - index.read(cx).file_declaration_count(definition); + let same_file_declaration_count = + index.read(cx).file_declaration_count(declaration); score_snippet( &identifier, &references, - definition.clone(), + declaration.clone(), is_same_file, - definition_line_distance, - definition_line_distance_rank, - same_file_definition_count, - definition_count, - total_file_count, + declaration_line_distance, + declaration_line_distance_rank, + same_file_declaration_count, + declaration_count, &containing_range_identifier_occurrences, &adjacent_identifier_occurrences, cursor_point, @@ -172,13 +171,12 @@ fn range_intersection(a: &Range, b: &Range) -> Option Scores { - // Score related to how likely this is the correct definition, range 0 to 1 + // Score related to how likely this is the correct declaration, range 0 to 1 let accuracy_score = if self.is_same_file { - // TODO: use definition_line_distance_rank - (0.5 / self.same_file_definition_count as f32) - + (0.5 / self.definition_file_count as f32) + // TODO: use declaration_line_distance_rank + (0.5 / self.same_file_declaration_count as f32) } else { - 1.0 / self.definition_count as f32 + 1.0 / self.declaration_count as f32 }; // Score related to the distance between the reference and cursor, range 0 to 1 @@ -312,9 +306,9 @@ impl ScoreInputs { Scores { signature: combined_score * self.containing_range_vs_signature_weighted_overlap, - // definition score gets boosted both by being multipled by 2 and by there being more + // declaration score gets boosted both by being multipled by 2 and by there being more // weighted overlap. - definition: 2.0 * combined_score * self.containing_range_vs_item_weighted_overlap, + declaration: 2.0 * combined_score * self.containing_range_vs_item_weighted_overlap, } } }