From 0063f03e86f4222a5027720142eb20db4adc485d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 21 Dec 2018 11:24:16 +0300 Subject: hide atom edits a bit --- crates/ra_analysis/src/imp.rs | 2 +- crates/ra_analysis/src/lib.rs | 4 ++-- crates/ra_lsp_server/src/conv.rs | 15 ++++++++++----- crates/ra_lsp_server/src/main_loop/handlers.rs | 11 +++++++++-- crates/ra_text_edit/src/text_edit.rs | 4 ++-- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index cefe5a748..a7be56f5a 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -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(), diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index d5725ef2e..2fb11365c 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -20,7 +20,7 @@ use std::{fmt, sync::Arc}; 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, + pub edit: TextEdit, } #[derive(Debug)] diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 198dbfc49..3531b727e 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -97,21 +97,21 @@ impl ConvWith for TextEdit { type Output = Vec; fn conv_with(self, line_index: &LineIndex) -> Vec { - 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 @@ impl TryConvWith for 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 @@ impl TryConvWith for SourceFileEdit { 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, diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 801966304..1751d7fa8 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -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)) } diff --git a/crates/ra_text_edit/src/text_edit.rs b/crates/ra_text_edit/src/text_edit.rs index fb46f046d..392968d63 100644 --- a/crates/ra_text_edit/src/text_edit.rs +++ b/crates/ra_text_edit/src/text_edit.rs @@ -41,8 +41,8 @@ impl TextEditBuilder { } impl TextEdit { - pub fn into_atoms(self) -> Vec { - self.atoms + pub fn as_atoms(&self) -> &[AtomTextEdit] { + &self.atoms } pub fn apply(&self, text: &str) -> String { -- cgit v1.2.3