mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
switch to upstream rowan's API
This commit is contained in:
parent
7bde8012cb
commit
c9cfd57eea
22 changed files with 208 additions and 738 deletions
|
@ -1,5 +1,4 @@
|
|||
use std::fmt::Write;
|
||||
|
||||
use format_buf::format;
|
||||
use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner};
|
||||
|
||||
pub(crate) trait ShortLabel {
|
||||
|
@ -73,7 +72,7 @@ where
|
|||
let mut buf = short_label_from_node(node, prefix)?;
|
||||
|
||||
if let Some(type_ref) = node.ascribed_type() {
|
||||
write!(buf, ": {}", type_ref.syntax()).unwrap();
|
||||
format!(buf, ": {}", type_ref.syntax());
|
||||
}
|
||||
|
||||
Some(buf)
|
||||
|
|
|
@ -2,7 +2,7 @@ use ra_db::SourceDatabase;
|
|||
use ra_syntax::{
|
||||
algo::{find_covering_element, find_token_at_offset, TokenAtOffset},
|
||||
ast::{self, AstNode, AstToken},
|
||||
Direction, SyntaxElement,
|
||||
Direction, NodeOrToken,
|
||||
SyntaxKind::*,
|
||||
SyntaxNode, SyntaxToken, TextRange, TextUnit, T,
|
||||
};
|
||||
|
@ -53,7 +53,7 @@ fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange
|
|||
return Some(leaf_range);
|
||||
};
|
||||
let node = match find_covering_element(root, range) {
|
||||
SyntaxElement::Token(token) => {
|
||||
NodeOrToken::Token(token) => {
|
||||
if token.text_range() != range {
|
||||
return Some(token.text_range());
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange
|
|||
}
|
||||
token.parent()
|
||||
}
|
||||
SyntaxElement::Node(node) => node,
|
||||
NodeOrToken::Node(node) => node,
|
||||
};
|
||||
if node.text_range() != range {
|
||||
return Some(node.text_range());
|
||||
|
@ -153,8 +153,8 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
|
|||
node.siblings_with_tokens(dir)
|
||||
.skip(1)
|
||||
.skip_while(|node| match node {
|
||||
SyntaxElement::Node(_) => false,
|
||||
SyntaxElement::Token(it) => is_single_line_ws(it),
|
||||
NodeOrToken::Node(_) => false,
|
||||
NodeOrToken::Token(it) => is_single_line_ws(it),
|
||||
})
|
||||
.next()
|
||||
.and_then(|it| it.into_token())
|
||||
|
|
|
@ -2,7 +2,7 @@ use rustc_hash::FxHashSet;
|
|||
|
||||
use ra_syntax::{
|
||||
ast::{self, AstNode, AstToken, VisibilityOwner},
|
||||
Direction, SourceFile, SyntaxElement,
|
||||
Direction, NodeOrToken, SourceFile,
|
||||
SyntaxKind::{self, *},
|
||||
SyntaxNode, TextRange,
|
||||
};
|
||||
|
@ -31,8 +31,8 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
|
|||
// Fold items that span multiple lines
|
||||
if let Some(kind) = fold_kind(element.kind()) {
|
||||
let is_multiline = match &element {
|
||||
SyntaxElement::Node(node) => node.text().contains_char('\n'),
|
||||
SyntaxElement::Token(token) => token.text().contains('\n'),
|
||||
NodeOrToken::Node(node) => node.text().contains_char('\n'),
|
||||
NodeOrToken::Token(token) => token.text().contains('\n'),
|
||||
};
|
||||
if is_multiline {
|
||||
res.push(Fold { range: element.text_range(), kind });
|
||||
|
@ -41,7 +41,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
|
|||
}
|
||||
|
||||
match element {
|
||||
SyntaxElement::Token(token) => {
|
||||
NodeOrToken::Token(token) => {
|
||||
// Fold groups of comments
|
||||
if let Some(comment) = ast::Comment::cast(token) {
|
||||
if !visited_comments.contains(&comment) {
|
||||
|
@ -53,7 +53,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
|
|||
}
|
||||
}
|
||||
}
|
||||
SyntaxElement::Node(node) => {
|
||||
NodeOrToken::Node(node) => {
|
||||
// Fold groups of imports
|
||||
if node.kind() == USE_ITEM && !visited_imports.contains(&node) {
|
||||
if let Some(range) = contiguous_range_for_group(&node, &mut visited_imports) {
|
||||
|
@ -108,7 +108,7 @@ fn contiguous_range_for_group_unless(
|
|||
let mut last = first.clone();
|
||||
for element in first.siblings_with_tokens(Direction::Next) {
|
||||
let node = match element {
|
||||
SyntaxElement::Token(token) => {
|
||||
NodeOrToken::Token(token) => {
|
||||
if let Some(ws) = ast::Whitespace::cast(token) {
|
||||
if !ws.spans_multiple_lines() {
|
||||
// Ignore whitespace without blank lines
|
||||
|
@ -119,7 +119,7 @@ fn contiguous_range_for_group_unless(
|
|||
// group ends here
|
||||
break;
|
||||
}
|
||||
SyntaxElement::Node(node) => node,
|
||||
NodeOrToken::Node(node) => node,
|
||||
};
|
||||
|
||||
// Stop if we find a node that doesn't belong to the group
|
||||
|
@ -154,7 +154,7 @@ fn contiguous_range_for_comment(
|
|||
let mut last = first.clone();
|
||||
for element in first.syntax().siblings_with_tokens(Direction::Next) {
|
||||
match element {
|
||||
SyntaxElement::Token(token) => {
|
||||
NodeOrToken::Token(token) => {
|
||||
if let Some(ws) = ast::Whitespace::cast(token.clone()) {
|
||||
if !ws.spans_multiple_lines() {
|
||||
// Ignore whitespace without blank lines
|
||||
|
@ -173,7 +173,7 @@ fn contiguous_range_for_comment(
|
|||
// * A comment of a different flavor was reached
|
||||
break;
|
||||
}
|
||||
SyntaxElement::Node(_) => break,
|
||||
NodeOrToken::Node(_) => break,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use ra_fmt::{compute_ws, extract_trivial_expression};
|
|||
use ra_syntax::{
|
||||
algo::{find_covering_element, non_trivia_sibling},
|
||||
ast::{self, AstNode, AstToken},
|
||||
Direction, SourceFile, SyntaxElement,
|
||||
Direction, NodeOrToken, SourceFile,
|
||||
SyntaxKind::{self, WHITESPACE},
|
||||
SyntaxNode, SyntaxToken, TextRange, TextUnit, T,
|
||||
};
|
||||
|
@ -23,8 +23,8 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
|
|||
};
|
||||
|
||||
let node = match find_covering_element(file.syntax(), range) {
|
||||
SyntaxElement::Node(node) => node,
|
||||
SyntaxElement::Token(token) => token.parent(),
|
||||
NodeOrToken::Node(node) => node,
|
||||
NodeOrToken::Token(token) => token.parent(),
|
||||
};
|
||||
let mut edit = TextEditBuilder::default();
|
||||
for token in node.descendants_with_tokens().filter_map(|it| it.into_token()) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::db::RootDatabase;
|
||||
use ra_db::SourceDatabase;
|
||||
use ra_syntax::{
|
||||
algo, AstNode, SourceFile, SyntaxElement,
|
||||
algo, AstNode, NodeOrToken, SourceFile,
|
||||
SyntaxKind::{RAW_STRING, STRING},
|
||||
SyntaxToken, TextRange,
|
||||
};
|
||||
|
@ -16,8 +16,8 @@ pub(crate) fn syntax_tree(
|
|||
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) {
|
||||
SyntaxElement::Node(node) => node,
|
||||
SyntaxElement::Token(token) => {
|
||||
NodeOrToken::Node(node) => node,
|
||||
NodeOrToken::Token(token) => {
|
||||
if let Some(tree) = syntax_tree_for_string(&token, text_range) {
|
||||
return tree;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue