From 6d5d82e412dea19ea48eecc6f7d5a4aa223a9599 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 20 Jul 2019 12:48:24 +0300 Subject: move debug_dump to fmt::Debug --- crates/ra_ide_api/src/display/navigation_target.rs | 2 +- crates/ra_ide_api/src/syntax_tree.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 8aff5f2cd..c212ebf28 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -233,7 +233,7 @@ impl NavigationTarget { pub(crate) fn from_macro_def(db: &RootDatabase, macro_call: hir::MacroDef) -> NavigationTarget { let src = macro_call.source(db); - log::debug!("nav target {}", src.ast.syntax().debug_dump()); + log::debug!("nav target {:#?}", src.ast.syntax()); NavigationTarget::from_named( src.file_id.original_file(db), &src.ast, diff --git a/crates/ra_ide_api/src/syntax_tree.rs b/crates/ra_ide_api/src/syntax_tree.rs index 3d7373d02..ae1849aaa 100644 --- a/crates/ra_ide_api/src/syntax_tree.rs +++ b/crates/ra_ide_api/src/syntax_tree.rs @@ -25,9 +25,9 @@ pub(crate) fn syntax_tree( } }; - node.debug_dump() + format!("{:#?}", node) } else { - parse.tree().syntax().debug_dump() + format!("{:#?}", parse.tree().syntax()) } } @@ -85,7 +85,7 @@ fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option Date: Sat, 20 Jul 2019 12:58:27 +0300 Subject: rename range -> text_range --- crates/ra_ide_api/src/call_info.rs | 4 +- .../ra_ide_api/src/completion/complete_keyword.rs | 2 +- crates/ra_ide_api/src/completion/complete_path.rs | 2 +- .../ra_ide_api/src/completion/complete_postfix.rs | 2 +- .../src/completion/completion_context.rs | 32 +++++++++------ crates/ra_ide_api/src/diagnostics.rs | 12 +++--- crates/ra_ide_api/src/display/navigation_target.rs | 4 +- crates/ra_ide_api/src/display/structure.rs | 8 ++-- crates/ra_ide_api/src/extend_selection.rs | 48 ++++++++++++---------- crates/ra_ide_api/src/folding_ranges.rs | 9 ++-- crates/ra_ide_api/src/goto_definition.rs | 4 +- crates/ra_ide_api/src/goto_type_definition.rs | 2 +- crates/ra_ide_api/src/hover.rs | 10 ++--- crates/ra_ide_api/src/impls.rs | 4 +- crates/ra_ide_api/src/join_lines.rs | 22 +++++----- crates/ra_ide_api/src/matching_brace.rs | 2 +- crates/ra_ide_api/src/references.rs | 2 +- crates/ra_ide_api/src/runnables.rs | 4 +- crates/ra_ide_api/src/symbol_index.rs | 2 +- crates/ra_ide_api/src/syntax_highlighting.rs | 14 +++---- crates/ra_ide_api/src/syntax_tree.rs | 2 +- crates/ra_ide_api/src/typing.rs | 8 ++-- 22 files changed, 107 insertions(+), 92 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 270499612..212448d41 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -47,7 +47,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option Option bool { .visit::(|it| it.loop_body()) .accept(&node); if let Some(Some(body)) = loop_body { - if leaf.range().is_subrange(&body.syntax().range()) { + if leaf.text_range().is_subrange(&body.syntax().text_range()) { return true; } } diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 29586cd1f..5fd41eeb3 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -26,7 +26,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { if Some(module) == ctx.module { if let Some(import) = res.import { if let Either::A(use_tree) = module.import_source(ctx.db, import) { - if use_tree.syntax().range().contains_inclusive(ctx.offset) { + if use_tree.syntax().text_range().contains_inclusive(ctx.offset) { // for `use self::foo<|>`, don't suggest `foo` as a completion tested_by!(dont_complete_current_use); continue; diff --git a/crates/ra_ide_api/src/completion/complete_postfix.rs b/crates/ra_ide_api/src/completion/complete_postfix.rs index c75b1c159..6d834f6ce 100644 --- a/crates/ra_ide_api/src/completion/complete_postfix.rs +++ b/crates/ra_ide_api/src/completion/complete_postfix.rs @@ -12,7 +12,7 @@ use ra_text_edit::TextEditBuilder; fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder { let edit = { let receiver_range = - ctx.dot_receiver.as_ref().expect("no receiver available").syntax().range(); + ctx.dot_receiver.as_ref().expect("no receiver available").syntax().text_range(); let delete_range = TextRange::from_to(receiver_range.start(), ctx.source_range().end()); let mut builder = TextEditBuilder::default(); builder.replace(delete_range, snippet.to_string()); diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index b803271ab..2f78d5409 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs @@ -78,7 +78,7 @@ impl<'a> CompletionContext<'a> { pub(crate) fn source_range(&self) -> TextRange { match self.token.kind() { // workaroud when completion is triggered by trigger characters. - IDENT => self.token.range(), + IDENT => self.token.text_range(), _ => TextRange::offset_len(self.offset, 0.into()), } } @@ -123,13 +123,17 @@ impl<'a> CompletionContext<'a> { } fn classify_name_ref(&mut self, original_file: SourceFile, name_ref: ast::NameRef) { - let name_range = name_ref.syntax().range(); + let name_range = name_ref.syntax().text_range(); if name_ref.syntax().parent().and_then(ast::NamedField::cast).is_some() { self.struct_lit_syntax = find_node_at_offset(original_file.syntax(), self.offset); } - let top_node = - name_ref.syntax().ancestors().take_while(|it| it.range() == name_range).last().unwrap(); + let top_node = name_ref + .syntax() + .ancestors() + .take_while(|it| it.text_range() == name_range) + .last() + .unwrap(); match top_node.parent().map(|it| it.kind()) { Some(SOURCE_FILE) | Some(ITEM_LIST) => { @@ -180,23 +184,27 @@ impl<'a> CompletionContext<'a> { .ancestors() .find_map(|node| { if let Some(stmt) = ast::ExprStmt::cast(node.clone()) { - return Some(stmt.syntax().range() == name_ref.syntax().range()); + return Some( + stmt.syntax().text_range() == name_ref.syntax().text_range(), + ); } if let Some(block) = ast::Block::cast(node) { return Some( - block.expr().map(|e| e.syntax().range()) - == Some(name_ref.syntax().range()), + block.expr().map(|e| e.syntax().text_range()) + == Some(name_ref.syntax().text_range()), ); } None }) .unwrap_or(false); - if let Some(off) = name_ref.syntax().range().start().checked_sub(2.into()) { + if let Some(off) = name_ref.syntax().text_range().start().checked_sub(2.into()) { if let Some(if_expr) = find_node_at_offset::(original_file.syntax(), off) { - if if_expr.syntax().range().end() < name_ref.syntax().range().start() { + if if_expr.syntax().text_range().end() + < name_ref.syntax().text_range().start() + { self.after_if = true; } } @@ -208,14 +216,14 @@ impl<'a> CompletionContext<'a> { // ident, so it should have the same range in the non-modified file self.dot_receiver = field_expr .expr() - .map(|e| e.syntax().range()) + .map(|e| e.syntax().text_range()) .and_then(|r| find_node_with_range(original_file.syntax(), r)); } if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) { // As above self.dot_receiver = method_call_expr .expr() - .map(|e| e.syntax().range()) + .map(|e| e.syntax().text_range()) .and_then(|r| find_node_with_range(original_file.syntax(), r)); self.is_call = true; } @@ -229,6 +237,6 @@ fn find_node_with_range(syntax: &SyntaxNode, range: TextRange) -> Op fn is_node(node: &SyntaxNode) -> bool { match node.ancestors().filter_map(N::cast).next() { None => false, - Some(n) => n.syntax().range() == node.range(), + Some(n) => n.syntax().text_range() == node.text_range(), } } diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index affbad6cd..028dc3d4f 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs @@ -96,7 +96,7 @@ fn check_unnecessary_braces_in_use_statement( ) -> Option<()> { let use_tree_list = ast::UseTreeList::cast(node.clone())?; if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() { - let range = use_tree_list.syntax().range(); + let range = use_tree_list.syntax().text_range(); let edit = text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(&single_use_tree) .unwrap_or_else(|| { @@ -126,8 +126,8 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement( ) -> Option { let use_tree_list_node = single_use_tree.syntax().parent()?; if single_use_tree.path()?.segment()?.syntax().first_child_or_token()?.kind() == T![self] { - let start = use_tree_list_node.prev_sibling_or_token()?.range().start(); - let end = use_tree_list_node.range().end(); + let start = use_tree_list_node.prev_sibling_or_token()?.text_range().start(); + let end = use_tree_list_node.text_range().end(); let range = TextRange::from_to(start, end); let mut edit_builder = TextEditBuilder::default(); edit_builder.delete(range); @@ -149,12 +149,12 @@ fn check_struct_shorthand_initialization( let field_expr = expr.syntax().text().to_string(); if field_name == field_expr { let mut edit_builder = TextEditBuilder::default(); - edit_builder.delete(named_field.syntax().range()); - edit_builder.insert(named_field.syntax().range().start(), field_name); + edit_builder.delete(named_field.syntax().text_range()); + edit_builder.insert(named_field.syntax().text_range().start(), field_name); let edit = edit_builder.finish(); acc.push(Diagnostic { - range: named_field.syntax().range(), + range: named_field.syntax().text_range(), message: "Shorthand struct initialization".to_string(), severity: Severity::WeakWarning, fix: Some(SourceChange::source_file_edit( diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index c212ebf28..84fabdb9e 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -275,7 +275,7 @@ impl NavigationTarget { ) -> NavigationTarget { //FIXME: use `_` instead of empty string let name = node.name().map(|it| it.text().clone()).unwrap_or_default(); - let focus_range = node.name().map(|it| it.syntax().range()); + let focus_range = node.name().map(|it| it.syntax().text_range()); NavigationTarget::from_syntax(file_id, name, focus_range, node.syntax(), docs, description) } @@ -291,7 +291,7 @@ impl NavigationTarget { file_id, name, kind: node.kind(), - full_range: node.range(), + full_range: node.text_range(), focus_range, // ptr: Some(LocalSyntaxPtr::new(node)), container_name: None, diff --git a/crates/ra_ide_api/src/display/structure.rs b/crates/ra_ide_api/src/display/structure.rs index 0b1a8b6e6..2ba10b2ef 100644 --- a/crates/ra_ide_api/src/display/structure.rs +++ b/crates/ra_ide_api/src/display/structure.rs @@ -73,8 +73,8 @@ fn structure_node(node: &SyntaxNode) -> Option { Some(StructureNode { parent: None, label: name.text().to_string(), - navigation_range: name.syntax().range(), - node_range: node.syntax().range(), + navigation_range: name.syntax().text_range(), + node_range: node.syntax().text_range(), kind: node.syntax().kind(), detail, deprecated: node.attrs().filter_map(|x| x.as_named()).any(|x| x == "deprecated"), @@ -140,8 +140,8 @@ fn structure_node(node: &SyntaxNode) -> Option { let node = StructureNode { parent: None, label, - navigation_range: target_type.syntax().range(), - node_range: im.syntax().range(), + navigation_range: target_type.syntax().text_range(), + node_range: im.syntax().text_range(), kind: im.syntax().kind(), detail: None, deprecated: false, diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 292f61f4a..140820df6 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs @@ -42,19 +42,20 @@ fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option return None, TokenAtOffset::Single(l) => { if string_kinds.contains(&l.kind()) { - extend_single_word_in_comment_or_string(&l, offset).unwrap_or_else(|| l.range()) + extend_single_word_in_comment_or_string(&l, offset) + .unwrap_or_else(|| l.text_range()) } else { - l.range() + l.text_range() } } - TokenAtOffset::Between(l, r) => pick_best(l, r).range(), + TokenAtOffset::Between(l, r) => pick_best(l, r).text_range(), }; return Some(leaf_range); }; let node = match find_covering_element(root, range) { SyntaxElement::Token(token) => { - if token.range() != range { - return Some(token.range()); + if token.text_range() != range { + return Some(token.text_range()); } if let Some(comment) = ast::Comment::cast(token.clone()) { if let Some(range) = extend_comments(comment) { @@ -65,12 +66,12 @@ fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option node, }; - if node.range() != range { - return Some(node.range()); + if node.text_range() != range { + return Some(node.text_range()); } // Using shallowest node with same range allows us to traverse siblings. - let node = node.ancestors().take_while(|n| n.range() == node.range()).last().unwrap(); + let node = node.ancestors().take_while(|n| n.text_range() == node.text_range()).last().unwrap(); if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) { if let Some(range) = extend_list_item(&node) { @@ -78,7 +79,7 @@ fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option Option { let text: &str = leaf.text(); - let cursor_position: u32 = (offset - leaf.range().start()).into(); + let cursor_position: u32 = (offset - leaf.text_range().start()).into(); let (before, after) = text.split_at(cursor_position as usize); @@ -104,31 +105,31 @@ fn extend_single_word_in_comment_or_string( if range.is_empty() { None } else { - Some(range + leaf.range().start()) + Some(range + leaf.text_range().start()) } } fn extend_ws(root: &SyntaxNode, ws: SyntaxToken, offset: TextUnit) -> TextRange { let ws_text = ws.text(); - let suffix = TextRange::from_to(offset, ws.range().end()) - ws.range().start(); - let prefix = TextRange::from_to(ws.range().start(), offset) - ws.range().start(); + let suffix = TextRange::from_to(offset, ws.text_range().end()) - ws.text_range().start(); + let prefix = TextRange::from_to(ws.text_range().start(), offset) - ws.text_range().start(); let ws_suffix = &ws_text.as_str()[suffix]; let ws_prefix = &ws_text.as_str()[prefix]; if ws_text.contains('\n') && !ws_suffix.contains('\n') { if let Some(node) = ws.next_sibling_or_token() { let start = match ws_prefix.rfind('\n') { - Some(idx) => ws.range().start() + TextUnit::from((idx + 1) as u32), - None => node.range().start(), + Some(idx) => ws.text_range().start() + TextUnit::from((idx + 1) as u32), + None => node.text_range().start(), }; - let end = if root.text().char_at(node.range().end()) == Some('\n') { - node.range().end() + TextUnit::of_char('\n') + let end = if root.text().char_at(node.text_range().end()) == Some('\n') { + node.text_range().end() + TextUnit::of_char('\n') } else { - node.range().end() + node.text_range().end() }; return TextRange::from_to(start, end); } } - ws.range() + ws.text_range() } fn pick_best<'a>(l: SyntaxToken, r: SyntaxToken) -> SyntaxToken { @@ -161,7 +162,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option { } if let Some(comma_node) = nearby_comma(node, Direction::Prev) { - return Some(TextRange::from_to(comma_node.range().start(), node.range().end())); + return Some(TextRange::from_to(comma_node.text_range().start(), node.text_range().end())); } if let Some(comma_node) = nearby_comma(node, Direction::Next) { // Include any following whitespace when comma if after list item. @@ -171,7 +172,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option { .filter(|node| is_single_line_ws(node)) .unwrap_or(comma_node); - return Some(TextRange::from_to(node.range().start(), final_node.range().end())); + return Some(TextRange::from_to(node.text_range().start(), final_node.text_range().end())); } None @@ -181,7 +182,10 @@ fn extend_comments(comment: ast::Comment) -> Option { let prev = adj_comments(&comment, Direction::Prev); let next = adj_comments(&comment, Direction::Next); if prev != next { - Some(TextRange::from_to(prev.syntax().range().start(), next.syntax().range().end())) + Some(TextRange::from_to( + prev.syntax().text_range().start(), + next.syntax().text_range().end(), + )) } else { None } diff --git a/crates/ra_ide_api/src/folding_ranges.rs b/crates/ra_ide_api/src/folding_ranges.rs index c2b981aed..9699000db 100644 --- a/crates/ra_ide_api/src/folding_ranges.rs +++ b/crates/ra_ide_api/src/folding_ranges.rs @@ -35,7 +35,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { SyntaxElement::Token(token) => token.text().contains('\n'), }; if is_multiline { - res.push(Fold { range: element.range(), kind }); + res.push(Fold { range: element.text_range(), kind }); continue; } } @@ -132,7 +132,7 @@ fn contiguous_range_for_group_unless( } if first != &last { - Some(TextRange::from_to(first.range().start(), last.range().end())) + Some(TextRange::from_to(first.text_range().start(), last.text_range().end())) } else { // The group consists of only one element, therefore it cannot be folded None @@ -178,7 +178,10 @@ fn contiguous_range_for_comment( } if first != last { - Some(TextRange::from_to(first.syntax().range().start(), last.syntax().range().end())) + Some(TextRange::from_to( + first.syntax().text_range().start(), + last.syntax().text_range().end(), + )) } else { // The group consists of only one element, therefore it cannot be folded None diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 82b5e3b5e..ddd55a9c1 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -23,11 +23,11 @@ pub(crate) fn goto_definition( let syntax = parse.tree().syntax().clone(); if let Some(name_ref) = find_node_at_offset::(&syntax, position.offset) { let navs = reference_definition(db, position.file_id, &name_ref).to_vec(); - return Some(RangeInfo::new(name_ref.syntax().range(), navs.to_vec())); + return Some(RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec())); } if let Some(name) = find_node_at_offset::(&syntax, position.offset) { let navs = name_definition(db, position.file_id, &name)?; - return Some(RangeInfo::new(name.syntax().range(), navs)); + return Some(RangeInfo::new(name.syntax().text_range(), navs)); } None } diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs index fc4b6e1af..007259d9e 100644 --- a/crates/ra_ide_api/src/goto_type_definition.rs +++ b/crates/ra_ide_api/src/goto_type_definition.rs @@ -32,7 +32,7 @@ pub(crate) fn goto_type_definition( let adt_def = analyzer.autoderef(db, ty).find_map(|ty| ty.as_adt().map(|adt| adt.0))?; let nav = NavigationTarget::from_adt_def(db, adt_def); - Some(RangeInfo::new(node.range(), vec![nav])) + Some(RangeInfo::new(node.text_range(), vec![nav])) } #[cfg(test)] diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index e503bf6a9..2a5ac7821 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -172,7 +172,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option(file.syntax(), position.offset) { if let Some(parent) = name.syntax().parent() { @@ -210,7 +210,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option Option Option { // if we picked identifier, expand to pattern/expression let node = leaf_node .ancestors() - .take_while(|it| it.range() == leaf_node.range()) + .take_while(|it| it.text_range() == leaf_node.text_range()) .find(|it| ast::Expr::cast(it.clone()).is_some() || ast::Pat::cast(it.clone()).is_some())?; let analyzer = hir::SourceAnalyzer::new(db, frange.file_id, &node, None); let ty = if let Some(ty) = ast::Expr::cast(node.clone()).and_then(|e| analyzer.type_of(db, &e)) diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs index 15999d433..f5b6ffd61 100644 --- a/crates/ra_ide_api/src/impls.rs +++ b/crates/ra_ide_api/src/impls.rs @@ -15,12 +15,12 @@ pub(crate) fn goto_implementation( if let Some(nominal_def) = find_node_at_offset::(&syntax, position.offset) { return Some(RangeInfo::new( - nominal_def.syntax().range(), + nominal_def.syntax().text_range(), impls_for_def(db, &nominal_def, module)?, )); } else if let Some(trait_def) = find_node_at_offset::(&syntax, position.offset) { return Some(RangeInfo::new( - trait_def.syntax().range(), + trait_def.syntax().text_range(), impls_for_trait(db, &trait_def, module)?, )); } diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs index 9b81ad9e4..fa998ebe1 100644 --- a/crates/ra_ide_api/src/join_lines.rs +++ b/crates/ra_ide_api/src/join_lines.rs @@ -28,14 +28,14 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit { }; let mut edit = TextEditBuilder::default(); for token in node.descendants_with_tokens().filter_map(|it| it.into_token()) { - let range = match range.intersection(&token.range()) { + let range = match range.intersection(&token.text_range()) { Some(range) => range, None => continue, - } - token.range().start(); + } - token.text_range().start(); let text = token.text(); for (pos, _) in text[range].bytes().enumerate().filter(|&(_, b)| b == b'\n') { let pos: TextUnit = (pos as u32).into(); - let off = token.range().start() + range.start() + pos; + let off = token.text_range().start() + range.start() + pos; if !edit.invalidates_offset(off) { remove_newline(&mut edit, &token, off); } @@ -49,7 +49,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU if token.kind() != WHITESPACE || token.text().bytes().filter(|&b| b == b'\n').count() != 1 { // The node is either the first or the last in the file let suff = &token.text()[TextRange::from_to( - offset - token.range().start() + TextUnit::of_char('\n'), + offset - token.text_range().start() + TextUnit::of_char('\n'), TextUnit::of_str(token.text()), )]; let spaces = suff.bytes().take_while(|&b| b == b' ').count(); @@ -86,7 +86,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU let next = token.next_sibling_or_token().unwrap(); if is_trailing_comma(prev.kind(), next.kind()) { // Removes: trailing comma, newline (incl. surrounding whitespace) - edit.delete(TextRange::from_to(prev.range().start(), token.range().end())); + edit.delete(TextRange::from_to(prev.text_range().start(), token.text_range().end())); } else if prev.kind() == T![,] && next.kind() == T!['}'] { // Removes: comma, newline (incl. surrounding whitespace) let space = if let Some(left) = prev.prev_sibling_or_token() { @@ -95,7 +95,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU " " }; edit.replace( - TextRange::from_to(prev.range().start(), token.range().end()), + TextRange::from_to(prev.text_range().start(), token.text_range().end()), space.to_string(), ); } else if let (Some(_), Some(next)) = ( @@ -104,12 +104,12 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU ) { // Removes: newline (incl. surrounding whitespace), start of the next comment edit.delete(TextRange::from_to( - token.range().start(), - next.syntax().range().start() + TextUnit::of_str(next.prefix()), + token.text_range().start(), + next.syntax().text_range().start() + TextUnit::of_str(next.prefix()), )); } else { // Remove newline but add a computed amount of whitespace characters - edit.replace(token.range(), compute_ws(prev.kind(), next.kind()).to_string()); + edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_string()); } } @@ -125,7 +125,7 @@ fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Op let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; let expr = extract_trivial_expression(&block)?; - let block_range = block_expr.syntax().range(); + let block_range = block_expr.syntax().text_range(); let mut buf = expr.syntax().text().to_string(); // Match block needs to have a comma after the block @@ -143,7 +143,7 @@ fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Op fn join_single_use_tree(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Option<()> { let use_tree_list = ast::UseTreeList::cast(token.parent())?; let (tree,) = use_tree_list.use_trees().collect_tuple()?; - edit.replace(use_tree_list.syntax().range(), tree.syntax().text().to_string()); + edit.replace(use_tree_list.syntax().text_range(), tree.syntax().text().to_string()); Some(()) } diff --git a/crates/ra_ide_api/src/matching_brace.rs b/crates/ra_ide_api/src/matching_brace.rs index 102327fd7..1e2fac848 100644 --- a/crates/ra_ide_api/src/matching_brace.rs +++ b/crates/ra_ide_api/src/matching_brace.rs @@ -12,7 +12,7 @@ pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option { let parent = brace_node.parent(); let matching_kind = BRACES[brace_idx ^ 1]; let matching_node = parent.children_with_tokens().find(|node| node.kind() == matching_kind)?; - Some(matching_node.range().start()) + Some(matching_node.text_range().start()) } #[cfg(test)] diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index 1c4cd49dc..5c74d3e36 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs @@ -166,7 +166,7 @@ fn rename_mod( file_id: position.file_id, edit: { let mut builder = ra_text_edit::TextEditBuilder::default(); - builder.replace(ast_name.syntax().range(), new_name.into()); + builder.replace(ast_name.syntax().text_range(), new_name.into()); builder.finish() }, }; diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index 200958434..07412a9ef 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs @@ -47,7 +47,7 @@ fn runnable_fn(fn_def: ast::FnDef) -> Option { } else { return None; }; - Some(Runnable { range: fn_def.syntax().range(), kind }) + Some(Runnable { range: fn_def.syntax().text_range(), kind }) } fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Option { @@ -62,7 +62,7 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Opti if !has_test_function { return None; } - let range = module.syntax().range(); + let range = module.syntax().text_range(); let module = hir::source_binder::module_from_child_node(db, file_id, module.syntax())?; let path = module.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)).join("::"); diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs index e784b5f69..d4afddab4 100644 --- a/crates/ra_ide_api/src/symbol_index.rs +++ b/crates/ra_ide_api/src/symbol_index.rs @@ -271,7 +271,7 @@ fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> { fn decl(node: N) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> { let name = node.name()?; - let name_range = name.syntax().range(); + let name_range = name.syntax().text_range(); let name = name.text().clone(); let ptr = SyntaxNodePtr::new(node.syntax()); diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 477827fa7..878a94f06 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -189,11 +189,11 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec range_end = sibling.range().end(), + T![!] | IDENT => range_end = sibling.text_range().end(), _ => (), } } @@ -209,7 +209,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec"); let tokens = parse.tree().syntax().descendants_with_tokens().filter_map(|it| it.into_token()); for token in tokens { - could_intersect.retain(|it| token.range().start() <= it.range.end()); + could_intersect.retain(|it| token.text_range().start() <= it.range.end()); while let Some(r) = ranges.get(frontier) { - if r.range.start() <= token.range().end() { + if r.range.start() <= token.text_range().end() { could_intersect.push(r); frontier += 1; } else { @@ -251,7 +251,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo let text = html_escape(&token.text()); let ranges = could_intersect .iter() - .filter(|it| token.range().is_subrange(&it.range)) + .filter(|it| token.text_range().is_subrange(&it.range)) .collect::>(); if ranges.is_empty() { buf.push_str(&text); diff --git a/crates/ra_ide_api/src/syntax_tree.rs b/crates/ra_ide_api/src/syntax_tree.rs index ae1849aaa..76c50f6d6 100644 --- a/crates/ra_ide_api/src/syntax_tree.rs +++ b/crates/ra_ide_api/src/syntax_tree.rs @@ -45,7 +45,7 @@ fn syntax_tree_for_string(token: &SyntaxToken, text_range: TextRange) -> Option< fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option { // Range of the full node - let node_range = node.range(); + let node_range = node.text_range(); let text = node.text().to_string(); // We start at some point inside the node diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index ad0ababcc..1747a529e 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs @@ -24,7 +24,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option Option Option { - let ws = match find_token_at_offset(file.syntax(), token.range().start()) { + let ws = match find_token_at_offset(file.syntax(), token.text_range().start()) { TokenAtOffset::Between(l, r) => { assert!(r == *token); l @@ -71,7 +71,7 @@ pub fn on_eq_typed(file: &SourceFile, eq_offset: TextUnit) -> Option { return None; } if let Some(expr) = let_stmt.initializer() { - let expr_range = expr.syntax().range(); + let expr_range = expr.syntax().text_range(); if expr_range.contains(eq_offset) && eq_offset != expr_range.start() { return None; } @@ -81,7 +81,7 @@ pub fn on_eq_typed(file: &SourceFile, eq_offset: TextUnit) -> Option { } else { return None; } - let offset = let_stmt.syntax().range().end(); + let offset = let_stmt.syntax().text_range().end(); let mut edit = TextEditBuilder::default(); edit.insert(offset, ";".to_string()); Some(edit.finish()) -- cgit v1.2.3