@@ -70,7 +70,7 @@ pub struct PlannedSnippet<'a> {
7070}
7171
7272#[ derive( EnumIter , Clone , Copy , PartialEq , Eq , Hash , Debug , PartialOrd , Ord ) ]
73- pub enum SnippetStyle {
73+ pub enum DeclarationStyle {
7474 Signature ,
7575 Declaration ,
7676}
@@ -84,10 +84,10 @@ pub struct SectionLabels {
8484impl < ' a > PlannedPrompt < ' a > {
8585 /// Greedy one-pass knapsack algorithm to populate the prompt plan. Does the following:
8686 ///
87- /// Initializes a priority queue by populating it with each snippet, finding the SnippetStyle
88- /// that minimizes `score_density = score / snippet.range(style).len()`. When a "signature"
89- /// snippet is popped, insert an entry for the "declaration" variant that reflects the cost of
90- /// upgrade.
87+ /// Initializes a priority queue by populating it with each snippet, finding the
88+ /// DeclarationStyle that minimizes `score_density = score / snippet.range(style).len()`. When a
89+ /// "signature" snippet is popped, insert an entry for the "declaration" variant that reflects
90+ /// the cost of upgrade.
9191 ///
9292 /// TODO: Implement an early halting condition. One option might be to have another priority
9393 /// queue where the score is the size, and update it accordingly. Another option might be to
@@ -131,13 +131,13 @@ impl<'a> PlannedPrompt<'a> {
131131 struct QueueEntry {
132132 score_density : OrderedFloat < f32 > ,
133133 declaration_index : usize ,
134- style : SnippetStyle ,
134+ style : DeclarationStyle ,
135135 }
136136
137137 // Initialize priority queue with the best score for each snippet.
138138 let mut queue: BinaryHeap < QueueEntry > = BinaryHeap :: new ( ) ;
139139 for ( declaration_index, declaration) in request. referenced_declarations . iter ( ) . enumerate ( ) {
140- let ( style, score_density) = SnippetStyle :: iter ( )
140+ let ( style, score_density) = DeclarationStyle :: iter ( )
141141 . map ( |style| {
142142 (
143143 style,
@@ -186,7 +186,7 @@ impl<'a> PlannedPrompt<'a> {
186186 this. budget_used += additional_bytes;
187187 this. add_parents ( & mut included_parents, additional_parents) ;
188188 let planned_snippet = match queue_entry. style {
189- SnippetStyle :: Signature => {
189+ DeclarationStyle :: Signature => {
190190 let Some ( text) = declaration. text . get ( declaration. signature_range . clone ( ) )
191191 else {
192192 return Err ( anyhow ! (
@@ -203,7 +203,7 @@ impl<'a> PlannedPrompt<'a> {
203203 text_is_truncated : declaration. text_is_truncated ,
204204 }
205205 }
206- SnippetStyle :: Declaration => PlannedSnippet {
206+ DeclarationStyle :: Declaration => PlannedSnippet {
207207 path : declaration. path . clone ( ) ,
208208 range : declaration. range . clone ( ) ,
209209 text : & declaration. text ,
@@ -213,19 +213,21 @@ impl<'a> PlannedPrompt<'a> {
213213 this. snippets . push ( planned_snippet) ;
214214
215215 // When a Signature is consumed, insert an entry for Definition style.
216- if queue_entry. style == SnippetStyle :: Signature {
217- let signature_size = declaration_size ( & declaration, SnippetStyle :: Signature ) ;
218- let declaration_size = declaration_size ( & declaration, SnippetStyle :: Declaration ) ;
219- let signature_score = declaration_score ( & declaration, SnippetStyle :: Signature ) ;
220- let declaration_score = declaration_score ( & declaration, SnippetStyle :: Declaration ) ;
216+ if queue_entry. style == DeclarationStyle :: Signature {
217+ let signature_size = declaration_size ( & declaration, DeclarationStyle :: Signature ) ;
218+ let declaration_size =
219+ declaration_size ( & declaration, DeclarationStyle :: Declaration ) ;
220+ let signature_score = declaration_score ( & declaration, DeclarationStyle :: Signature ) ;
221+ let declaration_score =
222+ declaration_score ( & declaration, DeclarationStyle :: Declaration ) ;
221223
222224 let score_diff = declaration_score - signature_score;
223225 let size_diff = declaration_size. saturating_sub ( signature_size) ;
224226 if score_diff > 0.0001 && size_diff > 0 {
225227 queue. push ( QueueEntry {
226228 declaration_index : queue_entry. declaration_index ,
227229 score_density : OrderedFloat ( score_diff / ( size_diff as f32 ) ) ,
228- style : SnippetStyle :: Declaration ,
230+ style : DeclarationStyle :: Declaration ,
229231 } ) ;
230232 }
231233 }
@@ -510,20 +512,20 @@ impl<'a> PlannedPrompt<'a> {
510512 }
511513}
512514
513- fn declaration_score_density ( declaration : & ReferencedDeclaration , style : SnippetStyle ) -> f32 {
515+ fn declaration_score_density ( declaration : & ReferencedDeclaration , style : DeclarationStyle ) -> f32 {
514516 declaration_score ( declaration, style) / declaration_size ( declaration, style) as f32
515517}
516518
517- fn declaration_score ( declaration : & ReferencedDeclaration , style : SnippetStyle ) -> f32 {
519+ fn declaration_score ( declaration : & ReferencedDeclaration , style : DeclarationStyle ) -> f32 {
518520 match style {
519- SnippetStyle :: Signature => declaration. signature_score ,
520- SnippetStyle :: Declaration => declaration. declaration_score ,
521+ DeclarationStyle :: Signature => declaration. signature_score ,
522+ DeclarationStyle :: Declaration => declaration. declaration_score ,
521523 }
522524}
523525
524- fn declaration_size ( declaration : & ReferencedDeclaration , style : SnippetStyle ) -> usize {
526+ fn declaration_size ( declaration : & ReferencedDeclaration , style : DeclarationStyle ) -> usize {
525527 match style {
526- SnippetStyle :: Signature => declaration. signature_range . len ( ) ,
527- SnippetStyle :: Declaration => declaration. text . len ( ) ,
528+ DeclarationStyle :: Signature => declaration. signature_range . len ( ) ,
529+ DeclarationStyle :: Declaration => declaration. text . len ( ) ,
528530 }
529531}
0 commit comments