From ea4bf46a365a2600094402003439b647e47f595d Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Wed, 17 Sep 2025 18:09:20 -0600 Subject: [PATCH] Return 0 results when declaration count limit exceeded Co-authored-by: Agus --- crates/edit_prediction_context/src/syntax_index.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/edit_prediction_context/src/syntax_index.rs b/crates/edit_prediction_context/src/syntax_index.rs index 5aba354c1dc0bd61a6dc5bb0b025ad45db6b12b6..3f61533ee8dadd5ee89b03a264cfabc6a73ff033 100644 --- a/crates/edit_prediction_context/src/syntax_index.rs +++ b/crates/edit_prediction_context/src/syntax_index.rs @@ -426,6 +426,9 @@ impl SyntaxIndexState { self.declarations.get(id) } + /// Returns declarations for the identifier. If the limit is exceeded, returns an empty vector. + /// + /// TODO: Consider doing some pre-ranking and instead truncating when N is exceeded. pub fn declarations_for_identifier( &self, identifier: &Identifier, @@ -453,7 +456,7 @@ impl SyntaxIndexState { included_buffer_entry_ids.push(*project_entry_id); result.push(declaration.clone()); if result.len() == N { - return result; + return Vec::new(); } } Declaration::File { @@ -475,7 +478,7 @@ impl SyntaxIndexState { result.push(declaration); if result.len() == N { - return result; + return Vec::new(); } } } @@ -644,7 +647,7 @@ mod tests { name: "main".into(), language_id: rust_lang_id, }); - assert_eq!(decls.len(), 1); + assert_eq!(decls.len(), 0); } #[gpui::test]