]> git.lizzy.rs Git - rust.git/commitdiff
hide atom edits a bit
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 21 Dec 2018 08:24:16 +0000 (11:24 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 21 Dec 2018 08:52:32 +0000 (11:52 +0300)
crates/ra_analysis/src/imp.rs
crates/ra_analysis/src/lib.rs
crates/ra_lsp_server/src/conv.rs
crates/ra_lsp_server/src/main_loop/handlers.rs
crates/ra_text_edit/src/text_edit.rs

index cefe5a748ecd2636a080782f60dcc1bb30453754..a7be56f5a19eafb67c7a2896a23a3814148a2366 100644 (file)
@@ -520,7 +520,7 @@ impl SourceChange {
     pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange {
         let file_edit = SourceFileEdit {
             file_id,
-            edits: edit.edit.into_atoms(),
+            edit: edit.edit,
         };
         SourceChange {
             label: label.to_string(),
index d5725ef2e5dde28ffa29aa5f8a796a202dc37bdc..2fb11365c3d8427168e5517ce460a504aad0d3e2 100644 (file)
@@ -20,7 +20,7 @@ macro_rules! ctry {
 
 use rustc_hash::FxHashMap;
 use ra_syntax::{SourceFileNode, TextRange, TextUnit};
-use ra_text_edit::AtomTextEdit;
+use ra_text_edit::TextEdit;
 use rayon::prelude::*;
 use relative_path::RelativePathBuf;
 
@@ -167,7 +167,7 @@ pub struct SourceChange {
 #[derive(Debug)]
 pub struct SourceFileEdit {
     pub file_id: FileId,
-    pub edits: Vec<AtomTextEdit>,
+    pub edit: TextEdit,
 }
 
 #[derive(Debug)]
index 198dbfc4951763ef96a0154637cef0bbd281b0ec..3531b727e98cdd4d86979658632481d3e2430b40 100644 (file)
@@ -97,21 +97,21 @@ impl ConvWith for TextEdit {
     type Output = Vec<languageserver_types::TextEdit>;
 
     fn conv_with(self, line_index: &LineIndex) -> Vec<languageserver_types::TextEdit> {
-        self.into_atoms()
+        self.as_atoms()
             .into_iter()
             .map_conv_with(line_index)
             .collect()
     }
 }
 
-impl ConvWith for AtomTextEdit {
+impl<'a> ConvWith for &'a AtomTextEdit {
     type Ctx = LineIndex;
     type Output = languageserver_types::TextEdit;
 
     fn conv_with(self, line_index: &LineIndex) -> languageserver_types::TextEdit {
         languageserver_types::TextEdit {
             range: self.delete.conv_with(line_index),
-            new_text: self.insert,
+            new_text: self.insert.clone(),
         }
     }
 }
@@ -199,7 +199,7 @@ fn try_conv_with(self, world: &ServerWorld) -> Result<req::SourceChange> {
                     .source_file_edits
                     .iter()
                     .find(|it| it.file_id == pos.file_id)
-                    .map(|it| it.edits.as_slice())
+                    .map(|it| it.edit.as_atoms())
                     .unwrap_or(&[]);
                 let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits);
                 let position =
@@ -265,7 +265,12 @@ fn try_conv_with(self, world: &ServerWorld) -> Result<TextDocumentEdit> {
             version: None,
         };
         let line_index = world.analysis().file_line_index(self.file_id);
-        let edits = self.edits.into_iter().map_conv_with(&line_index).collect();
+        let edits = self
+            .edit
+            .as_atoms()
+            .iter()
+            .map_conv_with(&line_index)
+            .collect();
         Ok(TextDocumentEdit {
             text_document,
             edits,
index 801966304cf535fc69a0903cd20a37cce9ddfee0..1751d7fa81bffbd3fcba3b76e92ce3f3c20e8577 100644 (file)
@@ -107,9 +107,16 @@ pub fn handle_on_type_formatting(
     };
     let edits = match world.analysis().on_eq_typed(position) {
         None => return Ok(None),
-        Some(mut action) => action.source_file_edits.pop().unwrap().edits,
+        Some(mut action) => action
+            .source_file_edits
+            .pop()
+            .unwrap()
+            .edit
+            .as_atoms()
+            .iter()
+            .map_conv_with(&line_index)
+            .collect(),
     };
-    let edits = edits.into_iter().map_conv_with(&line_index).collect();
     Ok(Some(edits))
 }
 
index fb46f046d8441afdd01e51035b42d674a7248763..392968d638f369fe5a57c25a71f58916a2b0a0d5 100644 (file)
@@ -41,8 +41,8 @@ pub fn invalidates_offset(&self, offset: TextUnit) -> bool {
 }
 
 impl TextEdit {
-    pub fn into_atoms(self) -> Vec<AtomTextEdit> {
-        self.atoms
+    pub fn as_atoms(&self) -> &[AtomTextEdit] {
+        &self.atoms
     }
 
     pub fn apply(&self, text: &str) -> String {