mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 11:44:28 +00:00
Merge #7286
7286: Remove useless wrapper r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
a8587f153b
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<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 {
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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<TextRange> {
|
||||
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),
|
||||
|
@ -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(),
|
||||
};
|
||||
|
@ -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) {
|
||||
|
@ -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> {
|
||||
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<SyntaxNode> {
|
||||
if u == v {
|
||||
return Some(u.clone());
|
||||
|
@ -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<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();
|
||||
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(),
|
||||
|
Loading…
Reference in New Issue
Block a user