From 9bd8336c512185df42f76b8f24a89960e2afb90e Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Thu, 21 Mar 2019 21:42:22 +0100 Subject: Remove LocalEdit usage --- crates/ra_ide_api/src/join_lines.rs | 24 +++++++++--------------- crates/ra_ide_api/src/lib.rs | 9 ++++++++- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs index d6274dc97..6e84e4b10 100644 --- a/crates/ra_ide_api/src/join_lines.rs +++ b/crates/ra_ide_api/src/join_lines.rs @@ -1,4 +1,5 @@ use itertools::Itertools; +use ra_db::FileRange; use ra_syntax::{ SourceFile, TextRange, TextUnit, AstNode, SyntaxNode, SyntaxKind::{self, WHITESPACE, COMMA, R_CURLY, R_PAREN, R_BRACK}, @@ -9,26 +10,19 @@ use ra_syntax::{ use ra_fmt::{ compute_ws, extract_trivial_expression }; -use ra_text_edit::TextEditBuilder; -use ra_ide_api_light::LocalEdit; +use ra_text_edit::{TextEdit, TextEditBuilder}; -pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { - let range = if range.is_empty() { +pub fn join_lines(file: &SourceFile, frange: FileRange) -> TextEdit { + let range = if frange.range.is_empty() { let syntax = file.syntax(); - let text = syntax.text().slice(range.start()..); + let text = syntax.text().slice(frange.range.start()..); let pos = match text.find('\n') { - None => { - return LocalEdit { - label: "join lines".to_string(), - edit: TextEditBuilder::default().finish(), - cursor_position: None, - }; - } + None => return TextEditBuilder::default().finish(), Some(pos) => pos, }; - TextRange::offset_len(range.start() + pos, TextUnit::of_char('\n')) + TextRange::offset_len(frange.range.start() + pos, TextUnit::of_char('\n')) } else { - range + frange.range }; let node = find_covering_node(file.syntax(), range); @@ -51,7 +45,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { } } - LocalEdit { label: "join lines".to_string(), edit: edit.finish(), cursor_position: None } + edit.finish() } fn remove_newline( diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 9e76dabff..d4dba1eeb 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -279,7 +279,14 @@ impl Analysis { /// stuff like trailing commas. pub fn join_lines(&self, frange: FileRange) -> SourceChange { let file = self.db.parse(frange.file_id); - SourceChange::from_local_edit(frange.file_id, join_lines::join_lines(&file, frange.range)) + let file_edit = + SourceFileEdit { file_id: frange.file_id, edit: join_lines::join_lines(&file, frange) }; + SourceChange { + label: "join lines".to_string(), + source_file_edits: vec![file_edit], + file_system_edits: vec![], + cursor_position: None, + } } /// Returns an edit which should be applied when opening a new line, fixing -- cgit v1.2.3