Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0ec2911

Browse files
committed
fix: consider relative offset to fake ident token in expansion for completion
1 parent 3bc33c7 commit 0ec2911

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

crates/ide-completion/src/context/analysis.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ pub(super) fn expand_and_analyze(
4848
// make the offset point to the start of the original token, as that is what the
4949
// intermediate offsets calculated in expansion always points to
5050
let offset = offset - relative_offset;
51-
let expansion = expand(sema, original_file, speculative_file, offset, fake_ident_token);
51+
let expansion =
52+
expand(sema, original_file, speculative_file, offset, fake_ident_token, relative_offset);
53+
5254
// add the relative offset back, so that left_biased finds the proper token
5355
let offset = expansion.offset + relative_offset;
5456
let token = expansion.original_file.token_at_offset(offset).left_biased()?;
@@ -67,6 +69,7 @@ fn expand(
6769
mut speculative_file: SyntaxNode,
6870
mut offset: TextSize,
6971
mut fake_ident_token: SyntaxToken,
72+
relative_offset: TextSize,
7073
) -> ExpansionResult {
7174
let _p = profile::span("CompletionContext::expand");
7275
let mut derive_ctx = None;
@@ -97,7 +100,7 @@ fn expand(
97100
// successful expansions
98101
(Some(actual_expansion), Some((fake_expansion, fake_mapped_token))) => {
99102
let new_offset = fake_mapped_token.text_range().start();
100-
if new_offset > actual_expansion.text_range().end() {
103+
if new_offset + relative_offset > actual_expansion.text_range().end() {
101104
// offset outside of bounds from the original expansion,
102105
// stop here to prevent problems from happening
103106
break 'expansion;
@@ -176,7 +179,7 @@ fn expand(
176179
// successful expansions
177180
(Some(actual_expansion), Some((fake_expansion, fake_mapped_token))) => {
178181
let new_offset = fake_mapped_token.text_range().start();
179-
if new_offset > actual_expansion.text_range().end() {
182+
if new_offset + relative_offset > actual_expansion.text_range().end() {
180183
// offset outside of bounds from the original expansion,
181184
// stop here to prevent problems from happening
182185
break 'expansion;

0 commit comments

Comments
 (0)