diff options
author | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
commit | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch) | |
tree | 71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/ra_ide_api_light/src/join_lines.rs | |
parent | 5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff) |
reformat the world
Diffstat (limited to 'crates/ra_ide_api_light/src/join_lines.rs')
-rw-r--r-- | crates/ra_ide_api_light/src/join_lines.rs | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/crates/ra_ide_api_light/src/join_lines.rs b/crates/ra_ide_api_light/src/join_lines.rs index ab7c5b4b5..03770c52e 100644 --- a/crates/ra_ide_api_light/src/join_lines.rs +++ b/crates/ra_ide_api_light/src/join_lines.rs | |||
@@ -50,11 +50,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { | |||
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | LocalEdit { | 53 | LocalEdit { label: "join lines".to_string(), edit: edit.finish(), cursor_position: None } |
54 | label: "join lines".to_string(), | ||
55 | edit: edit.finish(), | ||
56 | cursor_position: None, | ||
57 | } | ||
58 | } | 54 | } |
59 | 55 | ||
60 | fn remove_newline( | 56 | fn remove_newline( |
@@ -71,10 +67,7 @@ fn remove_newline( | |||
71 | )]; | 67 | )]; |
72 | let spaces = suff.bytes().take_while(|&b| b == b' ').count(); | 68 | let spaces = suff.bytes().take_while(|&b| b == b' ').count(); |
73 | 69 | ||
74 | edit.replace( | 70 | edit.replace(TextRange::offset_len(offset, ((spaces + 1) as u32).into()), " ".to_string()); |
75 | TextRange::offset_len(offset, ((spaces + 1) as u32).into()), | ||
76 | " ".to_string(), | ||
77 | ); | ||
78 | return; | 71 | return; |
79 | } | 72 | } |
80 | 73 | ||
@@ -109,11 +102,7 @@ fn remove_newline( | |||
109 | edit.delete(TextRange::from_to(prev.range().start(), node.range().end())); | 102 | edit.delete(TextRange::from_to(prev.range().start(), node.range().end())); |
110 | } else if prev.kind() == COMMA && next.kind() == R_CURLY { | 103 | } else if prev.kind() == COMMA && next.kind() == R_CURLY { |
111 | // Removes: comma, newline (incl. surrounding whitespace) | 104 | // Removes: comma, newline (incl. surrounding whitespace) |
112 | let space = if let Some(left) = prev.prev_sibling() { | 105 | let space = if let Some(left) = prev.prev_sibling() { compute_ws(left, next) } else { " " }; |
113 | compute_ws(left, next) | ||
114 | } else { | ||
115 | " " | ||
116 | }; | ||
117 | edit.replace( | 106 | edit.replace( |
118 | TextRange::from_to(prev.range().start(), node.range().end()), | 107 | TextRange::from_to(prev.range().start(), node.range().end()), |
119 | space.to_string(), | 108 | space.to_string(), |
@@ -134,20 +123,14 @@ fn join_single_expr_block(edit: &mut TextEditBuilder, node: &SyntaxNode) -> Opti | |||
134 | let block = ast::Block::cast(node.parent()?)?; | 123 | let block = ast::Block::cast(node.parent()?)?; |
135 | let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; | 124 | let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; |
136 | let expr = extract_trivial_expression(block)?; | 125 | let expr = extract_trivial_expression(block)?; |
137 | edit.replace( | 126 | edit.replace(block_expr.syntax().range(), expr.syntax().text().to_string()); |
138 | block_expr.syntax().range(), | ||
139 | expr.syntax().text().to_string(), | ||
140 | ); | ||
141 | Some(()) | 127 | Some(()) |
142 | } | 128 | } |
143 | 129 | ||
144 | fn join_single_use_tree(edit: &mut TextEditBuilder, node: &SyntaxNode) -> Option<()> { | 130 | fn join_single_use_tree(edit: &mut TextEditBuilder, node: &SyntaxNode) -> Option<()> { |
145 | let use_tree_list = ast::UseTreeList::cast(node.parent()?)?; | 131 | let use_tree_list = ast::UseTreeList::cast(node.parent()?)?; |
146 | let (tree,) = use_tree_list.use_trees().collect_tuple()?; | 132 | let (tree,) = use_tree_list.use_trees().collect_tuple()?; |
147 | edit.replace( | 133 | edit.replace(use_tree_list.syntax().range(), tree.syntax().text().to_string()); |
148 | use_tree_list.syntax().range(), | ||
149 | tree.syntax().text().to_string(), | ||
150 | ); | ||
151 | Some(()) | 134 | Some(()) |
152 | } | 135 | } |
153 | 136 | ||