mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Merge commit '426d2842c1
' into sync-from-ra2
This commit is contained in:
parent
e37cf75791
commit
932d85b529
240 changed files with 6941 additions and 3102 deletions
|
@ -11,7 +11,7 @@ use rowan::{GreenNodeData, GreenTokenData};
|
|||
|
||||
use crate::{
|
||||
ast::{self, support, AstNode, AstToken, HasAttrs, HasGenericParams, HasName, SyntaxNode},
|
||||
NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T,
|
||||
ted, NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T,
|
||||
};
|
||||
|
||||
impl ast::Lifetime {
|
||||
|
@ -323,6 +323,10 @@ impl ast::UseTree {
|
|||
pub fn is_simple_path(&self) -> bool {
|
||||
self.use_tree_list().is_none() && self.star_token().is_none()
|
||||
}
|
||||
|
||||
pub fn parent_use_tree_list(&self) -> Option<ast::UseTreeList> {
|
||||
self.syntax().parent().and_then(ast::UseTreeList::cast)
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::UseTreeList {
|
||||
|
@ -340,6 +344,34 @@ impl ast::UseTreeList {
|
|||
.find_map(ast::Comment::cast)
|
||||
.is_some()
|
||||
}
|
||||
|
||||
pub fn comma(&self) -> impl Iterator<Item = SyntaxToken> {
|
||||
self.syntax()
|
||||
.children_with_tokens()
|
||||
.filter_map(|it| it.into_token().filter(|it| it.kind() == T![,]))
|
||||
}
|
||||
|
||||
/// Remove the unnecessary braces in current `UseTreeList`
|
||||
pub fn remove_unnecessary_braces(mut self) {
|
||||
let remove_brace_in_use_tree_list = |u: &ast::UseTreeList| {
|
||||
let use_tree_count = u.use_trees().count();
|
||||
if use_tree_count == 1 {
|
||||
u.l_curly_token().map(ted::remove);
|
||||
u.r_curly_token().map(ted::remove);
|
||||
u.comma().for_each(ted::remove);
|
||||
}
|
||||
};
|
||||
|
||||
// take `use crate::{{{{A}}}}` for example
|
||||
// the below remove the innermost {}, got `use crate::{{{A}}}`
|
||||
remove_brace_in_use_tree_list(&self);
|
||||
|
||||
// the below remove othe unnecessary {}, got `use crate::A`
|
||||
while let Some(parent_use_tree_list) = self.parent_use_tree().parent_use_tree_list() {
|
||||
remove_brace_in_use_tree_list(&parent_use_tree_list);
|
||||
self = parent_use_tree_list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Impl {
|
||||
|
@ -585,6 +617,16 @@ impl ast::Item {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::Type {
|
||||
pub fn generic_arg_list(&self) -> Option<ast::GenericArgList> {
|
||||
if let ast::Type::PathType(path_type) = self {
|
||||
path_type.path()?.segment()?.generic_arg_list()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum FieldKind {
|
||||
Name(ast::NameRef),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue