diff options
-rw-r--r-- | crates/hir/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ide/src/references/rename.rs | 1 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 3 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 12 |
4 files changed, 15 insertions, 2 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 4ef38c0f0..58adc8fd3 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -305,7 +305,6 @@ impl ModuleDef { | |||
305 | ModuleDef::Module(it) => it.name(db), | 305 | ModuleDef::Module(it) => it.name(db), |
306 | ModuleDef::Const(it) => it.name(db), | 306 | ModuleDef::Const(it) => it.name(db), |
307 | ModuleDef::Static(it) => it.name(db), | 307 | ModuleDef::Static(it) => it.name(db), |
308 | |||
309 | ModuleDef::BuiltinType(it) => Some(it.name()), | 308 | ModuleDef::BuiltinType(it) => Some(it.name()), |
310 | } | 309 | } |
311 | } | 310 | } |
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 05c73de88..bb68bcc78 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs | |||
@@ -94,6 +94,7 @@ pub(crate) fn rename_with_semantics( | |||
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | /// Called by the client when it is about to rename a file. | ||
97 | pub(crate) fn will_rename_file( | 98 | pub(crate) fn will_rename_file( |
98 | db: &RootDatabase, | 99 | db: &RootDatabase, |
99 | file_id: FileId, | 100 | file_id: FileId, |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 25df13554..8af7871ac 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -395,6 +395,9 @@ impl Config { | |||
395 | pub fn work_done_progress(&self) -> bool { | 395 | pub fn work_done_progress(&self) -> bool { |
396 | try_or!(self.caps.window.as_ref()?.work_done_progress?, false) | 396 | try_or!(self.caps.window.as_ref()?.work_done_progress?, false) |
397 | } | 397 | } |
398 | pub fn will_rename(&self) -> bool { | ||
399 | try_or!(self.caps.workspace.as_ref()?.file_operations.as_ref()?.will_rename?, false) | ||
400 | } | ||
398 | pub fn code_action_resolve(&self) -> bool { | 401 | pub fn code_action_resolve(&self) -> bool { |
399 | try_or!( | 402 | try_or!( |
400 | self.caps | 403 | self.caps |
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index b5b2ffe50..6cc433cb8 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -799,8 +799,18 @@ pub(crate) fn handle_rename( | |||
799 | let _p = profile::span("handle_rename"); | 799 | let _p = profile::span("handle_rename"); |
800 | let position = from_proto::file_position(&snap, params.text_document_position)?; | 800 | let position = from_proto::file_position(&snap, params.text_document_position)?; |
801 | 801 | ||
802 | let change = | 802 | let mut change = |
803 | snap.analysis.rename(position, &*params.new_name)?.map_err(to_proto::rename_error)?; | 803 | snap.analysis.rename(position, &*params.new_name)?.map_err(to_proto::rename_error)?; |
804 | |||
805 | // this is kind of a hack to prevent double edits from happening when moving files | ||
806 | // When a module gets renamed by renaming the mod declaration this causes the file to move | ||
807 | // which in turn will trigger a WillRenameFiles request to the server for which we reply with a | ||
808 | // a second identical set of renames, the client will then apply both edits causing incorrect edits | ||
809 | // with this we only emit source_file_edits in the WillRenameFiles response which will do the rename instead | ||
810 | // See https://github.com/microsoft/vscode-languageserver-node/issues/752 for more info | ||
811 | if !change.file_system_edits.is_empty() && snap.config.will_rename() { | ||
812 | change.source_file_edits.clear(); | ||
813 | } | ||
804 | let workspace_edit = to_proto::workspace_edit(&snap, change)?; | 814 | let workspace_edit = to_proto::workspace_edit(&snap, change)?; |
805 | Ok(Some(workspace_edit)) | 815 | Ok(Some(workspace_edit)) |
806 | } | 816 | } |