7286: Remove useless wrapper r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2021-01-15 17:16:27 +00:00 committed by GitHub
commit a8587f153b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 28 deletions

View file

@ -2,7 +2,6 @@
use std::mem; use std::mem;
use algo::find_covering_element;
use hir::Semantics; use hir::Semantics;
use ide_db::{ use ide_db::{
base_db::{AnchoredPathBuf, FileId, FileRange}, 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()) self.sema.find_node_at_offset_with_descend(self.source_file.syntax(), self.offset())
} }
pub(crate) fn covering_element(&self) -> SyntaxElement { 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 // FIXME: remove
pub(crate) fn covering_node_for_range(&self, range: TextRange) -> SyntaxElement { 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)
} }
} }

View file

@ -4,10 +4,8 @@ use hir::{Local, ScopeDef, Semantics, SemanticsScope, Type};
use ide_db::base_db::{FilePosition, SourceDatabase}; use ide_db::base_db::{FilePosition, SourceDatabase};
use ide_db::{call_info::ActiveParameter, RootDatabase}; use ide_db::{call_info::ActiveParameter, RootDatabase};
use syntax::{ use syntax::{
algo::{find_covering_element, find_node_at_offset}, algo::find_node_at_offset, ast, match_ast, AstNode, NodeOrToken, SyntaxKind::*, SyntaxNode,
ast, match_ast, AstNode, NodeOrToken, SyntaxToken, TextRange, TextSize,
SyntaxKind::*,
SyntaxNode, SyntaxToken, TextRange, TextSize,
}; };
use test_utils::mark; use test_utils::mark;
use text_edit::Indel; use text_edit::Indel;
@ -513,7 +511,7 @@ impl<'a> CompletionContext<'a> {
} }
fn find_node_with_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<N> { fn find_node_with_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<N> {
find_covering_element(syntax, range).ancestors().find_map(N::cast) syntax.covering_element(range).ancestors().find_map(N::cast)
} }
fn is_node<N: AstNode>(node: &SyntaxNode) -> bool { fn is_node<N: AstNode>(node: &SyntaxNode) -> bool {

View file

@ -118,7 +118,7 @@ pub fn expand_hypothetical(
parse_macro_with_arg(db, macro_file, Some(std::sync::Arc::new((tt, tmap_1)))).value?; 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 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 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)) Some((node.syntax_node(), token))
} }

View file

@ -22,7 +22,7 @@ use std::sync::Arc;
use base_db::{impl_intern_key, salsa, CrateId, FileId, FileRange}; use base_db::{impl_intern_key, salsa, CrateId, FileId, FileRange};
use syntax::{ use syntax::{
algo::{self, skip_trivia_token}, algo::skip_trivia_token,
ast::{self, AstNode}, ast::{self, AstNode},
Direction, SyntaxNode, SyntaxToken, TextRange, TextSize, 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 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)) 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 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()) let token =
.into_token()?; tt.value.covering_element(range + tt.value.text_range().start()).into_token()?;
Some((tt.with_value(token), origin)) Some((tt.with_value(token), origin))
} }
} }

View file

@ -3,7 +3,7 @@ use std::iter::successors;
use hir::Semantics; use hir::Semantics;
use ide_db::RootDatabase; use ide_db::RootDatabase;
use syntax::{ use syntax::{
algo::{self, find_covering_element, skip_trivia_token}, algo::{self, skip_trivia_token},
ast::{self, AstNode, AstToken}, ast::{self, AstNode, AstToken},
Direction, NodeOrToken, Direction, NodeOrToken,
SyntaxKind::{self, *}, SyntaxKind::{self, *},
@ -76,7 +76,7 @@ fn try_extend_selection(
}; };
return Some(leaf_range); return Some(leaf_range);
}; };
let node = match find_covering_element(root, range) { let node = match root.covering_element(range) {
NodeOrToken::Token(token) => { NodeOrToken::Token(token) => {
if token.text_range() != range { if token.text_range() != range {
return Some(token.text_range()); return Some(token.text_range());
@ -120,7 +120,7 @@ fn extend_tokens_from_range(
macro_call: ast::MacroCall, macro_call: ast::MacroCall,
original_range: TextRange, original_range: TextRange,
) -> Option<TextRange> { ) -> Option<TextRange> {
let src = find_covering_element(&macro_call.syntax(), original_range); let src = macro_call.syntax().covering_element(original_range);
let (first_token, last_token) = match src { let (first_token, last_token) = match src {
NodeOrToken::Node(it) => (it.first_token()?, it.last_token()?), NodeOrToken::Node(it) => (it.first_token()?, it.last_token()?),
NodeOrToken::Token(it) => (it.clone(), it), NodeOrToken::Token(it) => (it.clone(), it),

View file

@ -1,7 +1,7 @@
use assists::utils::extract_trivial_expression; use assists::utils::extract_trivial_expression;
use itertools::Itertools; use itertools::Itertools;
use syntax::{ use syntax::{
algo::{find_covering_element, non_trivia_sibling}, algo::non_trivia_sibling,
ast::{self, AstNode, AstToken}, ast::{self, AstNode, AstToken},
Direction, NodeOrToken, SourceFile, Direction, NodeOrToken, SourceFile,
SyntaxKind::{self, USE_TREE, WHITESPACE}, SyntaxKind::{self, USE_TREE, WHITESPACE},
@ -31,7 +31,7 @@ pub(crate) fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
range range
}; };
let node = match find_covering_element(file.syntax(), range) { let node = match file.syntax().covering_element(range) {
NodeOrToken::Node(node) => node, NodeOrToken::Node(node) => node,
NodeOrToken::Token(token) => token.parent(), NodeOrToken::Token(token) => token.parent(),
}; };

View file

@ -1,7 +1,7 @@
use ide_db::base_db::{FileId, SourceDatabase}; use ide_db::base_db::{FileId, SourceDatabase};
use ide_db::RootDatabase; use ide_db::RootDatabase;
use syntax::{ use syntax::{
algo, AstNode, NodeOrToken, SourceFile, SyntaxKind::STRING, SyntaxToken, TextRange, TextSize, AstNode, NodeOrToken, SourceFile, SyntaxKind::STRING, SyntaxToken, TextRange, TextSize,
}; };
// Feature: Show Syntax Tree // Feature: Show Syntax Tree
@ -21,7 +21,7 @@ pub(crate) fn syntax_tree(
) -> String { ) -> String {
let parse = db.parse(file_id); let parse = db.parse(file_id);
if let Some(text_range) = text_range { 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::Node(node) => node,
NodeOrToken::Token(token) => { NodeOrToken::Token(token) => {
if let Some(tree) = syntax_tree_for_string(&token, text_range) { if let Some(tree) = syntax_tree_for_string(&token, text_range) {

View file

@ -45,7 +45,7 @@ pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextSize) ->
} }
pub fn find_node_at_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<N> { pub fn find_node_at_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<N> {
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 /// 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<SyntaxNode> { pub fn least_common_ancestor(u: &SyntaxNode, v: &SyntaxNode) -> Option<SyntaxNode> {
if u == v { if u == v {
return Some(u.clone()); return Some(u.clone());

View file

@ -10,7 +10,6 @@ use parser::Reparser;
use text_edit::Indel; use text_edit::Indel;
use crate::{ use crate::{
algo,
parsing::{ parsing::{
lexer::{lex_single_syntax_kind, tokenize, Token}, lexer::{lex_single_syntax_kind, tokenize, Token},
text_token_source::TextTokenSource, text_token_source::TextTokenSource,
@ -41,7 +40,7 @@ fn reparse_token<'node>(
root: &'node SyntaxNode, root: &'node SyntaxNode,
edit: &Indel, edit: &Indel,
) -> Option<(GreenNode, Vec<SyntaxError>, TextRange)> { ) -> Option<(GreenNode, Vec<SyntaxError>, 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(); let prev_token_kind = prev_token.kind();
match prev_token_kind { match prev_token_kind {
WHITESPACE | COMMENT | IDENT | STRING => { 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)> { 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 { let mut ancestors = match node {
NodeOrToken::Token(it) => it.parent().ancestors(), NodeOrToken::Token(it) => it.parent().ancestors(),