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
This commit is contained in:
Agus Zubiaga authored and GitHub committed 2025-12-10 09:48:10 -03:00
1 parent ad4edf8f70
commit 5717600176
1 file changed
+11
@@ -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),