Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
edit prediction: Exclude whole-module definitions from context (#44414)
Agus Zubiaga0a816cbc87a4
diff --git a/crates/edit_prediction_context/src/edit_prediction_context.rs b/crates/edit_prediction_context/src/edit_prediction_context.rsindex 475050fabb8..d3aefaa6e4e 100644--- a/crates/edit_prediction_context/src/edit_prediction_context.rs+++ b/crates/edit_prediction_context/src/edit_prediction_context.rs@@ -383,6 +383,8 @@ async fn rebuild_related_files(.await)}+const MAX_TARGET_LEN: usize = 128;+fn process_definition(location: LocationLink,project: &Entity<Project>,@@ -395,6 +397,15 @@ fn process_definition(if worktree.read(cx).is_single_file() {return None;}++ // If the target range is large, it likely means we requested the definition of an entire module.+ // For individual definitions, the target range should be small as it only covers the symbol.+ let buffer = location.target.buffer.read(cx);+ let target_len = anchor_range.to_offset(&buffer).len();+ if target_len > MAX_TARGET_LEN {+ return None;+ }+Some(CachedDefinition {path: ProjectPath {worktree_id: file.worktree_id(cx),