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

Commit 59c49a9

Browse files
bors[bot]tysgnemethf
authored
11442: fix(rename): Use text range of a mod name after macro expansion r=Veykril a=tysg Fixes rust-lang#11417. 11460: fix: documentation of SsrParams r=Veykril a=nemethf Fix rust-lang#11429 by extending the documentation of SsrParms with the mandatory field 'selections'. Copy its description from lsp_ext.rs. Co-authored-by: Tianyi Song <[email protected]> Co-authored-by: Felicián Németh <[email protected]>
3 parents e1acbd0 + aa8c982 + 7c7d699 commit 59c49a9

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

crates/ide/src/rename.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,34 @@ pub mod foo$0;
11331133
)
11341134
}
11351135

1136+
#[test]
1137+
fn test_rename_mod_in_macro() {
1138+
check(
1139+
"bar",
1140+
r#"
1141+
//- /foo.rs
1142+
1143+
//- /lib.rs
1144+
macro_rules! submodule {
1145+
($name:ident) => {
1146+
mod $name;
1147+
};
1148+
}
1149+
1150+
submodule!($0foo);
1151+
"#,
1152+
r#"
1153+
macro_rules! submodule {
1154+
($name:ident) => {
1155+
mod $name;
1156+
};
1157+
}
1158+
1159+
submodule!(bar);
1160+
"#,
1161+
)
1162+
}
1163+
11361164
#[test]
11371165
fn test_enum_variant_from_module_1() {
11381166
cov_mark::check!(rename_non_local);

crates/ide_db/src/rename.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,23 @@ fn rename_mod(
188188
source_change.push_file_system_edit(move_file);
189189
}
190190

191-
if let Some(InFile { file_id, value: decl_source }) = module.declaration_source(sema.db) {
192-
let file_id = file_id.original_file(sema.db);
193-
match decl_source.name() {
194-
Some(name) => source_change.insert_source_edit(
195-
file_id,
196-
TextEdit::replace(name.syntax().text_range(), new_name.to_string()),
197-
),
191+
if let Some(src) = module.declaration_source(sema.db) {
192+
let file_id = src.file_id.original_file(sema.db);
193+
match src.value.name() {
194+
Some(name) => {
195+
if let Some(file_range) =
196+
src.with_value(name.syntax()).original_file_range_opt(sema.db)
197+
{
198+
source_change.insert_source_edit(
199+
file_id,
200+
TextEdit::replace(file_range.range, new_name.to_string()),
201+
)
202+
};
203+
}
198204
_ => never!("Module source node is missing a name"),
199205
}
200206
}
207+
201208
let def = Definition::Module(module);
202209
let usages = def.usages(sema).all();
203210
let ref_edits = usages.iter().map(|(&file_id, references)| {

docs/dev/lsp-extensions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ interface SsrParams {
278278
textDocument: TextDocumentIdentifier;
279279
/// Position where SSR was invoked.
280280
position: Position;
281+
/// Current selections. Search/replace will be restricted to these if non-empty.
282+
selections: Range[];
281283
}
282284
```
283285

0 commit comments

Comments
 (0)