diff options
author | Lukas Wirth <[email protected]> | 2021-03-10 14:49:01 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-03-10 14:49:01 +0000 |
commit | 3af69b535992203c2582433d968eed22a7e7fe69 (patch) | |
tree | 999bcba7335ea8cce48b78117b07b1c459a6859a /crates/rust-analyzer/src/handlers.rs | |
parent | a9b1e5cde1cc6e470be60cf2c230b99a62c2d2c3 (diff) |
Avoid double text edits when renaming mod declaration
Diffstat (limited to 'crates/rust-analyzer/src/handlers.rs')
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 12 |
1 files changed, 11 insertions, 1 deletions
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 | } |