Rename fails on renaming definitions created by macros

This commit is contained in:
Lukas Wirth
2021-08-19 22:53:00 +02:00
parent 320bb72b7f
commit c67ecbebc4
5 changed files with 62 additions and 66 deletions

View File

@@ -143,8 +143,11 @@ impl NavigationTarget {
kind: SymbolKind,
) -> NavigationTarget {
let name = node.value.name().map(|it| it.text().into()).unwrap_or_else(|| "_".into());
let focus_range =
node.value.name().map(|it| node.with_value(it.syntax()).original_file_range(db).range);
let focus_range = node
.value
.name()
.and_then(|it| node.with_value(it.syntax()).original_file_range_opt(db))
.map(|it| it.range);
let frange = node.map(|it| it.syntax()).original_file_range(db);
NavigationTarget::from_syntax(frange.file_id, name, focus_range, frange.range, kind)

View File

@@ -1869,8 +1869,7 @@ fn f() { <()>::BAR$0; }"#,
}
#[test]
fn macros_are_broken_lol() {
cov_mark::check!(macros_are_broken_lol);
fn defs_from_macros_arent_renamed() {
check(
"lol",
r#"
@@ -1878,11 +1877,7 @@ macro_rules! m { () => { fn f() {} } }
m!();
fn main() { f$0() }
"#,
r#"
macro_rules! m { () => { fn f() {} } }
lol
fn main() { lol() }
"#,
"error: No identifier available to rename",
)
}
}

View File

@@ -1446,7 +1446,6 @@ gen2!();
0,
),
full_range: 228..236,
focus_range: 228..236,
name: "foo_test2",
kind: Function,
},
@@ -1467,7 +1466,6 @@ gen2!();
0,
),
full_range: 218..225,
focus_range: 218..225,
name: "foo_test",
kind: Function,
},
@@ -1533,7 +1531,6 @@ foo!();
0,
),
full_range: 210..217,
focus_range: 210..217,
name: "foo0",
kind: Function,
},
@@ -1554,7 +1551,6 @@ foo!();
0,
),
full_range: 210..217,
focus_range: 210..217,
name: "foo1",
kind: Function,
},
@@ -1575,7 +1571,6 @@ foo!();
0,
),
full_range: 210..217,
focus_range: 210..217,
name: "foo2",
kind: Function,
},