Skip to content

Commit 12a36db

Browse files
bors[bot]Veykril
andauthored
Merge #10055
10055: fix: Don't use fake text range in original node search as is in completions r=Veykril a=Veykril Fixes #10042 bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents ef54dac + ebb87fe commit 12a36db

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

crates/ide_completion/src/patterns.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ fn maximize_name_ref(name_ref: &ast::NameRef) -> SyntaxNode {
285285
}
286286

287287
fn find_node_with_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<N> {
288+
let range = syntax.text_range().intersect(range)?;
288289
syntax.covering_element(range).ancestors().find_map(N::cast)
289290
}
290291

crates/ide_completion/src/tests.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
7575
},
7676
};
7777

78-
pub(crate) fn completion_list(code: &str) -> String {
79-
completion_list_with_config(TEST_CONFIG, code)
78+
pub(crate) fn completion_list(ra_fixture: &str) -> String {
79+
completion_list_with_config(TEST_CONFIG, ra_fixture)
8080
}
8181

82-
fn completion_list_with_config(config: CompletionConfig, code: &str) -> String {
82+
fn completion_list_with_config(config: CompletionConfig, ra_fixture: &str) -> String {
8383
// filter out all but one builtintype completion for smaller test outputs
84-
let items = get_all_items(config, code);
84+
let items = get_all_items(config, ra_fixture);
8585
let mut bt_seen = false;
8686
let items = items
8787
.into_iter()
@@ -227,3 +227,26 @@ fn test_no_completions_required() {
227227
cov_mark::check!(no_completion_required);
228228
check_no_completion(r#"fn foo() { for i i$0 }"#);
229229
}
230+
231+
#[test]
232+
fn regression_10042() {
233+
completion_list(
234+
r#"
235+
macro_rules! preset {
236+
($($x:ident)&&*) => {
237+
{
238+
let mut v = Vec::new();
239+
$(
240+
v.push($x.into());
241+
)*
242+
v
243+
}
244+
};
245+
}
246+
247+
fn foo() {
248+
preset!(foo$0);
249+
}
250+
"#,
251+
);
252+
}

0 commit comments

Comments
 (0)