File tree Expand file tree Collapse file tree 4 files changed +15
-2
lines changed Expand file tree Collapse file tree 4 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -305,7 +305,6 @@ impl ModuleDef {
305
305
ModuleDef :: Module ( it) => it. name ( db) ,
306
306
ModuleDef :: Const ( it) => it. name ( db) ,
307
307
ModuleDef :: Static ( it) => it. name ( db) ,
308
-
309
308
ModuleDef :: BuiltinType ( it) => Some ( it. name ( ) ) ,
310
309
}
311
310
}
Original file line number Diff line number Diff line change @@ -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
98
pub ( crate ) fn will_rename_file (
98
99
db : & RootDatabase ,
99
100
file_id : FileId ,
Original file line number Diff line number Diff line change @@ -395,6 +395,9 @@ impl Config {
395
395
pub fn work_done_progress ( & self ) -> bool {
396
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
401
pub fn code_action_resolve ( & self ) -> bool {
399
402
try_or ! (
400
403
self . caps
Original file line number Diff line number Diff line change @@ -799,8 +799,18 @@ pub(crate) fn handle_rename(
799
799
let _p = profile:: span ( "handle_rename" ) ;
800
800
let position = from_proto:: file_position ( & snap, params. text_document_position ) ?;
801
801
802
- let change =
802
+ let mut change =
803
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
814
let workspace_edit = to_proto:: workspace_edit ( & snap, change) ?;
805
815
Ok ( Some ( workspace_edit) )
806
816
}
You can’t perform that action at this time.
0 commit comments