11//! Conversion of rust-analyzer specific types to lsp_types equivalents.
22use std:: {
33 iter:: once,
4- path,
4+ mem , path,
55 sync:: atomic:: { AtomicU32 , Ordering } ,
66} ;
77
@@ -1123,13 +1123,20 @@ pub(crate) fn snippet_text_document_ops(
11231123
11241124pub ( crate ) fn snippet_workspace_edit (
11251125 snap : & GlobalStateSnapshot ,
1126- source_change : SourceChange ,
1126+ mut source_change : SourceChange ,
11271127) -> Cancellable < lsp_ext:: SnippetWorkspaceEdit > {
11281128 let mut document_changes: Vec < lsp_ext:: SnippetDocumentChangeOperation > = Vec :: new ( ) ;
11291129
1130- for op in source_change. file_system_edits {
1131- let ops = snippet_text_document_ops ( snap, op) ?;
1132- document_changes. extend_from_slice ( & ops) ;
1130+ for op in & mut source_change. file_system_edits {
1131+ if let FileSystemEdit :: CreateFile { dst, initial_contents } = op {
1132+ // replace with a placeholder to avoid cloneing the edit
1133+ let op = FileSystemEdit :: CreateFile {
1134+ dst : dst. clone ( ) ,
1135+ initial_contents : mem:: take ( initial_contents) ,
1136+ } ;
1137+ let ops = snippet_text_document_ops ( snap, op) ?;
1138+ document_changes. extend_from_slice ( & ops) ;
1139+ }
11331140 }
11341141 for ( file_id, ( edit, snippet_edit) ) in source_change. source_file_edits {
11351142 let edit = snippet_text_document_edit (
@@ -1141,6 +1148,12 @@ pub(crate) fn snippet_workspace_edit(
11411148 ) ?;
11421149 document_changes. push ( lsp_ext:: SnippetDocumentChangeOperation :: Edit ( edit) ) ;
11431150 }
1151+ for op in source_change. file_system_edits {
1152+ if !matches ! ( op, FileSystemEdit :: CreateFile { .. } ) {
1153+ let ops = snippet_text_document_ops ( snap, op) ?;
1154+ document_changes. extend_from_slice ( & ops) ;
1155+ }
1156+ }
11441157 let mut workspace_edit = lsp_ext:: SnippetWorkspaceEdit {
11451158 changes : None ,
11461159 document_changes : Some ( document_changes) ,
0 commit comments