aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/call_info.rs2
-rw-r--r--crates/ra_ide/src/completion/complete_keyword.rs2
-rw-r--r--crates/ra_ide/src/completion/complete_postfix.rs6
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs8
-rw-r--r--crates/ra_ide/src/completion/completion_context.rs13
-rw-r--r--crates/ra_ide/src/diagnostics.rs2
-rw-r--r--crates/ra_ide/src/extend_selection.rs42
-rw-r--r--crates/ra_ide/src/folding_ranges.rs4
-rw-r--r--crates/ra_ide/src/hover.rs2
-rw-r--r--crates/ra_ide/src/join_lines.rs38
-rw-r--r--crates/ra_ide/src/lib.rs4
-rw-r--r--crates/ra_ide/src/matching_brace.rs4
-rw-r--r--crates/ra_ide/src/references/rename.rs4
-rw-r--r--crates/ra_ide/src/source_change.rs4
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs12
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs11
-rw-r--r--crates/ra_ide/src/syntax_tree.rs8
-rw-r--r--crates/ra_ide/src/test_utils.rs4
-rw-r--r--crates/ra_ide/src/typing.rs20
-rw-r--r--crates/ra_ide/src/typing/on_enter.rs6
20 files changed, 96 insertions, 100 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index 5da254a6e..780a03c13 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -126,7 +126,7 @@ impl FnCallNode {
126 ast::CallExpr(it) => Some(FnCallNode::CallExpr(it)), 126 ast::CallExpr(it) => Some(FnCallNode::CallExpr(it)),
127 ast::MethodCallExpr(it) => { 127 ast::MethodCallExpr(it) => {
128 let arg_list = it.arg_list()?; 128 let arg_list = it.arg_list()?;
129 if !syntax.text_range().is_subrange(&arg_list.syntax().text_range()) { 129 if !arg_list.syntax().text_range().contains_range(syntax.text_range()) {
130 return None; 130 return None;
131 } 131 }
132 Some(FnCallNode::MethodCallExpr(it)) 132 Some(FnCallNode::MethodCallExpr(it))
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs
index adefb290e..306ce96dc 100644
--- a/crates/ra_ide/src/completion/complete_keyword.rs
+++ b/crates/ra_ide/src/completion/complete_keyword.rs
@@ -97,7 +97,7 @@ fn is_in_loop_body(leaf: &SyntaxToken) -> bool {
97 } 97 }
98 }; 98 };
99 if let Some(body) = loop_body { 99 if let Some(body) = loop_body {
100 if leaf.text_range().is_subrange(&body.syntax().text_range()) { 100 if body.syntax().text_range().contains_range(leaf.text_range()) {
101 return true; 101 return true;
102 } 102 }
103 } 103 }
diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs
index 8d397b0fe..d6a37d720 100644
--- a/crates/ra_ide/src/completion/complete_postfix.rs
+++ b/crates/ra_ide/src/completion/complete_postfix.rs
@@ -2,7 +2,7 @@
2 2
3use ra_syntax::{ 3use ra_syntax::{
4 ast::{self, AstNode}, 4 ast::{self, AstNode},
5 TextRange, TextUnit, 5 TextRange, TextSize,
6}; 6};
7use ra_text_edit::TextEdit; 7use ra_text_edit::TextEdit;
8 8
@@ -115,7 +115,7 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
115fn get_receiver_text(receiver: &ast::Expr, receiver_is_ambiguous_float_literal: bool) -> String { 115fn get_receiver_text(receiver: &ast::Expr, receiver_is_ambiguous_float_literal: bool) -> String {
116 if receiver_is_ambiguous_float_literal { 116 if receiver_is_ambiguous_float_literal {
117 let text = receiver.syntax().text(); 117 let text = receiver.syntax().text();
118 let without_dot = ..text.len() - TextUnit::of_char('.'); 118 let without_dot = ..text.len() - TextSize::of('.');
119 text.slice(without_dot).to_string() 119 text.slice(without_dot).to_string()
120 } else { 120 } else {
121 receiver.to_string() 121 receiver.to_string()
@@ -143,7 +143,7 @@ fn postfix_snippet(
143 let edit = { 143 let edit = {
144 let receiver_syntax = receiver.syntax(); 144 let receiver_syntax = receiver.syntax();
145 let receiver_range = ctx.sema.original_range(receiver_syntax).range; 145 let receiver_range = ctx.sema.original_range(receiver_syntax).range;
146 let delete_range = TextRange::from_to(receiver_range.start(), ctx.source_range().end()); 146 let delete_range = TextRange::new(receiver_range.start(), ctx.source_range().end());
147 TextEdit::replace(delete_range, snippet.to_string()) 147 TextEdit::replace(delete_range, snippet.to_string())
148 }; 148 };
149 CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label) 149 CompletionItem::new(CompletionKind::Postfix, ctx.source_range(), label)
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index c39943252..e2a8c59cd 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -141,7 +141,7 @@ fn add_function_impl(
141 } else { 141 } else {
142 CompletionItemKind::Function 142 CompletionItemKind::Function
143 }; 143 };
144 let range = TextRange::from_to(fn_def_node.text_range().start(), ctx.source_range().end()); 144 let range = TextRange::new(fn_def_node.text_range().start(), ctx.source_range().end());
145 145
146 match ctx.config.snippet_cap { 146 match ctx.config.snippet_cap {
147 Some(cap) => { 147 Some(cap) => {
@@ -167,7 +167,7 @@ fn add_type_alias_impl(
167 167
168 let snippet = format!("type {} = ", alias_name); 168 let snippet = format!("type {} = ", alias_name);
169 169
170 let range = TextRange::from_to(type_def_node.text_range().start(), ctx.source_range().end()); 170 let range = TextRange::new(type_def_node.text_range().start(), ctx.source_range().end());
171 171
172 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()) 172 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
173 .text_edit(TextEdit::replace(range, snippet)) 173 .text_edit(TextEdit::replace(range, snippet))
@@ -189,7 +189,7 @@ fn add_const_impl(
189 let snippet = make_const_compl_syntax(&const_.source(ctx.db).value); 189 let snippet = make_const_compl_syntax(&const_.source(ctx.db).value);
190 190
191 let range = 191 let range =
192 TextRange::from_to(const_def_node.text_range().start(), ctx.source_range().end()); 192 TextRange::new(const_def_node.text_range().start(), ctx.source_range().end());
193 193
194 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone()) 194 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
195 .text_edit(TextEdit::replace(range, snippet)) 195 .text_edit(TextEdit::replace(range, snippet))
@@ -216,7 +216,7 @@ fn make_const_compl_syntax(const_: &ast::ConstDef) -> String {
216 .map_or(const_end, |f| f.text_range().start()); 216 .map_or(const_end, |f| f.text_range().start());
217 217
218 let len = end - start; 218 let len = end - start;
219 let range = TextRange::from_to(0.into(), len); 219 let range = TextRange::new(0.into(), len);
220 220
221 let syntax = const_.syntax().text().slice(range).to_string(); 221 let syntax = const_.syntax().text().slice(range).to_string();
222 222
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index 37880448a..5f2797e41 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -7,7 +7,7 @@ use ra_syntax::{
7 algo::{find_covering_element, find_node_at_offset}, 7 algo::{find_covering_element, find_node_at_offset},
8 ast, AstNode, 8 ast, AstNode,
9 SyntaxKind::*, 9 SyntaxKind::*,
10 SyntaxNode, SyntaxToken, TextRange, TextUnit, 10 SyntaxNode, SyntaxToken, TextRange, TextSize,
11}; 11};
12use ra_text_edit::AtomTextEdit; 12use ra_text_edit::AtomTextEdit;
13 13
@@ -20,7 +20,7 @@ pub(crate) struct CompletionContext<'a> {
20 pub(super) sema: Semantics<'a, RootDatabase>, 20 pub(super) sema: Semantics<'a, RootDatabase>,
21 pub(super) db: &'a RootDatabase, 21 pub(super) db: &'a RootDatabase,
22 pub(super) config: &'a CompletionConfig, 22 pub(super) config: &'a CompletionConfig,
23 pub(super) offset: TextUnit, 23 pub(super) offset: TextSize,
24 /// The token before the cursor, in the original file. 24 /// The token before the cursor, in the original file.
25 pub(super) original_token: SyntaxToken, 25 pub(super) original_token: SyntaxToken,
26 /// The token before the cursor, in the macro-expanded file. 26 /// The token before the cursor, in the macro-expanded file.
@@ -167,7 +167,7 @@ impl<'a> CompletionContext<'a> {
167 match self.token.kind() { 167 match self.token.kind() {
168 // workaroud when completion is triggered by trigger characters. 168 // workaroud when completion is triggered by trigger characters.
169 IDENT => self.original_token.text_range(), 169 IDENT => self.original_token.text_range(),
170 _ => TextRange::offset_len(self.offset, 0.into()), 170 _ => TextRange::empty(self.offset),
171 } 171 }
172 } 172 }
173 173
@@ -190,7 +190,7 @@ impl<'a> CompletionContext<'a> {
190 &mut self, 190 &mut self,
191 original_file: &SyntaxNode, 191 original_file: &SyntaxNode,
192 file_with_fake_ident: SyntaxNode, 192 file_with_fake_ident: SyntaxNode,
193 offset: TextUnit, 193 offset: TextSize,
194 ) { 194 ) {
195 // First, let's try to complete a reference to some declaration. 195 // First, let's try to complete a reference to some declaration.
196 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&file_with_fake_ident, offset) { 196 if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&file_with_fake_ident, offset) {
@@ -224,7 +224,8 @@ impl<'a> CompletionContext<'a> {
224 } 224 }
225 if let Some(let_stmt) = bind_pat.syntax().ancestors().find_map(ast::LetStmt::cast) { 225 if let Some(let_stmt) = bind_pat.syntax().ancestors().find_map(ast::LetStmt::cast) {
226 if let Some(pat) = let_stmt.pat() { 226 if let Some(pat) = let_stmt.pat() {
227 if bind_pat.syntax().text_range().is_subrange(&pat.syntax().text_range()) { 227 if pat.syntax().text_range().contains_range(bind_pat.syntax().text_range())
228 {
228 self.is_pat_binding_or_const = false; 229 self.is_pat_binding_or_const = false;
229 } 230 }
230 } 231 }
@@ -246,7 +247,7 @@ impl<'a> CompletionContext<'a> {
246 &mut self, 247 &mut self,
247 original_file: &SyntaxNode, 248 original_file: &SyntaxNode,
248 name_ref: ast::NameRef, 249 name_ref: ast::NameRef,
249 offset: TextUnit, 250 offset: TextSize,
250 ) { 251 ) {
251 self.name_ref_syntax = 252 self.name_ref_syntax =
252 find_node_at_offset(&original_file, name_ref.syntax().text_range().start()); 253 find_node_at_offset(&original_file, name_ref.syntax().text_range().start());
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index e7e201709..adfb1b9b2 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -171,7 +171,7 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
171 if single_use_tree.path()?.segment()?.syntax().first_child_or_token()?.kind() == T![self] { 171 if single_use_tree.path()?.segment()?.syntax().first_child_or_token()?.kind() == T![self] {
172 let start = use_tree_list_node.prev_sibling_or_token()?.text_range().start(); 172 let start = use_tree_list_node.prev_sibling_or_token()?.text_range().start();
173 let end = use_tree_list_node.text_range().end(); 173 let end = use_tree_list_node.text_range().end();
174 let range = TextRange::from_to(start, end); 174 let range = TextRange::new(start, end);
175 return Some(TextEdit::delete(range)); 175 return Some(TextEdit::delete(range));
176 } 176 }
177 None 177 None
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index 753d2ef6a..9f329b5d3 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -9,7 +9,7 @@ use ra_syntax::{
9 ast::{self, AstNode, AstToken}, 9 ast::{self, AstNode, AstToken},
10 Direction, NodeOrToken, 10 Direction, NodeOrToken,
11 SyntaxKind::{self, *}, 11 SyntaxKind::{self, *},
12 SyntaxNode, SyntaxToken, TextRange, TextUnit, TokenAtOffset, T, 12 SyntaxNode, SyntaxToken, TextRange, TextSize, TokenAtOffset, T,
13}; 13};
14 14
15use crate::FileRange; 15use crate::FileRange;
@@ -121,10 +121,10 @@ fn extend_tokens_from_range(
121 let mut first_token = skip_trivia_token(first_token, Direction::Next)?; 121 let mut first_token = skip_trivia_token(first_token, Direction::Next)?;
122 let mut last_token = skip_trivia_token(last_token, Direction::Prev)?; 122 let mut last_token = skip_trivia_token(last_token, Direction::Prev)?;
123 123
124 while !first_token.text_range().is_subrange(&original_range) { 124 while !original_range.contains_range(first_token.text_range()) {
125 first_token = skip_trivia_token(first_token.next_token()?, Direction::Next)?; 125 first_token = skip_trivia_token(first_token.next_token()?, Direction::Next)?;
126 } 126 }
127 while !last_token.text_range().is_subrange(&original_range) { 127 while !original_range.contains_range(last_token.text_range()) {
128 last_token = skip_trivia_token(last_token.prev_token()?, Direction::Prev)?; 128 last_token = skip_trivia_token(last_token.prev_token()?, Direction::Prev)?;
129 } 129 }
130 130
@@ -161,8 +161,8 @@ fn extend_tokens_from_range(
161 .take_while(validate) 161 .take_while(validate)
162 .last()?; 162 .last()?;
163 163
164 let range = first.text_range().extend_to(&last.text_range()); 164 let range = first.text_range().cover(last.text_range());
165 if original_range.is_subrange(&range) && original_range != range { 165 if range.contains_range(original_range) && original_range != range {
166 Some(range) 166 Some(range)
167 } else { 167 } else {
168 None 168 None
@@ -176,7 +176,7 @@ fn shallowest_node(node: &SyntaxNode) -> SyntaxNode {
176 176
177fn extend_single_word_in_comment_or_string( 177fn extend_single_word_in_comment_or_string(
178 leaf: &SyntaxToken, 178 leaf: &SyntaxToken,
179 offset: TextUnit, 179 offset: TextSize,
180) -> Option<TextRange> { 180) -> Option<TextRange> {
181 let text: &str = leaf.text(); 181 let text: &str = leaf.text();
182 let cursor_position: u32 = (offset - leaf.text_range().start()).into(); 182 let cursor_position: u32 = (offset - leaf.text_range().start()).into();
@@ -190,10 +190,10 @@ fn extend_single_word_in_comment_or_string(
190 let start_idx = before.rfind(non_word_char)? as u32; 190 let start_idx = before.rfind(non_word_char)? as u32;
191 let end_idx = after.find(non_word_char).unwrap_or_else(|| after.len()) as u32; 191 let end_idx = after.find(non_word_char).unwrap_or_else(|| after.len()) as u32;
192 192
193 let from: TextUnit = (start_idx + 1).into(); 193 let from: TextSize = (start_idx + 1).into();
194 let to: TextUnit = (cursor_position + end_idx).into(); 194 let to: TextSize = (cursor_position + end_idx).into();
195 195
196 let range = TextRange::from_to(from, to); 196 let range = TextRange::new(from, to);
197 if range.is_empty() { 197 if range.is_empty() {
198 None 198 None
199 } else { 199 } else {
@@ -201,24 +201,24 @@ fn extend_single_word_in_comment_or_string(
201 } 201 }
202} 202}
203 203
204fn extend_ws(root: &SyntaxNode, ws: SyntaxToken, offset: TextUnit) -> TextRange { 204fn extend_ws(root: &SyntaxNode, ws: SyntaxToken, offset: TextSize) -> TextRange {
205 let ws_text = ws.text(); 205 let ws_text = ws.text();
206 let suffix = TextRange::from_to(offset, ws.text_range().end()) - ws.text_range().start(); 206 let suffix = TextRange::new(offset, ws.text_range().end()) - ws.text_range().start();
207 let prefix = TextRange::from_to(ws.text_range().start(), offset) - ws.text_range().start(); 207 let prefix = TextRange::new(ws.text_range().start(), offset) - ws.text_range().start();
208 let ws_suffix = &ws_text.as_str()[suffix]; 208 let ws_suffix = &ws_text.as_str()[suffix];
209 let ws_prefix = &ws_text.as_str()[prefix]; 209 let ws_prefix = &ws_text.as_str()[prefix];
210 if ws_text.contains('\n') && !ws_suffix.contains('\n') { 210 if ws_text.contains('\n') && !ws_suffix.contains('\n') {
211 if let Some(node) = ws.next_sibling_or_token() { 211 if let Some(node) = ws.next_sibling_or_token() {
212 let start = match ws_prefix.rfind('\n') { 212 let start = match ws_prefix.rfind('\n') {
213 Some(idx) => ws.text_range().start() + TextUnit::from((idx + 1) as u32), 213 Some(idx) => ws.text_range().start() + TextSize::from((idx + 1) as u32),
214 None => node.text_range().start(), 214 None => node.text_range().start(),
215 }; 215 };
216 let end = if root.text().char_at(node.text_range().end()) == Some('\n') { 216 let end = if root.text().char_at(node.text_range().end()) == Some('\n') {
217 node.text_range().end() + TextUnit::of_char('\n') 217 node.text_range().end() + TextSize::of('\n')
218 } else { 218 } else {
219 node.text_range().end() 219 node.text_range().end()
220 }; 220 };
221 return TextRange::from_to(start, end); 221 return TextRange::new(start, end);
222 } 222 }
223 } 223 }
224 ws.text_range() 224 ws.text_range()
@@ -270,13 +270,10 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
270 .filter(|node| is_single_line_ws(node)) 270 .filter(|node| is_single_line_ws(node))
271 .unwrap_or(delimiter_node); 271 .unwrap_or(delimiter_node);
272 272
273 return Some(TextRange::from_to(node.text_range().start(), final_node.text_range().end())); 273 return Some(TextRange::new(node.text_range().start(), final_node.text_range().end()));
274 } 274 }
275 if let Some(delimiter_node) = nearby_delimiter(delimiter, node, Direction::Prev) { 275 if let Some(delimiter_node) = nearby_delimiter(delimiter, node, Direction::Prev) {
276 return Some(TextRange::from_to( 276 return Some(TextRange::new(delimiter_node.text_range().start(), node.text_range().end()));
277 delimiter_node.text_range().start(),
278 node.text_range().end(),
279 ));
280 } 277 }
281 278
282 None 279 None
@@ -286,10 +283,7 @@ fn extend_comments(comment: ast::Comment) -> Option<TextRange> {
286 let prev = adj_comments(&comment, Direction::Prev); 283 let prev = adj_comments(&comment, Direction::Prev);
287 let next = adj_comments(&comment, Direction::Next); 284 let next = adj_comments(&comment, Direction::Next);
288 if prev != next { 285 if prev != next {
289 Some(TextRange::from_to( 286 Some(TextRange::new(prev.syntax().text_range().start(), next.syntax().text_range().end()))
290 prev.syntax().text_range().start(),
291 next.syntax().text_range().end(),
292 ))
293 } else { 287 } else {
294 None 288 None
295 } 289 }
diff --git a/crates/ra_ide/src/folding_ranges.rs b/crates/ra_ide/src/folding_ranges.rs
index 4eeb76d14..034c4c7d4 100644
--- a/crates/ra_ide/src/folding_ranges.rs
+++ b/crates/ra_ide/src/folding_ranges.rs
@@ -141,7 +141,7 @@ fn contiguous_range_for_group_unless(
141 } 141 }
142 142
143 if first != &last { 143 if first != &last {
144 Some(TextRange::from_to(first.text_range().start(), last.text_range().end())) 144 Some(TextRange::new(first.text_range().start(), last.text_range().end()))
145 } else { 145 } else {
146 // The group consists of only one element, therefore it cannot be folded 146 // The group consists of only one element, therefore it cannot be folded
147 None 147 None
@@ -187,7 +187,7 @@ fn contiguous_range_for_comment(
187 } 187 }
188 188
189 if first != last { 189 if first != last {
190 Some(TextRange::from_to( 190 Some(TextRange::new(
191 first.syntax().text_range().start(), 191 first.syntax().text_range().start(),
192 last.syntax().text_range().end(), 192 last.syntax().text_range().end(),
193 )) 193 ))
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index a31187994..fcc2ab7fb 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -275,7 +275,7 @@ mod tests {
275 ", 275 ",
276 ); 276 );
277 let hover = analysis.hover(position).unwrap().unwrap(); 277 let hover = analysis.hover(position).unwrap().unwrap();
278 assert_eq!(hover.range, TextRange::from_to(95.into(), 100.into())); 278 assert_eq!(hover.range, TextRange::new(95.into(), 100.into()));
279 assert_eq!(trim_markup_opt(hover.info.first()), Some("u32")); 279 assert_eq!(trim_markup_opt(hover.info.first()), Some("u32"));
280 } 280 }
281 281
diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs
index 7d70dab9c..040846ec3 100644
--- a/crates/ra_ide/src/join_lines.rs
+++ b/crates/ra_ide/src/join_lines.rs
@@ -7,7 +7,7 @@ use ra_syntax::{
7 ast::{self, AstNode, AstToken}, 7 ast::{self, AstNode, AstToken},
8 Direction, NodeOrToken, SourceFile, 8 Direction, NodeOrToken, SourceFile,
9 SyntaxKind::{self, WHITESPACE}, 9 SyntaxKind::{self, WHITESPACE},
10 SyntaxNode, SyntaxToken, TextRange, TextUnit, T, 10 SyntaxNode, SyntaxToken, TextRange, TextSize, T,
11}; 11};
12use ra_text_edit::{TextEdit, TextEditBuilder}; 12use ra_text_edit::{TextEdit, TextEditBuilder};
13 13
@@ -19,7 +19,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
19 None => return TextEditBuilder::default().finish(), 19 None => return TextEditBuilder::default().finish(),
20 Some(pos) => pos, 20 Some(pos) => pos,
21 }; 21 };
22 TextRange::offset_len(range.start() + pos, TextUnit::of_char('\n')) 22 TextRange::at(range.start() + pos, TextSize::of('\n'))
23 } else { 23 } else {
24 range 24 range
25 }; 25 };
@@ -30,13 +30,13 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
30 }; 30 };
31 let mut edit = TextEditBuilder::default(); 31 let mut edit = TextEditBuilder::default();
32 for token in node.descendants_with_tokens().filter_map(|it| it.into_token()) { 32 for token in node.descendants_with_tokens().filter_map(|it| it.into_token()) {
33 let range = match range.intersection(&token.text_range()) { 33 let range = match range.intersect(token.text_range()) {
34 Some(range) => range, 34 Some(range) => range,
35 None => continue, 35 None => continue,
36 } - token.text_range().start(); 36 } - token.text_range().start();
37 let text = token.text(); 37 let text = token.text();
38 for (pos, _) in text[range].bytes().enumerate().filter(|&(_, b)| b == b'\n') { 38 for (pos, _) in text[range].bytes().enumerate().filter(|&(_, b)| b == b'\n') {
39 let pos: TextUnit = (pos as u32).into(); 39 let pos: TextSize = (pos as u32).into();
40 let off = token.text_range().start() + range.start() + pos; 40 let off = token.text_range().start() + range.start() + pos;
41 if !edit.invalidates_offset(off) { 41 if !edit.invalidates_offset(off) {
42 remove_newline(&mut edit, &token, off); 42 remove_newline(&mut edit, &token, off);
@@ -47,16 +47,16 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
47 edit.finish() 47 edit.finish()
48} 48}
49 49
50fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextUnit) { 50fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextSize) {
51 if token.kind() != WHITESPACE || token.text().bytes().filter(|&b| b == b'\n').count() != 1 { 51 if token.kind() != WHITESPACE || token.text().bytes().filter(|&b| b == b'\n').count() != 1 {
52 // The node is either the first or the last in the file 52 // The node is either the first or the last in the file
53 let suff = &token.text()[TextRange::from_to( 53 let suff = &token.text()[TextRange::new(
54 offset - token.text_range().start() + TextUnit::of_char('\n'), 54 offset - token.text_range().start() + TextSize::of('\n'),
55 TextUnit::of_str(token.text()), 55 TextSize::of(token.text().as_str()),
56 )]; 56 )];
57 let spaces = suff.bytes().take_while(|&b| b == b' ').count(); 57 let spaces = suff.bytes().take_while(|&b| b == b' ').count();
58 58
59 edit.replace(TextRange::offset_len(offset, ((spaces + 1) as u32).into()), " ".to_string()); 59 edit.replace(TextRange::at(offset, ((spaces + 1) as u32).into()), " ".to_string());
60 return; 60 return;
61 } 61 }
62 62
@@ -65,7 +65,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
65 let next = token.next_sibling_or_token().unwrap(); 65 let next = token.next_sibling_or_token().unwrap();
66 if is_trailing_comma(prev.kind(), next.kind()) { 66 if is_trailing_comma(prev.kind(), next.kind()) {
67 // Removes: trailing comma, newline (incl. surrounding whitespace) 67 // Removes: trailing comma, newline (incl. surrounding whitespace)
68 edit.delete(TextRange::from_to(prev.text_range().start(), token.text_range().end())); 68 edit.delete(TextRange::new(prev.text_range().start(), token.text_range().end()));
69 return; 69 return;
70 } 70 }
71 if prev.kind() == T![,] && next.kind() == T!['}'] { 71 if prev.kind() == T![,] && next.kind() == T!['}'] {
@@ -76,7 +76,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
76 " " 76 " "
77 }; 77 };
78 edit.replace( 78 edit.replace(
79 TextRange::from_to(prev.text_range().start(), token.text_range().end()), 79 TextRange::new(prev.text_range().start(), token.text_range().end()),
80 space.to_string(), 80 space.to_string(),
81 ); 81 );
82 return; 82 return;
@@ -87,9 +87,9 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
87 next.as_token().cloned().and_then(ast::Comment::cast), 87 next.as_token().cloned().and_then(ast::Comment::cast),
88 ) { 88 ) {
89 // Removes: newline (incl. surrounding whitespace), start of the next comment 89 // Removes: newline (incl. surrounding whitespace), start of the next comment
90 edit.delete(TextRange::from_to( 90 edit.delete(TextRange::new(
91 token.text_range().start(), 91 token.text_range().start(),
92 next.syntax().text_range().start() + TextUnit::of_str(next.prefix()), 92 next.syntax().text_range().start() + TextSize::of(next.prefix()),
93 )); 93 ));
94 return; 94 return;
95 } 95 }
@@ -420,10 +420,10 @@ fn foo() {
420 check_join_lines( 420 check_join_lines(
421 r" 421 r"
422<|>use ra_syntax::{ 422<|>use ra_syntax::{
423 TextUnit, TextRange, 423 TextSize, TextRange,
424};", 424};",
425 r" 425 r"
426<|>use ra_syntax::{TextUnit, TextRange, 426<|>use ra_syntax::{TextSize, TextRange,
427};", 427};",
428 ); 428 );
429 } 429 }
@@ -434,11 +434,11 @@ fn foo() {
434 check_join_lines( 434 check_join_lines(
435 r" 435 r"
436use ra_syntax::{ 436use ra_syntax::{
437<|> TextUnit, TextRange 437<|> TextSize, TextRange
438};", 438};",
439 r" 439 r"
440use ra_syntax::{ 440use ra_syntax::{
441<|> TextUnit, TextRange};", 441<|> TextSize, TextRange};",
442 ); 442 );
443 } 443 }
444 444
@@ -448,11 +448,11 @@ use ra_syntax::{
448 check_join_lines( 448 check_join_lines(
449 r" 449 r"
450use ra_syntax::{ 450use ra_syntax::{
451<|> TextUnit, TextRange, 451<|> TextSize, TextRange,
452};", 452};",
453 r" 453 r"
454use ra_syntax::{ 454use ra_syntax::{
455<|> TextUnit, TextRange};", 455<|> TextSize, TextRange};",
456 ); 456 );
457 } 457 }
458 458
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index f692fbaa2..09f602fe1 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -60,7 +60,7 @@ use ra_ide_db::{
60 symbol_index::{self, FileSymbol}, 60 symbol_index::{self, FileSymbol},
61 LineIndexDatabase, 61 LineIndexDatabase,
62}; 62};
63use ra_syntax::{SourceFile, TextRange, TextUnit}; 63use ra_syntax::{SourceFile, TextRange, TextSize};
64 64
65use crate::display::ToNav; 65use crate::display::ToNav;
66 66
@@ -265,7 +265,7 @@ impl Analysis {
265 265
266 /// Returns position of the matching brace (all types of braces are 266 /// Returns position of the matching brace (all types of braces are
267 /// supported). 267 /// supported).
268 pub fn matching_brace(&self, position: FilePosition) -> Cancelable<Option<TextUnit>> { 268 pub fn matching_brace(&self, position: FilePosition) -> Cancelable<Option<TextSize>> {
269 self.with_db(|db| { 269 self.with_db(|db| {
270 let parse = db.parse(position.file_id); 270 let parse = db.parse(position.file_id);
271 let file = parse.tree(); 271 let file = parse.tree();
diff --git a/crates/ra_ide/src/matching_brace.rs b/crates/ra_ide/src/matching_brace.rs
index d1204fac0..b85348706 100644
--- a/crates/ra_ide/src/matching_brace.rs
+++ b/crates/ra_ide/src/matching_brace.rs
@@ -1,8 +1,8 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use ra_syntax::{ast::AstNode, SourceFile, SyntaxKind, TextUnit, T}; 3use ra_syntax::{ast::AstNode, SourceFile, SyntaxKind, TextSize, T};
4 4
5pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { 5pub fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<TextSize> {
6 const BRACES: &[SyntaxKind] = 6 const BRACES: &[SyntaxKind] =
7 &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>]]; 7 &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>]];
8 let (brace_node, brace_idx) = file 8 let (brace_node, brace_idx) = file
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index 9acc6158a..1c64b3eb9 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -54,7 +54,7 @@ fn source_edit_from_reference(reference: Reference, new_name: &str) -> SourceFil
54 ReferenceKind::StructFieldShorthandForField => { 54 ReferenceKind::StructFieldShorthandForField => {
55 replacement_text.push_str(new_name); 55 replacement_text.push_str(new_name);
56 replacement_text.push_str(": "); 56 replacement_text.push_str(": ");
57 TextRange::from_to( 57 TextRange::new(
58 reference.file_range.range.start(), 58 reference.file_range.range.start(),
59 reference.file_range.range.start(), 59 reference.file_range.range.start(),
60 ) 60 )
@@ -62,7 +62,7 @@ fn source_edit_from_reference(reference: Reference, new_name: &str) -> SourceFil
62 ReferenceKind::StructFieldShorthandForLocal => { 62 ReferenceKind::StructFieldShorthandForLocal => {
63 replacement_text.push_str(": "); 63 replacement_text.push_str(": ");
64 replacement_text.push_str(new_name); 64 replacement_text.push_str(new_name);
65 TextRange::from_to(reference.file_range.range.end(), reference.file_range.range.end()) 65 TextRange::new(reference.file_range.range.end(), reference.file_range.range.end())
66 } 66 }
67 _ => { 67 _ => {
68 replacement_text.push_str(new_name); 68 replacement_text.push_str(new_name);
diff --git a/crates/ra_ide/src/source_change.rs b/crates/ra_ide/src/source_change.rs
index f5f7f8807..71b0e8f75 100644
--- a/crates/ra_ide/src/source_change.rs
+++ b/crates/ra_ide/src/source_change.rs
@@ -6,7 +6,7 @@
6use ra_db::RelativePathBuf; 6use ra_db::RelativePathBuf;
7use ra_text_edit::TextEdit; 7use ra_text_edit::TextEdit;
8 8
9use crate::{FileId, FilePosition, SourceRootId, TextUnit}; 9use crate::{FileId, FilePosition, SourceRootId, TextSize};
10 10
11#[derive(Debug)] 11#[derive(Debug)]
12pub struct SourceChange { 12pub struct SourceChange {
@@ -104,7 +104,7 @@ pub enum FileSystemEdit {
104pub(crate) struct SingleFileChange { 104pub(crate) struct SingleFileChange {
105 pub label: String, 105 pub label: String,
106 pub edit: TextEdit, 106 pub edit: TextEdit,
107 pub cursor_position: Option<TextUnit>, 107 pub cursor_position: Option<TextSize>,
108} 108}
109 109
110impl SingleFileChange { 110impl SingleFileChange {
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index c0728bfb1..6f02614a6 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -61,16 +61,16 @@ impl HighlightedRangeStack {
61 let prev = self.stack.last_mut().unwrap(); 61 let prev = self.stack.last_mut().unwrap();
62 let needs_flattening = !children.is_empty() 62 let needs_flattening = !children.is_empty()
63 && !prev.is_empty() 63 && !prev.is_empty()
64 && children.first().unwrap().range.is_subrange(&prev.last().unwrap().range); 64 && prev.last().unwrap().range.contains_range(children.first().unwrap().range);
65 if !needs_flattening { 65 if !needs_flattening {
66 prev.extend(children); 66 prev.extend(children);
67 } else { 67 } else {
68 let mut parent = prev.pop().unwrap(); 68 let mut parent = prev.pop().unwrap();
69 for ele in children { 69 for ele in children {
70 assert!(ele.range.is_subrange(&parent.range)); 70 assert!(parent.range.contains_range(ele.range));
71 let mut cloned = parent.clone(); 71 let mut cloned = parent.clone();
72 parent.range = TextRange::from_to(parent.range.start(), ele.range.start()); 72 parent.range = TextRange::new(parent.range.start(), ele.range.start());
73 cloned.range = TextRange::from_to(ele.range.end(), cloned.range.end()); 73 cloned.range = TextRange::new(ele.range.end(), cloned.range.end());
74 if !parent.range.is_empty() { 74 if !parent.range.is_empty() {
75 prev.push(parent); 75 prev.push(parent);
76 } 76 }
@@ -152,7 +152,7 @@ pub(crate) fn highlight(
152 }; 152 };
153 153
154 // Element outside of the viewport, no need to highlight 154 // Element outside of the viewport, no need to highlight
155 if range_to_highlight.intersection(&event_range).is_none() { 155 if range_to_highlight.intersect(event_range).is_none() {
156 continue; 156 continue;
157 } 157 }
158 158
@@ -309,7 +309,7 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
309 } 309 }
310 } 310 }
311 311
312 Some(TextRange::from_to(range_start, range_end)) 312 Some(TextRange::new(range_start, range_end))
313} 313}
314 314
315fn highlight_element( 315fn highlight_element(
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 4496529a1..4f17d1040 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -1,7 +1,7 @@
1//! Renders a bit of code as HTML. 1//! Renders a bit of code as HTML.
2 2
3use ra_db::SourceDatabase; 3use ra_db::SourceDatabase;
4use ra_syntax::{AstNode, TextUnit}; 4use ra_syntax::{AstNode, TextSize};
5 5
6use crate::{FileId, RootDatabase}; 6use crate::{FileId, RootDatabase};
7 7
@@ -23,17 +23,18 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
23 23
24 let ranges = highlight(db, file_id, None); 24 let ranges = highlight(db, file_id, None);
25 let text = parse.tree().syntax().to_string(); 25 let text = parse.tree().syntax().to_string();
26 let mut prev_pos = TextUnit::from(0); 26 let mut prev_pos = TextSize::from(0);
27 let mut buf = String::new(); 27 let mut buf = String::new();
28 buf.push_str(&STYLE); 28 buf.push_str(&STYLE);
29 buf.push_str("<pre><code>"); 29 buf.push_str("<pre><code>");
30 // TODO: unusize
30 for range in &ranges { 31 for range in &ranges {
31 if range.range.start() > prev_pos { 32 if range.range.start() > prev_pos {
32 let curr = &text[prev_pos.to_usize()..range.range.start().to_usize()]; 33 let curr = &text[usize::from(prev_pos)..usize::from(range.range.start())];
33 let text = html_escape(curr); 34 let text = html_escape(curr);
34 buf.push_str(&text); 35 buf.push_str(&text);
35 } 36 }
36 let curr = &text[range.range.start().to_usize()..range.range.end().to_usize()]; 37 let curr = &text[usize::from(range.range.start())..usize::from(range.range.end())];
37 38
38 let class = range.highlight.to_string().replace('.', " "); 39 let class = range.highlight.to_string().replace('.', " ");
39 let color = match (rainbow, range.binding_hash) { 40 let color = match (rainbow, range.binding_hash) {
@@ -47,7 +48,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
47 prev_pos = range.range.end(); 48 prev_pos = range.range.end();
48 } 49 }
49 // Add the remaining (non-highlighted) text 50 // Add the remaining (non-highlighted) text
50 let curr = &text[prev_pos.to_usize()..]; 51 let curr = &text[usize::from(prev_pos)..];
51 let text = html_escape(curr); 52 let text = html_escape(curr);
52 buf.push_str(&text); 53 buf.push_str(&text);
53 buf.push_str("</code></pre>"); 54 buf.push_str("</code></pre>");
diff --git a/crates/ra_ide/src/syntax_tree.rs b/crates/ra_ide/src/syntax_tree.rs
index 5842ae2e8..a8a97a69f 100644
--- a/crates/ra_ide/src/syntax_tree.rs
+++ b/crates/ra_ide/src/syntax_tree.rs
@@ -5,7 +5,7 @@ use ra_ide_db::RootDatabase;
5use ra_syntax::{ 5use ra_syntax::{
6 algo, AstNode, NodeOrToken, SourceFile, 6 algo, AstNode, NodeOrToken, SourceFile,
7 SyntaxKind::{RAW_STRING, STRING}, 7 SyntaxKind::{RAW_STRING, STRING},
8 SyntaxToken, TextRange, TextUnit, 8 SyntaxToken, TextRange, TextSize,
9}; 9};
10 10
11pub use ra_db::FileId; 11pub use ra_db::FileId;
@@ -66,13 +66,13 @@ fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option<St
66 let len = len.min(node_len); 66 let len = len.min(node_len);
67 67
68 // Ensure our slice is inside the actual string 68 // Ensure our slice is inside the actual string
69 let end = if start + len < TextUnit::of_str(&text) { 69 let end = if start + len < TextSize::of(&text) {
70 start + len 70 start + len
71 } else { 71 } else {
72 TextUnit::of_str(&text) - start 72 TextSize::of(&text) - start
73 }; 73 };
74 74
75 let text = &text[TextRange::from_to(start, end)]; 75 let text = &text[TextRange::new(start, end)];
76 76
77 // Remove possible extra string quotes from the start 77 // Remove possible extra string quotes from the start
78 // and the end of the string 78 // and the end of the string
diff --git a/crates/ra_ide/src/test_utils.rs b/crates/ra_ide/src/test_utils.rs
index 8adb214d4..f14533e14 100644
--- a/crates/ra_ide/src/test_utils.rs
+++ b/crates/ra_ide/src/test_utils.rs
@@ -1,11 +1,11 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use ra_syntax::{SourceFile, TextUnit}; 3use ra_syntax::{SourceFile, TextSize};
4use ra_text_edit::TextEdit; 4use ra_text_edit::TextEdit;
5 5
6pub use test_utils::*; 6pub use test_utils::*;
7 7
8pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<TextEdit>>( 8pub fn check_action<F: Fn(&SourceFile, TextSize) -> Option<TextEdit>>(
9 before: &str, 9 before: &str,
10 after: &str, 10 after: &str,
11 f: F, 11 f: F,
diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs
index f55cd3bf5..98af79dff 100644
--- a/crates/ra_ide/src/typing.rs
+++ b/crates/ra_ide/src/typing.rs
@@ -21,7 +21,7 @@ use ra_ide_db::RootDatabase;
21use ra_syntax::{ 21use ra_syntax::{
22 algo::find_node_at_offset, 22 algo::find_node_at_offset,
23 ast::{self, AstToken}, 23 ast::{self, AstToken},
24 AstNode, SourceFile, TextRange, TextUnit, 24 AstNode, SourceFile, TextRange, TextSize,
25}; 25};
26use ra_text_edit::TextEdit; 26use ra_text_edit::TextEdit;
27 27
@@ -45,7 +45,7 @@ pub(crate) fn on_char_typed(
45 45
46fn on_char_typed_inner( 46fn on_char_typed_inner(
47 file: &SourceFile, 47 file: &SourceFile,
48 offset: TextUnit, 48 offset: TextSize,
49 char_typed: char, 49 char_typed: char,
50) -> Option<SingleFileChange> { 50) -> Option<SingleFileChange> {
51 assert!(TRIGGER_CHARS.contains(char_typed)); 51 assert!(TRIGGER_CHARS.contains(char_typed));
@@ -60,7 +60,7 @@ fn on_char_typed_inner(
60/// Returns an edit which should be applied after `=` was typed. Primarily, 60/// Returns an edit which should be applied after `=` was typed. Primarily,
61/// this works when adding `let =`. 61/// this works when adding `let =`.
62// FIXME: use a snippet completion instead of this hack here. 62// FIXME: use a snippet completion instead of this hack here.
63fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange> { 63fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<SingleFileChange> {
64 assert_eq!(file.syntax().text().char_at(offset), Some('=')); 64 assert_eq!(file.syntax().text().char_at(offset), Some('='));
65 let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; 65 let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?;
66 if let_stmt.semicolon_token().is_some() { 66 if let_stmt.semicolon_token().is_some() {
@@ -86,7 +86,7 @@ fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange>
86} 86}
87 87
88/// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately. 88/// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately.
89fn on_dot_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange> { 89fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<SingleFileChange> {
90 assert_eq!(file.syntax().text().char_at(offset), Some('.')); 90 assert_eq!(file.syntax().text().char_at(offset), Some('.'));
91 let whitespace = 91 let whitespace =
92 file.syntax().token_at_offset(offset).left_biased().and_then(ast::Whitespace::cast)?; 92 file.syntax().token_at_offset(offset).left_biased().and_then(ast::Whitespace::cast)?;
@@ -96,13 +96,13 @@ fn on_dot_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange>
96 let newline = text.rfind('\n')?; 96 let newline = text.rfind('\n')?;
97 &text[newline + 1..] 97 &text[newline + 1..]
98 }; 98 };
99 let current_indent_len = TextUnit::of_str(current_indent); 99 let current_indent_len = TextSize::of(current_indent);
100 100
101 // Make sure dot is a part of call chain 101 // Make sure dot is a part of call chain
102 let field_expr = ast::FieldExpr::cast(whitespace.syntax().parent())?; 102 let field_expr = ast::FieldExpr::cast(whitespace.syntax().parent())?;
103 let prev_indent = leading_indent(field_expr.syntax())?; 103 let prev_indent = leading_indent(field_expr.syntax())?;
104 let target_indent = format!(" {}", prev_indent); 104 let target_indent = format!(" {}", prev_indent);
105 let target_indent_len = TextUnit::of_str(&target_indent); 105 let target_indent_len = TextSize::of(&target_indent);
106 if current_indent_len == target_indent_len { 106 if current_indent_len == target_indent_len {
107 return None; 107 return None;
108 } 108 }
@@ -110,20 +110,20 @@ fn on_dot_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange>
110 Some(SingleFileChange { 110 Some(SingleFileChange {
111 label: "reindent dot".to_string(), 111 label: "reindent dot".to_string(),
112 edit: TextEdit::replace( 112 edit: TextEdit::replace(
113 TextRange::from_to(offset - current_indent_len, offset), 113 TextRange::new(offset - current_indent_len, offset),
114 target_indent, 114 target_indent,
115 ), 115 ),
116 cursor_position: Some( 116 cursor_position: Some(
117 offset + target_indent_len - current_indent_len + TextUnit::of_char('.'), 117 offset + target_indent_len - current_indent_len + TextSize::of('.'),
118 ), 118 ),
119 }) 119 })
120} 120}
121 121
122/// Adds a space after an arrow when `fn foo() { ... }` is turned into `fn foo() -> { ... }` 122/// Adds a space after an arrow when `fn foo() { ... }` is turned into `fn foo() -> { ... }`
123fn on_arrow_typed(file: &SourceFile, offset: TextUnit) -> Option<SingleFileChange> { 123fn on_arrow_typed(file: &SourceFile, offset: TextSize) -> Option<SingleFileChange> {
124 let file_text = file.syntax().text(); 124 let file_text = file.syntax().text();
125 assert_eq!(file_text.char_at(offset), Some('>')); 125 assert_eq!(file_text.char_at(offset), Some('>'));
126 let after_arrow = offset + TextUnit::of_char('>'); 126 let after_arrow = offset + TextSize::of('>');
127 if file_text.char_at(after_arrow) != Some('{') { 127 if file_text.char_at(after_arrow) != Some('{') {
128 return None; 128 return None;
129 } 129 }
diff --git a/crates/ra_ide/src/typing/on_enter.rs b/crates/ra_ide/src/typing/on_enter.rs
index 6bcf2d72b..30c8c5572 100644
--- a/crates/ra_ide/src/typing/on_enter.rs
+++ b/crates/ra_ide/src/typing/on_enter.rs
@@ -7,7 +7,7 @@ use ra_syntax::{
7 ast::{self, AstToken}, 7 ast::{self, AstToken},
8 AstNode, SmolStr, SourceFile, 8 AstNode, SmolStr, SourceFile,
9 SyntaxKind::*, 9 SyntaxKind::*,
10 SyntaxToken, TextUnit, TokenAtOffset, 10 SyntaxToken, TextSize, TokenAtOffset,
11}; 11};
12use ra_text_edit::TextEdit; 12use ra_text_edit::TextEdit;
13 13
@@ -28,7 +28,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
28 28
29 let prefix = comment.prefix(); 29 let prefix = comment.prefix();
30 let comment_range = comment.syntax().text_range(); 30 let comment_range = comment.syntax().text_range();
31 if position.offset < comment_range.start() + TextUnit::of_str(prefix) { 31 if position.offset < comment_range.start() + TextSize::of(prefix) {
32 return None; 32 return None;
33 } 33 }
34 34
@@ -39,7 +39,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
39 39
40 let indent = node_indent(&file, comment.syntax())?; 40 let indent = node_indent(&file, comment.syntax())?;
41 let inserted = format!("\n{}{} ", indent, prefix); 41 let inserted = format!("\n{}{} ", indent, prefix);
42 let cursor_position = position.offset + TextUnit::of_str(&inserted); 42 let cursor_position = position.offset + TextSize::of(&inserted);
43 let edit = TextEdit::insert(position.offset, inserted); 43 let edit = TextEdit::insert(position.offset, inserted);
44 44
45 Some( 45 Some(