aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/join_lines.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/join_lines.rs')
-rw-r--r--crates/ra_ide_api/src/join_lines.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs
index 6e84e4b10..8fb3eaa06 100644
--- a/crates/ra_ide_api/src/join_lines.rs
+++ b/crates/ra_ide_api/src/join_lines.rs
@@ -1,5 +1,4 @@
1use itertools::Itertools; 1use itertools::Itertools;
2use ra_db::FileRange;
3use ra_syntax::{ 2use ra_syntax::{
4 SourceFile, TextRange, TextUnit, AstNode, SyntaxNode, 3 SourceFile, TextRange, TextUnit, AstNode, SyntaxNode,
5 SyntaxKind::{self, WHITESPACE, COMMA, R_CURLY, R_PAREN, R_BRACK}, 4 SyntaxKind::{self, WHITESPACE, COMMA, R_CURLY, R_PAREN, R_BRACK},
@@ -12,17 +11,17 @@ use ra_fmt::{
12}; 11};
13use ra_text_edit::{TextEdit, TextEditBuilder}; 12use ra_text_edit::{TextEdit, TextEditBuilder};
14 13
15pub fn join_lines(file: &SourceFile, frange: FileRange) -> TextEdit { 14pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
16 let range = if frange.range.is_empty() { 15 let range = if range.is_empty() {
17 let syntax = file.syntax(); 16 let syntax = file.syntax();
18 let text = syntax.text().slice(frange.range.start()..); 17 let text = syntax.text().slice(range.start()..);
19 let pos = match text.find('\n') { 18 let pos = match text.find('\n') {
20 None => return TextEditBuilder::default().finish(), 19 None => return TextEditBuilder::default().finish(),
21 Some(pos) => pos, 20 Some(pos) => pos,
22 }; 21 };
23 TextRange::offset_len(frange.range.start() + pos, TextUnit::of_char('\n')) 22 TextRange::offset_len(range.start() + pos, TextUnit::of_char('\n'))
24 } else { 23 } else {
25 frange.range 24 range
26 }; 25 };
27 26
28 let node = find_covering_node(file.syntax(), range); 27 let node = find_covering_node(file.syntax(), range);
@@ -507,7 +506,7 @@ fn foo() {
507 let (sel, before) = extract_range(before); 506 let (sel, before) = extract_range(before);
508 let file = SourceFile::parse(&before); 507 let file = SourceFile::parse(&before);
509 let result = join_lines(&file, sel); 508 let result = join_lines(&file, sel);
510 let actual = result.edit.apply(&before); 509 let actual = result.apply(&before);
511 assert_eq_text!(after, &actual); 510 assert_eq_text!(after, &actual);
512 } 511 }
513 512