Skip to content

Commit 9ec04ed

Browse files
committed
Auto merge of #17192 - roife:fix-issue-17179, r=lnicola
Fix source_range for INT_NUMBER in completion fix #17179. Previously r-a use `TextRange::empty(self.position.offset)` as `source_range` for `INT_NUMBER`, so the `text_edit` would always be an insertion, which results in #17179. This PR changed it by using `text_range` of `original_token` (same as `IDENT`).
2 parents c4618fe + 435e83d commit 9ec04ed

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

crates/ide-completion/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl CompletionContext<'_> {
466466
cov_mark::hit!(completes_if_lifetime_without_idents);
467467
TextRange::at(self.original_token.text_range().start(), TextSize::from(1))
468468
}
469-
IDENT | LIFETIME_IDENT | UNDERSCORE => self.original_token.text_range(),
469+
IDENT | LIFETIME_IDENT | UNDERSCORE | INT_NUMBER => self.original_token.text_range(),
470470
_ if kind.is_keyword() => self.original_token.text_range(),
471471
_ => TextRange::empty(self.position.offset),
472472
}

crates/ide-completion/src/render.rs

+45
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,51 @@ fn foo(a: A) { B { bar: a.$0 }; }
17301730
)
17311731
}
17321732

1733+
#[test]
1734+
fn tuple_field_detail() {
1735+
check(
1736+
r#"
1737+
struct S(i32);
1738+
1739+
fn f() -> i32 {
1740+
let s = S(0);
1741+
s.0$0
1742+
}
1743+
"#,
1744+
SymbolKind::Field,
1745+
expect![[r#"
1746+
[
1747+
CompletionItem {
1748+
label: "0",
1749+
source_range: 56..57,
1750+
delete: 56..57,
1751+
insert: "0",
1752+
kind: SymbolKind(
1753+
Field,
1754+
),
1755+
detail: "i32",
1756+
relevance: CompletionRelevance {
1757+
exact_name_match: false,
1758+
type_match: Some(
1759+
Exact,
1760+
),
1761+
is_local: false,
1762+
is_item_from_trait: false,
1763+
is_item_from_notable_trait: false,
1764+
is_name_already_imported: false,
1765+
requires_import: false,
1766+
is_op_method: false,
1767+
is_private_editable: false,
1768+
postfix_match: None,
1769+
is_definite: false,
1770+
function: None,
1771+
},
1772+
},
1773+
]
1774+
"#]],
1775+
);
1776+
}
1777+
17331778
#[test]
17341779
fn record_field_and_call_relevances() {
17351780
check_relevance(

0 commit comments

Comments
 (0)