From 0a816cbc87a4c513c429ee025caeac1082988335 Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Wed, 10 Dec 2025 09:48:10 -0300 Subject: [PATCH] edit prediction: Exclude whole-module definitions from context (#44414) For qualified identifiers we end up requesting both the definition of the module and the item within it, but we only want the latter. At the moment, we can't skip the request altogether, because we can't tell them apart from the highlights query. However, we can tell from the target range length, because it should be small for individual definitions as it only covers their name, not the whole body. Release Notes: - N/A --- .../src/edit_prediction_context.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/edit_prediction_context/src/edit_prediction_context.rs b/crates/edit_prediction_context/src/edit_prediction_context.rs index 475050fabb8b17ad76c34234094cf798e36a76ab..d3aefaa6e4ec585dc7c90fee1e95de17e018f90f 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, @@ -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),