Skip to content

Don't return a SourceChange on WillRenameFiles when nothing gets refactored #8119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions crates/ide_assists/src/handlers/add_lifetime_to_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext) -> Op
let node = ctx.find_node_at_offset::<ast::Adt>()?;
let has_lifetime = node
.generic_param_list()
.map(|gen_list| gen_list.lifetime_params().count() > 0)
.unwrap_or_default();
.map_or(false, |gen_list| gen_list.lifetime_params().next().is_some());

if has_lifetime {
return None;
Expand All @@ -41,7 +40,7 @@ pub(crate) fn add_lifetime_to_type(acc: &mut Assists, ctx: &AssistContext) -> Op

acc.add(
AssistId("add_lifetime_to_type", AssistKind::Generate),
"Add lifetime`",
"Add lifetime",
target,
|builder| {
match node.generic_param_list() {
Expand Down
2 changes: 1 addition & 1 deletion crates/ide_assists/src/handlers/add_turbo_fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let ident = ctx.find_token_syntax_at_offset(SyntaxKind::IDENT).or_else(|| {
let arg_list = ctx.find_node_at_offset::<ast::ArgList>()?;
if arg_list.args().count() > 0 {
if arg_list.args().next().is_some() {
return None;
}
cov_mark::hit!(add_turbo_fish_after_call);
Expand Down
7 changes: 5 additions & 2 deletions crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,11 @@ pub(crate) fn handle_will_rename_files(
source_change.file_system_edits.clear();
// no collect here because we want to merge text edits on same file ids
source_change.extend(source_changes.map(|it| it.source_file_edits).flatten());
let workspace_edit = to_proto::workspace_edit(&snap, source_change)?;
Ok(Some(workspace_edit))
if source_change.source_file_edits.is_empty() {
Ok(None)
} else {
to_proto::workspace_edit(&snap, source_change).map(Some)
}
}

pub(crate) fn handle_goto_definition(
Expand Down
8 changes: 2 additions & 6 deletions crates/rust-analyzer/tests/rust-analyzer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,7 @@ fn main() {}
new_uri: base_path.join("src/from_mod/foo.rs").to_str().unwrap().to_string(),
}],
},
json!({
"documentChanges": []
}),
json!(null),
);

//rename file from foo.rs to mod.rs
Expand All @@ -851,9 +849,7 @@ fn main() {}
new_uri: base_path.join("src/to_mod/mod.rs").to_str().unwrap().to_string(),
}],
},
json!({
"documentChanges": []
}),
json!(null),
);

//rename same level file
Expand Down