1
1
//! Conversion of rust-analyzer specific types to lsp_types equivalents.
2
2
use std:: {
3
3
iter:: once,
4
- path,
4
+ mem , path,
5
5
sync:: atomic:: { AtomicU32 , Ordering } ,
6
6
} ;
7
7
@@ -1123,13 +1123,20 @@ pub(crate) fn snippet_text_document_ops(
1123
1123
1124
1124
pub ( crate ) fn snippet_workspace_edit (
1125
1125
snap : & GlobalStateSnapshot ,
1126
- source_change : SourceChange ,
1126
+ mut source_change : SourceChange ,
1127
1127
) -> Cancellable < lsp_ext:: SnippetWorkspaceEdit > {
1128
1128
let mut document_changes: Vec < lsp_ext:: SnippetDocumentChangeOperation > = Vec :: new ( ) ;
1129
1129
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
+ }
1133
1140
}
1134
1141
for ( file_id, ( edit, snippet_edit) ) in source_change. source_file_edits {
1135
1142
let edit = snippet_text_document_edit (
@@ -1141,6 +1148,12 @@ pub(crate) fn snippet_workspace_edit(
1141
1148
) ?;
1142
1149
document_changes. push ( lsp_ext:: SnippetDocumentChangeOperation :: Edit ( edit) ) ;
1143
1150
}
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
+ }
1144
1157
let mut workspace_edit = lsp_ext:: SnippetWorkspaceEdit {
1145
1158
changes : None ,
1146
1159
document_changes : Some ( document_changes) ,
0 commit comments