From 6dbba4d75d56728a95f84ee978eae3ac84016c73 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Jan 2021 20:15:33 +0300 Subject: Remove useless wrapper --- crates/assists/src/assist_context.rs | 5 ++--- crates/completion/src/context.rs | 8 +++----- crates/hir_expand/src/db.rs | 2 +- crates/hir_expand/src/lib.rs | 8 ++++---- crates/ide/src/extend_selection.rs | 6 +++--- crates/ide/src/join_lines.rs | 4 ++-- crates/ide/src/syntax_tree.rs | 4 ++-- crates/syntax/src/algo.rs | 6 +----- crates/syntax/src/parsing/reparsing.rs | 5 ++--- 9 files changed, 20 insertions(+), 28 deletions(-) (limited to 'crates') diff --git a/crates/assists/src/assist_context.rs b/crates/assists/src/assist_context.rs index 321fe77f3..8d93edba2 100644 --- a/crates/assists/src/assist_context.rs +++ b/crates/assists/src/assist_context.rs @@ -2,7 +2,6 @@ use std::mem; -use algo::find_covering_element; use hir::Semantics; use ide_db::{ base_db::{AnchoredPathBuf, FileId, FileRange}, @@ -94,11 +93,11 @@ impl<'a> AssistContext<'a> { self.sema.find_node_at_offset_with_descend(self.source_file.syntax(), self.offset()) } pub(crate) fn covering_element(&self) -> SyntaxElement { - find_covering_element(self.source_file.syntax(), self.frange.range) + self.source_file.syntax().covering_element(self.frange.range) } // FIXME: remove pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement { - find_covering_element(self.source_file.syntax(), range) + self.source_file.syntax().covering_element(range) } } diff --git a/crates/completion/src/context.rs b/crates/completion/src/context.rs index d809460e2..b1e8eba85 100644 --- a/crates/completion/src/context.rs +++ b/crates/completion/src/context.rs @@ -4,10 +4,8 @@ use hir::{Local, ScopeDef, Semantics, SemanticsScope, Type}; use ide_db::base_db::{FilePosition, SourceDatabase}; use ide_db::{call_info::ActiveParameter, RootDatabase}; use syntax::{ - algo::{find_covering_element, find_node_at_offset}, - ast, match_ast, AstNode, NodeOrToken, - SyntaxKind::*, - SyntaxNode, SyntaxToken, TextRange, TextSize, + algo::find_node_at_offset, ast, match_ast, AstNode, NodeOrToken, SyntaxKind::*, SyntaxNode, + SyntaxToken, TextRange, TextSize, }; use test_utils::mark; use text_edit::Indel; @@ -513,7 +511,7 @@ impl<'a> CompletionContext<'a> { } fn find_node_with_range(syntax: &SyntaxNode, range: TextRange) -> Option { - find_covering_element(syntax, range).ancestors().find_map(N::cast) + syntax.covering_element(range).ancestors().find_map(N::cast) } fn is_node(node: &SyntaxNode) -> bool { diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index c62086390..467516eb7 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs @@ -118,7 +118,7 @@ pub fn expand_hypothetical( parse_macro_with_arg(db, macro_file, Some(std::sync::Arc::new((tt, tmap_1)))).value?; let token_id = macro_def.0.map_id_down(token_id); let range = tmap_2.range_by_token(token_id)?.by_kind(token_to_map.kind())?; - let token = syntax::algo::find_covering_element(&node.syntax_node(), range).into_token()?; + let token = node.syntax_node().covering_element(range).into_token()?; Some((node.syntax_node(), token)) } diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs index 3fa1b1d77..e388ddacc 100644 --- a/crates/hir_expand/src/lib.rs +++ b/crates/hir_expand/src/lib.rs @@ -22,7 +22,7 @@ use std::sync::Arc; use base_db::{impl_intern_key, salsa, CrateId, FileId, FileRange}; use syntax::{ - algo::{self, skip_trivia_token}, + algo::skip_trivia_token, ast::{self, AstNode}, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize, }; @@ -335,7 +335,7 @@ impl ExpansionInfo { let range = self.exp_map.range_by_token(token_id)?.by_kind(token.value.kind())?; - let token = algo::find_covering_element(&self.expanded.value, range).into_token()?; + let token = self.expanded.value.covering_element(range).into_token()?; Some(self.expanded.with_value(token)) } @@ -360,8 +360,8 @@ impl ExpansionInfo { }; let range = token_map.range_by_token(token_id)?.by_kind(token.value.kind())?; - let token = algo::find_covering_element(&tt.value, range + tt.value.text_range().start()) - .into_token()?; + let token = + tt.value.covering_element(range + tt.value.text_range().start()).into_token()?; Some((tt.with_value(token), origin)) } } diff --git a/crates/ide/src/extend_selection.rs b/crates/ide/src/extend_selection.rs index 56418c960..17a540972 100644 --- a/crates/ide/src/extend_selection.rs +++ b/crates/ide/src/extend_selection.rs @@ -3,7 +3,7 @@ use std::iter::successors; use hir::Semantics; use ide_db::RootDatabase; use syntax::{ - algo::{self, find_covering_element, skip_trivia_token}, + algo::{self, skip_trivia_token}, ast::{self, AstNode, AstToken}, Direction, NodeOrToken, SyntaxKind::{self, *}, @@ -76,7 +76,7 @@ fn try_extend_selection( }; return Some(leaf_range); }; - let node = match find_covering_element(root, range) { + let node = match root.covering_element(range) { NodeOrToken::Token(token) => { if token.text_range() != range { return Some(token.text_range()); @@ -120,7 +120,7 @@ fn extend_tokens_from_range( macro_call: ast::MacroCall, original_range: TextRange, ) -> Option { - let src = find_covering_element(¯o_call.syntax(), original_range); + let src = macro_call.syntax().covering_element(original_range); let (first_token, last_token) = match src { NodeOrToken::Node(it) => (it.first_token()?, it.last_token()?), NodeOrToken::Token(it) => (it.clone(), it), diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs index 05380f2a1..981467c8d 100644 --- a/crates/ide/src/join_lines.rs +++ b/crates/ide/src/join_lines.rs @@ -1,7 +1,7 @@ use assists::utils::extract_trivial_expression; use itertools::Itertools; use syntax::{ - algo::{find_covering_element, non_trivia_sibling}, + algo::non_trivia_sibling, ast::{self, AstNode, AstToken}, Direction, NodeOrToken, SourceFile, SyntaxKind::{self, USE_TREE, WHITESPACE}, @@ -31,7 +31,7 @@ pub(crate) fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit { range }; - let node = match find_covering_element(file.syntax(), range) { + let node = match file.syntax().covering_element(range) { NodeOrToken::Node(node) => node, NodeOrToken::Token(token) => token.parent(), }; diff --git a/crates/ide/src/syntax_tree.rs b/crates/ide/src/syntax_tree.rs index 1f26f8043..1d4bac7ad 100644 --- a/crates/ide/src/syntax_tree.rs +++ b/crates/ide/src/syntax_tree.rs @@ -1,7 +1,7 @@ use ide_db::base_db::{FileId, SourceDatabase}; use ide_db::RootDatabase; use syntax::{ - algo, AstNode, NodeOrToken, SourceFile, SyntaxKind::STRING, SyntaxToken, TextRange, TextSize, + AstNode, NodeOrToken, SourceFile, SyntaxKind::STRING, SyntaxToken, TextRange, TextSize, }; // Feature: Show Syntax Tree @@ -21,7 +21,7 @@ pub(crate) fn syntax_tree( ) -> String { let parse = db.parse(file_id); if let Some(text_range) = text_range { - let node = match algo::find_covering_element(parse.tree().syntax(), text_range) { + let node = match parse.tree().syntax().covering_element(text_range) { NodeOrToken::Node(node) => node, NodeOrToken::Token(token) => { if let Some(tree) = syntax_tree_for_string(&token, text_range) { diff --git a/crates/syntax/src/algo.rs b/crates/syntax/src/algo.rs index 384d031e7..1456270d0 100644 --- a/crates/syntax/src/algo.rs +++ b/crates/syntax/src/algo.rs @@ -45,7 +45,7 @@ pub fn find_node_at_offset(syntax: &SyntaxNode, offset: TextSize) -> } pub fn find_node_at_range(syntax: &SyntaxNode, range: TextRange) -> Option { - find_covering_element(syntax, range).ancestors().find_map(N::cast) + syntax.covering_element(range).ancestors().find_map(N::cast) } /// Skip to next non `trivia` token @@ -74,10 +74,6 @@ pub fn non_trivia_sibling(element: SyntaxElement, direction: Direction) -> Optio } } -pub fn find_covering_element(root: &SyntaxNode, range: TextRange) -> SyntaxElement { - root.covering_element(range) -} - pub fn least_common_ancestor(u: &SyntaxNode, v: &SyntaxNode) -> Option { if u == v { return Some(u.clone()); diff --git a/crates/syntax/src/parsing/reparsing.rs b/crates/syntax/src/parsing/reparsing.rs index 78eaf3410..76f01084c 100644 --- a/crates/syntax/src/parsing/reparsing.rs +++ b/crates/syntax/src/parsing/reparsing.rs @@ -10,7 +10,6 @@ use parser::Reparser; use text_edit::Indel; use crate::{ - algo, parsing::{ lexer::{lex_single_syntax_kind, tokenize, Token}, text_token_source::TextTokenSource, @@ -41,7 +40,7 @@ fn reparse_token<'node>( root: &'node SyntaxNode, edit: &Indel, ) -> Option<(GreenNode, Vec, TextRange)> { - let prev_token = algo::find_covering_element(root, edit.delete).as_token()?.clone(); + let prev_token = root.covering_element(edit.delete).as_token()?.clone(); let prev_token_kind = prev_token.kind(); match prev_token_kind { WHITESPACE | COMMENT | IDENT | STRING => { @@ -124,7 +123,7 @@ fn is_contextual_kw(text: &str) -> bool { } fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(SyntaxNode, Reparser)> { - let node = algo::find_covering_element(node, range); + let node = node.covering_element(range); let mut ancestors = match node { NodeOrToken::Token(it) => it.parent().ancestors(), -- cgit v1.2.3