aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor')
-rw-r--r--crates/ra_editor/src/assists.rs39
-rw-r--r--crates/ra_editor/src/assists/add_derive.rs2
-rw-r--r--crates/ra_editor/src/assists/add_impl.rs2
-rw-r--r--crates/ra_editor/src/assists/change_visibility.rs2
-rw-r--r--crates/ra_editor/src/assists/introduce_variable.rs4
-rw-r--r--crates/ra_editor/src/assists/replace_if_let_with_match.rs92
-rw-r--r--crates/ra_editor/src/diagnostics.rs32
-rw-r--r--crates/ra_editor/src/extend_selection.rs24
-rw-r--r--crates/ra_editor/src/folding_ranges.rs17
-rw-r--r--crates/ra_editor/src/lib.rs24
-rw-r--r--crates/ra_editor/src/structure.rs12
-rw-r--r--crates/ra_editor/src/test_utils.rs15
-rw-r--r--crates/ra_editor/src/typing.rs36
13 files changed, 203 insertions, 98 deletions
diff --git a/crates/ra_editor/src/assists.rs b/crates/ra_editor/src/assists.rs
index 57b78342a..f839f6a7a 100644
--- a/crates/ra_editor/src/assists.rs
+++ b/crates/ra_editor/src/assists.rs
@@ -9,12 +9,15 @@ mod add_impl;
9mod introduce_variable; 9mod introduce_variable;
10mod change_visibility; 10mod change_visibility;
11mod split_import; 11mod split_import;
12mod replace_if_let_with_match;
12 13
13use ra_text_edit::{TextEdit, TextEditBuilder}; 14use ra_text_edit::{TextEdit, TextEditBuilder};
14use ra_syntax::{ 15use ra_syntax::{
15 Direction, SyntaxNodeRef, TextUnit, TextRange,SourceFileNode, AstNode, 16 Direction, SyntaxNode, TextUnit, TextRange, SourceFile, AstNode,
16 algo::{find_leaf_at_offset, find_covering_node, LeafAtOffset}, 17 algo::{find_leaf_at_offset, find_covering_node, LeafAtOffset},
18 ast::{self, AstToken},
17}; 19};
20use itertools::Itertools;
18 21
19use crate::find_node_at_offset; 22use crate::find_node_at_offset;
20 23
@@ -25,10 +28,11 @@ pub use self::{
25 introduce_variable::introduce_variable, 28 introduce_variable::introduce_variable,
26 change_visibility::change_visibility, 29 change_visibility::change_visibility,
27 split_import::split_import, 30 split_import::split_import,
31 replace_if_let_with_match::replace_if_let_with_match,
28}; 32};
29 33
30/// Return all the assists applicable at the given position. 34/// Return all the assists applicable at the given position.
31pub fn assists(file: &SourceFileNode, range: TextRange) -> Vec<LocalEdit> { 35pub fn assists(file: &SourceFile, range: TextRange) -> Vec<LocalEdit> {
32 let ctx = AssistCtx::new(file, range); 36 let ctx = AssistCtx::new(file, range);
33 [ 37 [
34 flip_comma, 38 flip_comma,
@@ -37,6 +41,7 @@ pub fn assists(file: &SourceFileNode, range: TextRange) -> Vec<LocalEdit> {
37 introduce_variable, 41 introduce_variable,
38 change_visibility, 42 change_visibility,
39 split_import, 43 split_import,
44 replace_if_let_with_match,
40 ] 45 ]
41 .iter() 46 .iter()
42 .filter_map(|&assist| ctx.clone().apply(assist)) 47 .filter_map(|&assist| ctx.clone().apply(assist))
@@ -50,7 +55,7 @@ pub struct LocalEdit {
50 pub cursor_position: Option<TextUnit>, 55 pub cursor_position: Option<TextUnit>,
51} 56}
52 57
53fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<SyntaxNodeRef> { 58fn non_trivia_sibling(node: &SyntaxNode, direction: Direction) -> Option<&SyntaxNode> {
54 node.siblings(direction) 59 node.siblings(direction)
55 .skip(1) 60 .skip(1)
56 .find(|node| !node.kind().is_trivia()) 61 .find(|node| !node.kind().is_trivia())
@@ -88,7 +93,7 @@ fn non_trivia_sibling(node: SyntaxNodeRef, direction: Direction) -> Option<Synta
88/// easier to just compute the edit eagarly :-) 93/// easier to just compute the edit eagarly :-)
89#[derive(Debug, Clone)] 94#[derive(Debug, Clone)]
90pub struct AssistCtx<'a> { 95pub struct AssistCtx<'a> {
91 source_file: &'a SourceFileNode, 96 source_file: &'a SourceFile,
92 range: TextRange, 97 range: TextRange,
93 should_compute_edit: bool, 98 should_compute_edit: bool,
94} 99}
@@ -106,7 +111,7 @@ struct AssistBuilder {
106} 111}
107 112
108impl<'a> AssistCtx<'a> { 113impl<'a> AssistCtx<'a> {
109 pub fn new(source_file: &'a SourceFileNode, range: TextRange) -> AssistCtx { 114 pub fn new(source_file: &'a SourceFile, range: TextRange) -> AssistCtx {
110 AssistCtx { 115 AssistCtx {
111 source_file, 116 source_file,
112 range, 117 range,
@@ -145,13 +150,13 @@ impl<'a> AssistCtx<'a> {
145 })) 150 }))
146 } 151 }
147 152
148 pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<SyntaxNodeRef<'a>> { 153 pub(crate) fn leaf_at_offset(&self) -> LeafAtOffset<&'a SyntaxNode> {
149 find_leaf_at_offset(self.source_file.syntax(), self.range.start()) 154 find_leaf_at_offset(self.source_file.syntax(), self.range.start())
150 } 155 }
151 pub(crate) fn node_at_offset<N: AstNode<'a>>(&self) -> Option<N> { 156 pub(crate) fn node_at_offset<N: AstNode>(&self) -> Option<&'a N> {
152 find_node_at_offset(self.source_file.syntax(), self.range.start()) 157 find_node_at_offset(self.source_file.syntax(), self.range.start())
153 } 158 }
154 pub(crate) fn covering_node(&self) -> SyntaxNodeRef<'a> { 159 pub(crate) fn covering_node(&self) -> &'a SyntaxNode {
155 find_covering_node(self.source_file.syntax(), self.range) 160 find_covering_node(self.source_file.syntax(), self.range)
156 } 161 }
157} 162}
@@ -160,6 +165,13 @@ impl AssistBuilder {
160 fn replace(&mut self, range: TextRange, replace_with: impl Into<String>) { 165 fn replace(&mut self, range: TextRange, replace_with: impl Into<String>) {
161 self.edit.replace(range, replace_with.into()) 166 self.edit.replace(range, replace_with.into())
162 } 167 }
168 fn replace_node_and_indent(&mut self, node: &SyntaxNode, replace_with: impl Into<String>) {
169 let mut replace_with = replace_with.into();
170 if let Some(indent) = calc_indent(node) {
171 replace_with = reindent(&replace_with, indent)
172 }
173 self.replace(node.range(), replace_with)
174 }
163 #[allow(unused)] 175 #[allow(unused)]
164 fn delete(&mut self, range: TextRange) { 176 fn delete(&mut self, range: TextRange) {
165 self.edit.delete(range) 177 self.edit.delete(range)
@@ -172,6 +184,17 @@ impl AssistBuilder {
172 } 184 }
173} 185}
174 186
187fn calc_indent(node: &SyntaxNode) -> Option<&str> {
188 let prev = node.prev_sibling()?;
189 let ws_text = ast::Whitespace::cast(prev)?.text();
190 ws_text.rfind('\n').map(|pos| &ws_text[pos + 1..])
191}
192
193fn reindent(text: &str, indent: &str) -> String {
194 let indent = format!("\n{}", indent);
195 text.lines().intersperse(&indent).collect()
196}
197
175#[cfg(test)] 198#[cfg(test)]
176fn check_assist(assist: fn(AssistCtx) -> Option<Assist>, before: &str, after: &str) { 199fn check_assist(assist: fn(AssistCtx) -> Option<Assist>, before: &str, after: &str) {
177 crate::test_utils::check_action(before, after, |file, off| { 200 crate::test_utils::check_action(before, after, |file, off| {
diff --git a/crates/ra_editor/src/assists/add_derive.rs b/crates/ra_editor/src/assists/add_derive.rs
index 1e2cd4f30..6e964d011 100644
--- a/crates/ra_editor/src/assists/add_derive.rs
+++ b/crates/ra_editor/src/assists/add_derive.rs
@@ -28,7 +28,7 @@ pub fn add_derive(ctx: AssistCtx) -> Option<Assist> {
28} 28}
29 29
30// Insert `derive` after doc comments. 30// Insert `derive` after doc comments.
31fn derive_insertion_offset(nominal: ast::NominalDef) -> Option<TextUnit> { 31fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextUnit> {
32 let non_ws_child = nominal 32 let non_ws_child = nominal
33 .syntax() 33 .syntax()
34 .children() 34 .children()
diff --git a/crates/ra_editor/src/assists/add_impl.rs b/crates/ra_editor/src/assists/add_impl.rs
index 9353e2717..2eda7cae2 100644
--- a/crates/ra_editor/src/assists/add_impl.rs
+++ b/crates/ra_editor/src/assists/add_impl.rs
@@ -1,6 +1,6 @@
1use join_to_string::join; 1use join_to_string::join;
2use ra_syntax::{ 2use ra_syntax::{
3 ast::{self, AstNode, NameOwner, TypeParamsOwner}, 3 ast::{self, AstNode, AstToken, NameOwner, TypeParamsOwner},
4 TextUnit, 4 TextUnit,
5}; 5};
6 6
diff --git a/crates/ra_editor/src/assists/change_visibility.rs b/crates/ra_editor/src/assists/change_visibility.rs
index 6c8466394..89729e2c2 100644
--- a/crates/ra_editor/src/assists/change_visibility.rs
+++ b/crates/ra_editor/src/assists/change_visibility.rs
@@ -46,7 +46,7 @@ fn add_vis(ctx: AssistCtx) -> Option<Assist> {
46 }) 46 })
47} 47}
48 48
49fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> { 49fn change_vis(ctx: AssistCtx, vis: &ast::Visibility) -> Option<Assist> {
50 if vis.syntax().text() != "pub" { 50 if vis.syntax().text() != "pub" {
51 return None; 51 return None;
52 } 52 }
diff --git a/crates/ra_editor/src/assists/introduce_variable.rs b/crates/ra_editor/src/assists/introduce_variable.rs
index 782861023..523ec7034 100644
--- a/crates/ra_editor/src/assists/introduce_variable.rs
+++ b/crates/ra_editor/src/assists/introduce_variable.rs
@@ -1,7 +1,7 @@
1use ra_syntax::{ 1use ra_syntax::{
2 ast::{self, AstNode}, 2 ast::{self, AstNode},
3 SyntaxKind::WHITESPACE, 3 SyntaxKind::WHITESPACE,
4 SyntaxNodeRef, TextUnit, 4 SyntaxNode, TextUnit,
5}; 5};
6 6
7use crate::assists::{AssistCtx, Assist}; 7use crate::assists::{AssistCtx, Assist};
@@ -39,7 +39,7 @@ pub fn introduce_variable<'a>(ctx: AssistCtx) -> Option<Assist> {
39 39
40/// Statement or last in the block expression, which will follow 40/// Statement or last in the block expression, which will follow
41/// the freshly introduced var. 41/// the freshly introduced var.
42fn anchor_stmt(expr: ast::Expr) -> Option<SyntaxNodeRef> { 42fn anchor_stmt(expr: &ast::Expr) -> Option<&SyntaxNode> {
43 expr.syntax().ancestors().find(|&node| { 43 expr.syntax().ancestors().find(|&node| {
44 if ast::Stmt::cast(node).is_some() { 44 if ast::Stmt::cast(node).is_some() {
45 return true; 45 return true;
diff --git a/crates/ra_editor/src/assists/replace_if_let_with_match.rs b/crates/ra_editor/src/assists/replace_if_let_with_match.rs
new file mode 100644
index 000000000..30c371480
--- /dev/null
+++ b/crates/ra_editor/src/assists/replace_if_let_with_match.rs
@@ -0,0 +1,92 @@
1use ra_syntax::{
2 AstNode, SyntaxKind::{L_CURLY, R_CURLY, WHITESPACE},
3 ast,
4};
5
6use crate::assists::{AssistCtx, Assist};
7
8pub fn replace_if_let_with_match(ctx: AssistCtx) -> Option<Assist> {
9 let if_expr: &ast::IfExpr = ctx.node_at_offset()?;
10 let cond = if_expr.condition()?;
11 let pat = cond.pat()?;
12 let expr = cond.expr()?;
13 let then_block = if_expr.then_branch()?;
14 let else_block = if_expr.else_branch()?;
15
16 ctx.build("replace with match", |edit| {
17 let match_expr = build_match_expr(expr, pat, then_block, else_block);
18 edit.replace_node_and_indent(if_expr.syntax(), match_expr);
19 edit.set_cursor(if_expr.syntax().range().start())
20 })
21}
22
23fn build_match_expr(
24 expr: &ast::Expr,
25 pat1: &ast::Pat,
26 arm1: &ast::Block,
27 arm2: &ast::Block,
28) -> String {
29 let mut buf = String::new();
30 buf.push_str(&format!("match {} {{\n", expr.syntax().text()));
31 buf.push_str(&format!(
32 " {} => {}\n",
33 pat1.syntax().text(),
34 format_arm(arm1)
35 ));
36 buf.push_str(&format!(" _ => {}\n", format_arm(arm2)));
37 buf.push_str("}");
38 buf
39}
40
41fn format_arm(block: &ast::Block) -> String {
42 match extract_expression(block) {
43 None => block.syntax().text().to_string(),
44 Some(e) => format!("{},", e.syntax().text()),
45 }
46}
47
48fn extract_expression(block: &ast::Block) -> Option<&ast::Expr> {
49 let expr = block.expr()?;
50 let non_trivial_children = block.syntax().children().filter(|it| {
51 !(it == &expr.syntax()
52 || it.kind() == L_CURLY
53 || it.kind() == R_CURLY
54 || it.kind() == WHITESPACE)
55 });
56 if non_trivial_children.count() > 0 {
57 return None;
58 }
59 Some(expr)
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65 use crate::assists::check_assist;
66
67 #[test]
68 fn test_replace_if_let_with_match_unwraps_simple_expressions() {
69 check_assist(
70 replace_if_let_with_match,
71 "
72impl VariantData {
73 pub fn is_struct(&self) -> bool {
74 if <|>let VariantData::Struct(..) = *self {
75 true
76 } else {
77 false
78 }
79 }
80} ",
81 "
82impl VariantData {
83 pub fn is_struct(&self) -> bool {
84 <|>match *self {
85 VariantData::Struct(..) => true,
86 _ => false,
87 }
88 }
89} ",
90 )
91 }
92}
diff --git a/crates/ra_editor/src/diagnostics.rs b/crates/ra_editor/src/diagnostics.rs
index 199b0e502..2b695dfdf 100644
--- a/crates/ra_editor/src/diagnostics.rs
+++ b/crates/ra_editor/src/diagnostics.rs
@@ -1,25 +1,15 @@
1use itertools::Itertools; 1use itertools::Itertools;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 Location, SourceFile, SyntaxKind, TextRange, SyntaxNode,
4 ast::{self, AstNode}, 5 ast::{self, AstNode},
5 Location,
6 SourceFileNode,
7 SyntaxKind,
8 TextRange,
9};
10use ra_syntax::SyntaxNodeRef;
11use ra_text_edit::{
12 TextEdit,
13 TextEditBuilder,
14};
15 6
16use crate::{
17 Diagnostic,
18 LocalEdit,
19 Severity,
20}; 7};
8use ra_text_edit::{TextEdit, TextEditBuilder};
9
10use crate::{Diagnostic, LocalEdit, Severity};
21 11
22pub fn diagnostics(file: &SourceFileNode) -> Vec<Diagnostic> { 12pub fn diagnostics(file: &SourceFile) -> Vec<Diagnostic> {
23 fn location_to_range(location: Location) -> TextRange { 13 fn location_to_range(location: Location) -> TextRange {
24 match location { 14 match location {
25 Location::Offset(offset) => TextRange::offset_len(offset, 1.into()), 15 Location::Offset(offset) => TextRange::offset_len(offset, 1.into()),
@@ -48,7 +38,7 @@ pub fn diagnostics(file: &SourceFileNode) -> Vec<Diagnostic> {
48 38
49fn check_unnecessary_braces_in_use_statement( 39fn check_unnecessary_braces_in_use_statement(
50 acc: &mut Vec<Diagnostic>, 40 acc: &mut Vec<Diagnostic>,
51 node: SyntaxNodeRef, 41 node: &SyntaxNode,
52) -> Option<()> { 42) -> Option<()> {
53 let use_tree_list = ast::UseTreeList::cast(node)?; 43 let use_tree_list = ast::UseTreeList::cast(node)?;
54 if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() { 44 if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() {
@@ -79,7 +69,7 @@ fn check_unnecessary_braces_in_use_statement(
79} 69}
80 70
81fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( 71fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
82 single_use_tree: ast::UseTree, 72 single_use_tree: &ast::UseTree,
83) -> Option<TextEdit> { 73) -> Option<TextEdit> {
84 let use_tree_list_node = single_use_tree.syntax().parent()?; 74 let use_tree_list_node = single_use_tree.syntax().parent()?;
85 if single_use_tree 75 if single_use_tree
@@ -102,7 +92,7 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
102 92
103fn check_struct_shorthand_initialization( 93fn check_struct_shorthand_initialization(
104 acc: &mut Vec<Diagnostic>, 94 acc: &mut Vec<Diagnostic>,
105 node: SyntaxNodeRef, 95 node: &SyntaxNode,
106) -> Option<()> { 96) -> Option<()> {
107 let struct_lit = ast::StructLit::cast(node)?; 97 let struct_lit = ast::StructLit::cast(node)?;
108 let named_field_list = struct_lit.named_field_list()?; 98 let named_field_list = struct_lit.named_field_list()?;
@@ -138,10 +128,10 @@ mod tests {
138 128
139 use super::*; 129 use super::*;
140 130
141 type DiagnosticChecker = fn(&mut Vec<Diagnostic>, SyntaxNodeRef) -> Option<()>; 131 type DiagnosticChecker = fn(&mut Vec<Diagnostic>, &SyntaxNode) -> Option<()>;
142 132
143 fn check_not_applicable(code: &str, func: DiagnosticChecker) { 133 fn check_not_applicable(code: &str, func: DiagnosticChecker) {
144 let file = SourceFileNode::parse(code); 134 let file = SourceFile::parse(code);
145 let mut diagnostics = Vec::new(); 135 let mut diagnostics = Vec::new();
146 for node in file.syntax().descendants() { 136 for node in file.syntax().descendants() {
147 func(&mut diagnostics, node); 137 func(&mut diagnostics, node);
@@ -150,7 +140,7 @@ mod tests {
150 } 140 }
151 141
152 fn check_apply(before: &str, after: &str, func: DiagnosticChecker) { 142 fn check_apply(before: &str, after: &str, func: DiagnosticChecker) {
153 let file = SourceFileNode::parse(before); 143 let file = SourceFile::parse(before);
154 let mut diagnostics = Vec::new(); 144 let mut diagnostics = Vec::new();
155 for node in file.syntax().descendants() { 145 for node in file.syntax().descendants() {
156 func(&mut diagnostics, node); 146 func(&mut diagnostics, node);
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs
index 7a423852b..08cae5a51 100644
--- a/crates/ra_editor/src/extend_selection.rs
+++ b/crates/ra_editor/src/extend_selection.rs
@@ -1,11 +1,10 @@
1use ra_syntax::{ 1use ra_syntax::{
2 Direction, SyntaxNode, TextRange, TextUnit,
2 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset}, 3 algo::{find_covering_node, find_leaf_at_offset, LeafAtOffset},
3 Direction,
4 SyntaxKind::*, 4 SyntaxKind::*,
5 SyntaxNodeRef, TextRange, TextUnit,
6}; 5};
7 6
8pub fn extend_selection(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange> { 7pub fn extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange> {
9 let string_kinds = [COMMENT, STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; 8 let string_kinds = [COMMENT, STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING];
10 if range.is_empty() { 9 if range.is_empty() {
11 let offset = range.start(); 10 let offset = range.start();
@@ -40,7 +39,7 @@ pub fn extend_selection(root: SyntaxNodeRef, range: TextRange) -> Option<TextRan
40} 39}
41 40
42fn extend_single_word_in_comment_or_string( 41fn extend_single_word_in_comment_or_string(
43 leaf: SyntaxNodeRef, 42 leaf: &SyntaxNode,
44 offset: TextUnit, 43 offset: TextUnit,
45) -> Option<TextRange> { 44) -> Option<TextRange> {
46 let text: &str = leaf.leaf_text()?; 45 let text: &str = leaf.leaf_text()?;
@@ -66,7 +65,7 @@ fn extend_single_word_in_comment_or_string(
66 } 65 }
67} 66}
68 67
69fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange { 68fn extend_ws(root: &SyntaxNode, ws: &SyntaxNode, offset: TextUnit) -> TextRange {
70 let ws_text = ws.leaf_text().unwrap(); 69 let ws_text = ws.leaf_text().unwrap();
71 let suffix = TextRange::from_to(offset, ws.range().end()) - ws.range().start(); 70 let suffix = TextRange::from_to(offset, ws.range().end()) - ws.range().start();
72 let prefix = TextRange::from_to(ws.range().start(), offset) - ws.range().start(); 71 let prefix = TextRange::from_to(ws.range().start(), offset) - ws.range().start();
@@ -89,9 +88,9 @@ fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRa
89 ws.range() 88 ws.range()
90} 89}
91 90
92fn pick_best<'a>(l: SyntaxNodeRef<'a>, r: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a> { 91fn pick_best<'a>(l: &'a SyntaxNode, r: &'a SyntaxNode) -> &'a SyntaxNode {
93 return if priority(r) > priority(l) { r } else { l }; 92 return if priority(r) > priority(l) { r } else { l };
94 fn priority(n: SyntaxNodeRef) -> usize { 93 fn priority(n: &SyntaxNode) -> usize {
95 match n.kind() { 94 match n.kind() {
96 WHITESPACE => 0, 95 WHITESPACE => 0,
97 IDENT | SELF_KW | SUPER_KW | CRATE_KW | LIFETIME => 2, 96 IDENT | SELF_KW | SUPER_KW | CRATE_KW | LIFETIME => 2,
@@ -100,7 +99,7 @@ fn pick_best<'a>(l: SyntaxNodeRef<'a>, r: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a
100 } 99 }
101} 100}
102 101
103fn extend_comments(node: SyntaxNodeRef) -> Option<TextRange> { 102fn extend_comments(node: &SyntaxNode) -> Option<TextRange> {
104 let prev = adj_comments(node, Direction::Prev); 103 let prev = adj_comments(node, Direction::Prev);
105 let next = adj_comments(node, Direction::Next); 104 let next = adj_comments(node, Direction::Next);
106 if prev != next { 105 if prev != next {
@@ -110,7 +109,7 @@ fn extend_comments(node: SyntaxNodeRef) -> Option<TextRange> {
110 } 109 }
111} 110}
112 111
113fn adj_comments(node: SyntaxNodeRef, dir: Direction) -> SyntaxNodeRef { 112fn adj_comments(node: &SyntaxNode, dir: Direction) -> &SyntaxNode {
114 let mut res = node; 113 let mut res = node;
115 for node in node.siblings(dir) { 114 for node in node.siblings(dir) {
116 match node.kind() { 115 match node.kind() {
@@ -124,13 +123,14 @@ fn adj_comments(node: SyntaxNodeRef, dir: Direction) -> SyntaxNodeRef {
124 123
125#[cfg(test)] 124#[cfg(test)]
126mod tests { 125mod tests {
127 use super::*; 126 use ra_syntax::{SourceFile, AstNode};
128 use ra_syntax::SourceFileNode;
129 use test_utils::extract_offset; 127 use test_utils::extract_offset;
130 128
129 use super::*;
130
131 fn do_check(before: &str, afters: &[&str]) { 131 fn do_check(before: &str, afters: &[&str]) {
132 let (cursor, before) = extract_offset(before); 132 let (cursor, before) = extract_offset(before);
133 let file = SourceFileNode::parse(&before); 133 let file = SourceFile::parse(&before);
134 let mut range = TextRange::offset_len(cursor, 0.into()); 134 let mut range = TextRange::offset_len(cursor, 0.into());
135 for &after in afters { 135 for &after in afters {
136 range = extend_selection(file.syntax(), range).unwrap(); 136 range = extend_selection(file.syntax(), range).unwrap();
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs
index da542ecf0..6f3106889 100644
--- a/crates/ra_editor/src/folding_ranges.rs
+++ b/crates/ra_editor/src/folding_ranges.rs
@@ -1,9 +1,8 @@
1use rustc_hash::FxHashSet; 1use rustc_hash::FxHashSet;
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 ast, AstNode, Direction, SourceFileNode, 4 ast, AstNode, Direction, SourceFile, SyntaxNode, TextRange,
5 SyntaxKind::{self, *}, 5 SyntaxKind::{self, *},
6 SyntaxNodeRef, TextRange,
7}; 6};
8 7
9#[derive(Debug, PartialEq, Eq)] 8#[derive(Debug, PartialEq, Eq)]
@@ -19,7 +18,7 @@ pub struct Fold {
19 pub kind: FoldKind, 18 pub kind: FoldKind,
20} 19}
21 20
22pub fn folding_ranges(file: &SourceFileNode) -> Vec<Fold> { 21pub fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
23 let mut res = vec![]; 22 let mut res = vec![];
24 let mut visited_comments = FxHashSet::default(); 23 let mut visited_comments = FxHashSet::default();
25 let mut visited_imports = FxHashSet::default(); 24 let mut visited_imports = FxHashSet::default();
@@ -69,7 +68,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
69 } 68 }
70} 69}
71 70
72fn has_newline(node: SyntaxNodeRef) -> bool { 71fn has_newline(node: &SyntaxNode) -> bool {
73 for descendant in node.descendants() { 72 for descendant in node.descendants() {
74 if let Some(ws) = ast::Whitespace::cast(descendant) { 73 if let Some(ws) = ast::Whitespace::cast(descendant) {
75 if ws.has_newlines() { 74 if ws.has_newlines() {
@@ -86,8 +85,8 @@ fn has_newline(node: SyntaxNodeRef) -> bool {
86} 85}
87 86
88fn contiguous_range_for_group<'a>( 87fn contiguous_range_for_group<'a>(
89 first: SyntaxNodeRef<'a>, 88 first: &'a SyntaxNode,
90 visited: &mut FxHashSet<SyntaxNodeRef<'a>>, 89 visited: &mut FxHashSet<&'a SyntaxNode>,
91) -> Option<TextRange> { 90) -> Option<TextRange> {
92 visited.insert(first); 91 visited.insert(first);
93 92
@@ -124,8 +123,8 @@ fn contiguous_range_for_group<'a>(
124} 123}
125 124
126fn contiguous_range_for_comment<'a>( 125fn contiguous_range_for_comment<'a>(
127 first: SyntaxNodeRef<'a>, 126 first: &'a SyntaxNode,
128 visited: &mut FxHashSet<SyntaxNodeRef<'a>>, 127 visited: &mut FxHashSet<&'a SyntaxNode>,
129) -> Option<TextRange> { 128) -> Option<TextRange> {
130 visited.insert(first); 129 visited.insert(first);
131 130
@@ -174,7 +173,7 @@ mod tests {
174 173
175 fn do_check(text: &str, fold_kinds: &[FoldKind]) { 174 fn do_check(text: &str, fold_kinds: &[FoldKind]) {
176 let (ranges, text) = extract_ranges(text, "fold"); 175 let (ranges, text) = extract_ranges(text, "fold");
177 let file = SourceFileNode::parse(&text); 176 let file = SourceFile::parse(&text);
178 let folds = folding_ranges(&file); 177 let folds = folding_ranges(&file);
179 178
180 assert_eq!( 179 assert_eq!(
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs
index a3c85ed5d..6731260a3 100644
--- a/crates/ra_editor/src/lib.rs
+++ b/crates/ra_editor/src/lib.rs
@@ -21,11 +21,10 @@ pub use self::{
21}; 21};
22use ra_text_edit::TextEditBuilder; 22use ra_text_edit::TextEditBuilder;
23use ra_syntax::{ 23use ra_syntax::{
24 algo::find_leaf_at_offset, 24 SourceFile, SyntaxNode, TextRange, TextUnit, Direction,
25 ast::{self, AstNode},
26 SourceFileNode,
27 SyntaxKind::{self, *}, 25 SyntaxKind::{self, *},
28 SyntaxNodeRef, TextRange, TextUnit, Direction, 26 ast::{self, AstNode},
27 algo::find_leaf_at_offset,
29}; 28};
30use rustc_hash::FxHashSet; 29use rustc_hash::FxHashSet;
31 30
@@ -49,7 +48,7 @@ pub struct Diagnostic {
49 pub fix: Option<LocalEdit>, 48 pub fix: Option<LocalEdit>,
50} 49}
51 50
52pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> { 51pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> {
53 const BRACES: &[SyntaxKind] = &[ 52 const BRACES: &[SyntaxKind] = &[
54 L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE, 53 L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE,
55 ]; 54 ];
@@ -67,7 +66,7 @@ pub fn matching_brace(file: &SourceFileNode, offset: TextUnit) -> Option<TextUni
67 Some(matching_node.range().start()) 66 Some(matching_node.range().start())
68} 67}
69 68
70pub fn highlight(root: SyntaxNodeRef) -> Vec<HighlightedRange> { 69pub fn highlight(root: &SyntaxNode) -> Vec<HighlightedRange> {
71 // Visited nodes to handle highlighting priorities 70 // Visited nodes to handle highlighting priorities
72 let mut highlighted = FxHashSet::default(); 71 let mut highlighted = FxHashSet::default();
73 let mut res = Vec::new(); 72 let mut res = Vec::new();
@@ -117,26 +116,25 @@ pub fn highlight(root: SyntaxNodeRef) -> Vec<HighlightedRange> {
117 res 116 res
118} 117}
119 118
120pub fn syntax_tree(file: &SourceFileNode) -> String { 119pub fn syntax_tree(file: &SourceFile) -> String {
121 ::ra_syntax::utils::dump_tree(file.syntax()) 120 ::ra_syntax::utils::dump_tree(file.syntax())
122} 121}
123 122
124pub fn find_node_at_offset<'a, N: AstNode<'a>>( 123pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> {
125 syntax: SyntaxNodeRef<'a>,
126 offset: TextUnit,
127) -> Option<N> {
128 find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast)) 124 find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast))
129} 125}
130 126
131#[cfg(test)] 127#[cfg(test)]
132mod tests { 128mod tests {
129 use ra_syntax::AstNode;
130
133 use crate::test_utils::{add_cursor, assert_eq_dbg, assert_eq_text, extract_offset}; 131 use crate::test_utils::{add_cursor, assert_eq_dbg, assert_eq_text, extract_offset};
134 132
135 use super::*; 133 use super::*;
136 134
137 #[test] 135 #[test]
138 fn test_highlighting() { 136 fn test_highlighting() {
139 let file = SourceFileNode::parse( 137 let file = SourceFile::parse(
140 r#" 138 r#"
141// comment 139// comment
142fn main() {} 140fn main() {}
@@ -159,7 +157,7 @@ fn main() {}
159 fn test_matching_brace() { 157 fn test_matching_brace() {
160 fn do_check(before: &str, after: &str) { 158 fn do_check(before: &str, after: &str) {
161 let (pos, before) = extract_offset(before); 159 let (pos, before) = extract_offset(before);
162 let file = SourceFileNode::parse(&before); 160 let file = SourceFile::parse(&before);
163 let new_pos = match matching_brace(&file, pos) { 161 let new_pos = match matching_brace(&file, pos) {
164 None => pos, 162 None => pos,
165 Some(pos) => pos, 163 Some(pos) => pos,
diff --git a/crates/ra_editor/src/structure.rs b/crates/ra_editor/src/structure.rs
index 32d59e335..8bd57555f 100644
--- a/crates/ra_editor/src/structure.rs
+++ b/crates/ra_editor/src/structure.rs
@@ -3,7 +3,7 @@ use crate::TextRange;
3use ra_syntax::{ 3use ra_syntax::{
4 algo::visit::{visitor, Visitor}, 4 algo::visit::{visitor, Visitor},
5 ast::{self, NameOwner}, 5 ast::{self, NameOwner},
6 AstNode, SourceFileNode, SyntaxKind, SyntaxNodeRef, WalkEvent, 6 AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent,
7}; 7};
8 8
9#[derive(Debug, Clone)] 9#[derive(Debug, Clone)]
@@ -15,7 +15,7 @@ pub struct StructureNode {
15 pub kind: SyntaxKind, 15 pub kind: SyntaxKind,
16} 16}
17 17
18pub fn file_structure(file: &SourceFileNode) -> Vec<StructureNode> { 18pub fn file_structure(file: &SourceFile) -> Vec<StructureNode> {
19 let mut res = Vec::new(); 19 let mut res = Vec::new();
20 let mut stack = Vec::new(); 20 let mut stack = Vec::new();
21 21
@@ -38,8 +38,8 @@ pub fn file_structure(file: &SourceFileNode) -> Vec<StructureNode> {
38 res 38 res
39} 39}
40 40
41fn structure_node(node: SyntaxNodeRef) -> Option<StructureNode> { 41fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
42 fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<StructureNode> { 42 fn decl<N: NameOwner>(node: &N) -> Option<StructureNode> {
43 let name = node.name()?; 43 let name = node.name()?;
44 Some(StructureNode { 44 Some(StructureNode {
45 parent: None, 45 parent: None,
@@ -60,7 +60,7 @@ fn structure_node(node: SyntaxNodeRef) -> Option<StructureNode> {
60 .visit(decl::<ast::TypeDef>) 60 .visit(decl::<ast::TypeDef>)
61 .visit(decl::<ast::ConstDef>) 61 .visit(decl::<ast::ConstDef>)
62 .visit(decl::<ast::StaticDef>) 62 .visit(decl::<ast::StaticDef>)
63 .visit(|im: ast::ImplBlock| { 63 .visit(|im: &ast::ImplBlock| {
64 let target_type = im.target_type()?; 64 let target_type = im.target_type()?;
65 let target_trait = im.target_trait(); 65 let target_trait = im.target_trait();
66 let label = match target_trait { 66 let label = match target_trait {
@@ -91,7 +91,7 @@ mod tests {
91 91
92 #[test] 92 #[test]
93 fn test_file_structure() { 93 fn test_file_structure() {
94 let file = SourceFileNode::parse( 94 let file = SourceFile::parse(
95 r#" 95 r#"
96struct Foo { 96struct Foo {
97 x: i32 97 x: i32
diff --git a/crates/ra_editor/src/test_utils.rs b/crates/ra_editor/src/test_utils.rs
index f0a4f250a..dc2470aa3 100644
--- a/crates/ra_editor/src/test_utils.rs
+++ b/crates/ra_editor/src/test_utils.rs
@@ -1,32 +1,35 @@
1use ra_syntax::{SourceFileNode, TextRange, TextUnit}; 1use ra_syntax::{SourceFile, TextRange, TextUnit};
2 2
3use crate::LocalEdit; 3use crate::LocalEdit;
4pub use test_utils::*; 4pub use test_utils::*;
5 5
6pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>( 6pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<LocalEdit>>(
7 before: &str, 7 before: &str,
8 after: &str, 8 after: &str,
9 f: F, 9 f: F,
10) { 10) {
11 let (before_cursor_pos, before) = extract_offset(before); 11 let (before_cursor_pos, before) = extract_offset(before);
12 let file = SourceFileNode::parse(&before); 12 let file = SourceFile::parse(&before);
13 let result = f(&file, before_cursor_pos).expect("code action is not applicable"); 13 let result = f(&file, before_cursor_pos).expect("code action is not applicable");
14 let actual = result.edit.apply(&before); 14 let actual = result.edit.apply(&before);
15 let actual_cursor_pos = match result.cursor_position { 15 let actual_cursor_pos = match result.cursor_position {
16 None => result.edit.apply_to_offset(before_cursor_pos).unwrap(), 16 None => result
17 .edit
18 .apply_to_offset(before_cursor_pos)
19 .expect("cursor position is affected by the edit"),
17 Some(off) => off, 20 Some(off) => off,
18 }; 21 };
19 let actual = add_cursor(&actual, actual_cursor_pos); 22 let actual = add_cursor(&actual, actual_cursor_pos);
20 assert_eq_text!(after, &actual); 23 assert_eq_text!(after, &actual);
21} 24}
22 25
23pub fn check_action_range<F: Fn(&SourceFileNode, TextRange) -> Option<LocalEdit>>( 26pub fn check_action_range<F: Fn(&SourceFile, TextRange) -> Option<LocalEdit>>(
24 before: &str, 27 before: &str,
25 after: &str, 28 after: &str,
26 f: F, 29 f: F,
27) { 30) {
28 let (range, before) = extract_range(before); 31 let (range, before) = extract_range(before);
29 let file = SourceFileNode::parse(&before); 32 let file = SourceFile::parse(&before);
30 let result = f(&file, range).expect("code action is not applicable"); 33 let result = f(&file, range).expect("code action is not applicable");
31 let actual = result.edit.apply(&before); 34 let actual = result.edit.apply(&before);
32 let actual_cursor_pos = match result.cursor_position { 35 let actual_cursor_pos = match result.cursor_position {
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};
12use ra_text_edit::text_utils::contains_offset_nonstrict; 12use ra_text_edit::text_utils::contains_offset_nonstrict;
13 13
14use crate::{find_node_at_offset, LocalEdit, TextEditBuilder}; 14use crate::{find_node_at_offset, LocalEdit, TextEditBuilder};
15 15
16pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { 16pub 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
62pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { 62pub 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
88fn node_indent<'a>(file: &'a SourceFileNode, node: SyntaxNodeRef) -> Option<&'a str> { 88fn 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
108pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { 108pub 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
139pub fn on_dot_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { 139pub 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
189fn remove_newline( 189fn 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
269fn join_single_expr_block(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> { 269fn 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
280fn single_expr(block: ast::Block) -> Option<ast::Expr> { 280fn 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
300fn join_single_use_tree(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> { 300fn 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
310fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str { 310fn 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());