diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-08 09:05:55 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-08 09:05:55 +0000 |
commit | 3f4be819125ce4a22edd86721fa56b5caba99c2e (patch) | |
tree | be93895ddc08c911585d9f7bc64623a3741f32c6 /crates/ra_editor/src/typing.rs | |
parent | 4e444d2bc24d16284401444fd2154f63e0f96070 (diff) | |
parent | 122410d7aa34a32d468a3173858cbc8a2bbc68f5 (diff) |
Merge #449
449: switch to new rowan API r=matklad a=matklad
closes https://github.com/rust-analyzer/rust-analyzer/issues/448
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_editor/src/typing.rs')
-rw-r--r-- | crates/ra_editor/src/typing.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs index 12500854c..5b260d2ac 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs | |||
@@ -5,15 +5,15 @@ use ra_syntax::{ | |||
5 | algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, | 5 | algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, |
6 | ast, | 6 | ast, |
7 | text_utils::intersect, | 7 | text_utils::intersect, |
8 | AstNode, Direction, SourceFileNode, SyntaxKind, | 8 | AstNode, Direction, SourceFile, SyntaxKind, |
9 | SyntaxKind::*, | 9 | SyntaxKind::*, |
10 | SyntaxNodeRef, TextRange, TextUnit, | 10 | SyntaxNode, TextRange, TextUnit, |
11 | }; | 11 | }; |
12 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 12 | use ra_text_edit::text_utils::contains_offset_nonstrict; |
13 | 13 | ||
14 | use crate::{find_node_at_offset, LocalEdit, TextEditBuilder}; | 14 | use crate::{find_node_at_offset, LocalEdit, TextEditBuilder}; |
15 | 15 | ||
16 | pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { | 16 | pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { |
17 | let range = if range.is_empty() { | 17 | let range = if range.is_empty() { |
18 | let syntax = file.syntax(); | 18 | let syntax = file.syntax(); |
19 | let text = syntax.text().slice(range.start()..); | 19 | let text = syntax.text().slice(range.start()..); |
@@ -59,7 +59,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { | |||
59 | } | 59 | } |
60 | } | 60 | } |
61 | 61 | ||
62 | pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { | 62 | pub fn on_enter(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> { |
63 | let comment = find_leaf_at_offset(file.syntax(), offset) | 63 | let comment = find_leaf_at_offset(file.syntax(), offset) |
64 | .left_biased() | 64 | .left_biased() |
65 | .and_then(ast::Comment::cast)?; | 65 | .and_then(ast::Comment::cast)?; |
@@ -85,7 +85,7 @@ pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { | |||
85 | }) | 85 | }) |
86 | } | 86 | } |
87 | 87 | ||
88 | fn node_indent<'a>(file: &'a SourceFileNode, node: SyntaxNodeRef) -> Option<&'a str> { | 88 | fn node_indent<'a>(file: &'a SourceFile, node: &SyntaxNode) -> Option<&'a str> { |
89 | let ws = match find_leaf_at_offset(file.syntax(), node.range().start()) { | 89 | let ws = match find_leaf_at_offset(file.syntax(), node.range().start()) { |
90 | LeafAtOffset::Between(l, r) => { | 90 | LeafAtOffset::Between(l, r) => { |
91 | assert!(r == node); | 91 | assert!(r == node); |
@@ -105,8 +105,8 @@ fn node_indent<'a>(file: &'a SourceFileNode, node: SyntaxNodeRef) -> Option<&'a | |||
105 | Some(&text[pos..]) | 105 | Some(&text[pos..]) |
106 | } | 106 | } |
107 | 107 | ||
108 | pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { | 108 | pub fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> { |
109 | let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; | 109 | let let_stmt: &ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; |
110 | if let_stmt.has_semi() { | 110 | if let_stmt.has_semi() { |
111 | return None; | 111 | return None; |
112 | } | 112 | } |
@@ -136,7 +136,7 @@ pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> | |||
136 | }) | 136 | }) |
137 | } | 137 | } |
138 | 138 | ||
139 | pub fn on_dot_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { | 139 | pub fn on_dot_typed(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> { |
140 | let before_dot_offset = offset - TextUnit::of_char('.'); | 140 | let before_dot_offset = offset - TextUnit::of_char('.'); |
141 | 141 | ||
142 | let whitespace = find_leaf_at_offset(file.syntax(), before_dot_offset).left_biased()?; | 142 | let whitespace = find_leaf_at_offset(file.syntax(), before_dot_offset).left_biased()?; |
@@ -151,7 +151,7 @@ pub fn on_dot_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit | |||
151 | .skip(1) | 151 | .skip(1) |
152 | .next()?; | 152 | .next()?; |
153 | 153 | ||
154 | ast::MethodCallExprNode::cast(method_call)?; | 154 | ast::MethodCallExpr::cast(method_call)?; |
155 | 155 | ||
156 | // find how much the _method call is indented | 156 | // find how much the _method call is indented |
157 | let method_chain_indent = method_call | 157 | let method_chain_indent = method_call |
@@ -188,7 +188,7 @@ fn last_line_indent_in_whitespace(ws: &str) -> &str { | |||
188 | 188 | ||
189 | fn remove_newline( | 189 | fn remove_newline( |
190 | edit: &mut TextEditBuilder, | 190 | edit: &mut TextEditBuilder, |
191 | node: SyntaxNodeRef, | 191 | node: &SyntaxNode, |
192 | node_text: &str, | 192 | node_text: &str, |
193 | offset: TextUnit, | 193 | offset: TextUnit, |
194 | ) { | 194 | ) { |
@@ -266,7 +266,7 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { | |||
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | fn join_single_expr_block(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> { | 269 | fn join_single_expr_block(edit: &mut TextEditBuilder, node: &SyntaxNode) -> Option<()> { |
270 | let block = ast::Block::cast(node.parent()?)?; | 270 | let block = ast::Block::cast(node.parent()?)?; |
271 | let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; | 271 | let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; |
272 | let expr = single_expr(block)?; | 272 | let expr = single_expr(block)?; |
@@ -277,7 +277,7 @@ fn join_single_expr_block(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Op | |||
277 | Some(()) | 277 | Some(()) |
278 | } | 278 | } |
279 | 279 | ||
280 | fn single_expr(block: ast::Block) -> Option<ast::Expr> { | 280 | fn single_expr(block: &ast::Block) -> Option<&ast::Expr> { |
281 | let mut res = None; | 281 | let mut res = None; |
282 | for child in block.syntax().children() { | 282 | for child in block.syntax().children() { |
283 | if let Some(expr) = ast::Expr::cast(child) { | 283 | if let Some(expr) = ast::Expr::cast(child) { |
@@ -297,7 +297,7 @@ fn single_expr(block: ast::Block) -> Option<ast::Expr> { | |||
297 | res | 297 | res |
298 | } | 298 | } |
299 | 299 | ||
300 | fn join_single_use_tree(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> { | 300 | fn join_single_use_tree(edit: &mut TextEditBuilder, node: &SyntaxNode) -> Option<()> { |
301 | let use_tree_list = ast::UseTreeList::cast(node.parent()?)?; | 301 | let use_tree_list = ast::UseTreeList::cast(node.parent()?)?; |
302 | let (tree,) = use_tree_list.use_trees().collect_tuple()?; | 302 | let (tree,) = use_tree_list.use_trees().collect_tuple()?; |
303 | edit.replace( | 303 | edit.replace( |
@@ -307,7 +307,7 @@ fn join_single_use_tree(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Opti | |||
307 | Some(()) | 307 | Some(()) |
308 | } | 308 | } |
309 | 309 | ||
310 | fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str { | 310 | fn compute_ws(left: &SyntaxNode, right: &SyntaxNode) -> &'static str { |
311 | match left.kind() { | 311 | match left.kind() { |
312 | L_PAREN | L_BRACK => return "", | 312 | L_PAREN | L_BRACK => return "", |
313 | L_CURLY => { | 313 | L_CURLY => { |
@@ -547,7 +547,7 @@ fn foo() { | |||
547 | 547 | ||
548 | fn check_join_lines_sel(before: &str, after: &str) { | 548 | fn check_join_lines_sel(before: &str, after: &str) { |
549 | let (sel, before) = extract_range(before); | 549 | let (sel, before) = extract_range(before); |
550 | let file = SourceFileNode::parse(&before); | 550 | let file = SourceFile::parse(&before); |
551 | let result = join_lines(&file, sel); | 551 | let result = join_lines(&file, sel); |
552 | let actual = result.edit.apply(&before); | 552 | let actual = result.edit.apply(&before); |
553 | assert_eq_text!(after, &actual); | 553 | assert_eq_text!(after, &actual); |
@@ -626,7 +626,7 @@ pub fn handle_find_matching_brace() { | |||
626 | fn test_on_eq_typed() { | 626 | fn test_on_eq_typed() { |
627 | fn do_check(before: &str, after: &str) { | 627 | fn do_check(before: &str, after: &str) { |
628 | let (offset, before) = extract_offset(before); | 628 | let (offset, before) = extract_offset(before); |
629 | let file = SourceFileNode::parse(&before); | 629 | let file = SourceFile::parse(&before); |
630 | let result = on_eq_typed(&file, offset).unwrap(); | 630 | let result = on_eq_typed(&file, offset).unwrap(); |
631 | let actual = result.edit.apply(&before); | 631 | let actual = result.edit.apply(&before); |
632 | assert_eq_text!(after, &actual); | 632 | assert_eq_text!(after, &actual); |
@@ -670,7 +670,7 @@ fn foo() { | |||
670 | fn test_on_dot_typed() { | 670 | fn test_on_dot_typed() { |
671 | fn do_check(before: &str, after: &str) { | 671 | fn do_check(before: &str, after: &str) { |
672 | let (offset, before) = extract_offset(before); | 672 | let (offset, before) = extract_offset(before); |
673 | let file = SourceFileNode::parse(&before); | 673 | let file = SourceFile::parse(&before); |
674 | if let Some(result) = on_eq_typed(&file, offset) { | 674 | if let Some(result) = on_eq_typed(&file, offset) { |
675 | let actual = result.edit.apply(&before); | 675 | let actual = result.edit.apply(&before); |
676 | assert_eq_text!(after, &actual); | 676 | assert_eq_text!(after, &actual); |
@@ -779,7 +779,7 @@ fn foo() { | |||
779 | fn test_on_enter() { | 779 | fn test_on_enter() { |
780 | fn apply_on_enter(before: &str) -> Option<String> { | 780 | fn apply_on_enter(before: &str) -> Option<String> { |
781 | let (offset, before) = extract_offset(before); | 781 | let (offset, before) = extract_offset(before); |
782 | let file = SourceFileNode::parse(&before); | 782 | let file = SourceFile::parse(&before); |
783 | let result = on_enter(&file, offset)?; | 783 | let result = on_enter(&file, offset)?; |
784 | let actual = result.edit.apply(&before); | 784 | let actual = result.edit.apply(&before); |
785 | let actual = add_cursor(&actual, result.cursor_position.unwrap()); | 785 | let actual = add_cursor(&actual, result.cursor_position.unwrap()); |