diff options
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/join_lines.rs | 24 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 9 |
2 files changed, 17 insertions, 16 deletions
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 @@ | |||
1 | use itertools::Itertools; | 1 | use itertools::Itertools; |
2 | use ra_db::FileRange; | ||
2 | use ra_syntax::{ | 3 | use ra_syntax::{ |
3 | SourceFile, TextRange, TextUnit, AstNode, SyntaxNode, | 4 | SourceFile, TextRange, TextUnit, AstNode, SyntaxNode, |
4 | SyntaxKind::{self, WHITESPACE, COMMA, R_CURLY, R_PAREN, R_BRACK}, | 5 | SyntaxKind::{self, WHITESPACE, COMMA, R_CURLY, R_PAREN, R_BRACK}, |
@@ -9,26 +10,19 @@ use ra_syntax::{ | |||
9 | use ra_fmt::{ | 10 | use ra_fmt::{ |
10 | compute_ws, extract_trivial_expression | 11 | compute_ws, extract_trivial_expression |
11 | }; | 12 | }; |
12 | use ra_text_edit::TextEditBuilder; | 13 | use ra_text_edit::{TextEdit, TextEditBuilder}; |
13 | use ra_ide_api_light::LocalEdit; | ||
14 | 14 | ||
15 | pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { | 15 | pub fn join_lines(file: &SourceFile, frange: FileRange) -> TextEdit { |
16 | let range = if range.is_empty() { | 16 | let range = if frange.range.is_empty() { |
17 | let syntax = file.syntax(); | 17 | let syntax = file.syntax(); |
18 | let text = syntax.text().slice(range.start()..); | 18 | let text = syntax.text().slice(frange.range.start()..); |
19 | let pos = match text.find('\n') { | 19 | let pos = match text.find('\n') { |
20 | None => { | 20 | None => return TextEditBuilder::default().finish(), |
21 | return LocalEdit { | ||
22 | label: "join lines".to_string(), | ||
23 | edit: TextEditBuilder::default().finish(), | ||
24 | cursor_position: None, | ||
25 | }; | ||
26 | } | ||
27 | Some(pos) => pos, | 21 | Some(pos) => pos, |
28 | }; | 22 | }; |
29 | TextRange::offset_len(range.start() + pos, TextUnit::of_char('\n')) | 23 | TextRange::offset_len(frange.range.start() + pos, TextUnit::of_char('\n')) |
30 | } else { | 24 | } else { |
31 | range | 25 | frange.range |
32 | }; | 26 | }; |
33 | 27 | ||
34 | let node = find_covering_node(file.syntax(), range); | 28 | let node = find_covering_node(file.syntax(), range); |
@@ -51,7 +45,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { | |||
51 | } | 45 | } |
52 | } | 46 | } |
53 | 47 | ||
54 | LocalEdit { label: "join lines".to_string(), edit: edit.finish(), cursor_position: None } | 48 | edit.finish() |
55 | } | 49 | } |
56 | 50 | ||
57 | fn remove_newline( | 51 | 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 { | |||
279 | /// stuff like trailing commas. | 279 | /// stuff like trailing commas. |
280 | pub fn join_lines(&self, frange: FileRange) -> SourceChange { | 280 | pub fn join_lines(&self, frange: FileRange) -> SourceChange { |
281 | let file = self.db.parse(frange.file_id); | 281 | let file = self.db.parse(frange.file_id); |
282 | SourceChange::from_local_edit(frange.file_id, join_lines::join_lines(&file, frange.range)) | 282 | let file_edit = |
283 | SourceFileEdit { file_id: frange.file_id, edit: join_lines::join_lines(&file, frange) }; | ||
284 | SourceChange { | ||
285 | label: "join lines".to_string(), | ||
286 | source_file_edits: vec![file_edit], | ||
287 | file_system_edits: vec![], | ||
288 | cursor_position: None, | ||
289 | } | ||
283 | } | 290 | } |
284 | 291 | ||
285 | /// Returns an edit which should be applied when opening a new line, fixing | 292 | /// Returns an edit which should be applied when opening a new line, fixing |