aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-01-14 21:43:36 +0000
committerLukas Wirth <[email protected]>2021-01-14 21:43:36 +0000
commitd5095329a1c12e93653d8de4a93f0b4f5cad4c6e (patch)
tree1de73ddefe48cc9f82cb4f063eaddc069adf83bc /crates/rust-analyzer/src
parente23bfafb32a235fdb60ba279ea68b5aa381c2110 (diff)
Phase out SourceFileEdits in favour of a plain HashMap
Diffstat (limited to 'crates/rust-analyzer/src')
-rw-r--r--crates/rust-analyzer/src/cli/ssr.rs2
-rw-r--r--crates/rust-analyzer/src/handlers.rs10
-rw-r--r--crates/rust-analyzer/src/to_proto.rs2
3 files changed, 6 insertions, 8 deletions
diff --git a/crates/rust-analyzer/src/cli/ssr.rs b/crates/rust-analyzer/src/cli/ssr.rs
index 100331c37..bbb550ec9 100644
--- a/crates/rust-analyzer/src/cli/ssr.rs
+++ b/crates/rust-analyzer/src/cli/ssr.rs
@@ -12,7 +12,7 @@ pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> {
12 match_finder.add_rule(rule)?; 12 match_finder.add_rule(rule)?;
13 } 13 }
14 let edits = match_finder.edits(); 14 let edits = match_finder.edits();
15 for (file_id, edit) in edits.edits { 15 for (file_id, edit) in edits {
16 if let Some(path) = vfs.file_path(file_id).as_path() { 16 if let Some(path) = vfs.file_path(file_id).as_path() {
17 let mut contents = db.file_text(file_id).to_string(); 17 let mut contents = db.file_text(file_id).to_string();
18 edit.apply(&mut contents); 18 edit.apply(&mut contents);
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 839466e4f..1a4e0dd32 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -266,7 +266,7 @@ pub(crate) fn handle_on_type_formatting(
266 }; 266 };
267 267
268 // This should be a single-file edit 268 // This should be a single-file edit
269 let (_, edit) = edit.source_file_edits.edits.into_iter().next().unwrap(); 269 let (_, edit) = edit.source_file_edits.into_iter().next().unwrap();
270 270
271 let change = to_proto::text_edit_vec(&line_index, line_endings, edit); 271 let change = to_proto::text_edit_vec(&line_index, line_endings, edit);
272 Ok(Some(change)) 272 Ok(Some(change))
@@ -464,12 +464,10 @@ pub(crate) fn handle_will_rename_files(
464 464
465 // Drop file system edits since we're just renaming things on the same level 465 // Drop file system edits since we're just renaming things on the same level
466 let mut source_changes = source_changes.into_iter(); 466 let mut source_changes = source_changes.into_iter();
467 let mut source_file_edits = 467 let mut source_change = source_changes.next().unwrap_or_default();
468 source_changes.next().map_or_else(Default::default, |it| it.source_file_edits); 468 source_change.file_system_edits.clear();
469 // no collect here because we want to merge text edits on same file ids 469 // no collect here because we want to merge text edits on same file ids
470 source_file_edits.extend(source_changes.map(|it| it.source_file_edits.edits).flatten()); 470 source_change.extend(source_changes.map(|it| it.source_file_edits).flatten());
471 let source_change = SourceChange::from_edits(source_file_edits, Vec::new());
472
473 let workspace_edit = to_proto::workspace_edit(&snap, source_change)?; 471 let workspace_edit = to_proto::workspace_edit(&snap, source_change)?;
474 Ok(Some(workspace_edit)) 472 Ok(Some(workspace_edit))
475} 473}
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 34f510e73..dc67d19a7 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -698,7 +698,7 @@ pub(crate) fn snippet_workspace_edit(
698 let ops = snippet_text_document_ops(snap, op); 698 let ops = snippet_text_document_ops(snap, op);
699 document_changes.extend_from_slice(&ops); 699 document_changes.extend_from_slice(&ops);
700 } 700 }
701 for (file_id, edit) in source_change.source_file_edits.edits { 701 for (file_id, edit) in source_change.source_file_edits {
702 let edit = snippet_text_document_edit(&snap, source_change.is_snippet, file_id, edit)?; 702 let edit = snippet_text_document_edit(&snap, source_change.is_snippet, file_id, edit)?;
703 document_changes.push(lsp_ext::SnippetDocumentChangeOperation::Edit(edit)); 703 document_changes.push(lsp_ext::SnippetDocumentChangeOperation::Edit(edit));
704 } 704 }