From 35e7966ebeee70ca2c15b5139b5c1918d9ef4086 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:06:04 +0200 Subject: Add comma list to use tree --- crates/ra_syntax/src/ast/generated/nodes.rs | 155 ++++++++++++++-------------- 1 file changed, 78 insertions(+), 77 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 3fd761367..9d8127a3d 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -268,6 +268,36 @@ pub struct Rename { impl ast::NameOwner for Rename {} impl Rename { pub fn as_token(&self) -> Option { support::token(&self.syntax, T![as]) } + pub fn underscore_token(&self) -> Option { support::token(&self.syntax, T![_]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct UseTree { + pub(crate) syntax: SyntaxNode, +} +impl UseTree { + pub fn path(&self) -> Option { support::child(&self.syntax) } + pub fn coloncolon_token(&self) -> Option { support::token(&self.syntax, T![::]) } + pub fn star_token(&self) -> Option { support::token(&self.syntax, T![*]) } + pub fn use_tree_list(&self) -> Option { support::child(&self.syntax) } + pub fn rename(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Path { + pub(crate) syntax: SyntaxNode, +} +impl Path { + pub fn qualifier(&self) -> Option { support::child(&self.syntax) } + pub fn coloncolon_token(&self) -> Option { support::token(&self.syntax, T![::]) } + pub fn segment(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct UseTreeList { + pub(crate) syntax: SyntaxNode, +} +impl UseTreeList { + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } + pub fn use_trees(&self) -> AstChildren { support::children(&self.syntax) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Abi { @@ -433,15 +463,6 @@ impl PathType { pub fn path(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Path { - pub(crate) syntax: SyntaxNode, -} -impl Path { - pub fn qualifier(&self) -> Option { support::child(&self.syntax) } - pub fn coloncolon_token(&self) -> Option { support::token(&self.syntax, T![::]) } - pub fn segment(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PointerType { pub(crate) syntax: SyntaxNode, } @@ -1178,26 +1199,6 @@ impl Param { pub fn dotdotdot_token(&self) -> Option { support::token(&self.syntax, T![...]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UseTree { - pub(crate) syntax: SyntaxNode, -} -impl UseTree { - pub fn path(&self) -> Option { support::child(&self.syntax) } - pub fn coloncolon_token(&self) -> Option { support::token(&self.syntax, T![::]) } - pub fn star_token(&self) -> Option { support::token(&self.syntax, T![*]) } - pub fn use_tree_list(&self) -> Option { support::child(&self.syntax) } - pub fn rename(&self) -> Option { support::child(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UseTreeList { - pub(crate) syntax: SyntaxNode, -} -impl UseTreeList { - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn use_trees(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PathSegment { pub(crate) syntax: SyntaxNode, } @@ -1627,6 +1628,39 @@ impl AstNode for Rename { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for UseTree { + fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for Path { + fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for UseTreeList { + fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for Abi { fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } fn cast(syntax: SyntaxNode) -> Option { @@ -1825,17 +1859,6 @@ impl AstNode for PathType { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Path { - fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for PointerType { fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE } fn cast(syntax: SyntaxNode) -> Option { @@ -2672,28 +2695,6 @@ impl AstNode for Param { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for UseTree { - fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for UseTreeList { - fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for PathSegment { fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT } fn cast(syntax: SyntaxNode) -> Option { @@ -3560,6 +3561,21 @@ impl std::fmt::Display for Rename { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for UseTree { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for Path { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for UseTreeList { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for Abi { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3650,11 +3666,6 @@ impl std::fmt::Display for PathType { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Path { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for PointerType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -4035,16 +4046,6 @@ impl std::fmt::Display for Param { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for UseTree { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl std::fmt::Display for UseTreeList { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for PathSegment { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) -- cgit v1.2.3 From 9697d23cbe7b0ad897139b15f1b1ffe1cab6ad89 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:12:04 +0200 Subject: Rename UseItem -> Use --- crates/ra_syntax/src/ast/edit.rs | 4 ++-- crates/ra_syntax/src/ast/generated/nodes.rs | 29 +++++++++++++++-------------- crates/ra_syntax/src/ast/make.rs | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 2e958fa23..6ebe10ff6 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -262,9 +262,9 @@ impl ast::PathSegment { } } -impl ast::UseItem { +impl ast::Use { #[must_use] - pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem { + pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::Use { if let Some(old) = self.use_tree() { return self.replace_descendant(old, use_tree); } diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 9d8127a3d..be657699f 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -213,12 +213,12 @@ impl UnionDef { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UseItem { +pub struct Use { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for UseItem {} -impl ast::VisibilityOwner for UseItem {} -impl UseItem { +impl ast::AttrsOwner for Use {} +impl ast::VisibilityOwner for Use {} +impl Use { pub fn use_token(&self) -> Option { support::token(&self.syntax, T![use]) } pub fn use_tree(&self) -> Option { support::child(&self.syntax) } pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } @@ -1283,7 +1283,7 @@ pub enum Item { TraitDef(TraitDef), TypeAliasDef(TypeAliasDef), UnionDef(UnionDef), - UseItem(UseItem), + Use(Use), } impl ast::AttrsOwner for Item {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1562,8 +1562,8 @@ impl AstNode for UnionDef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for UseItem { - fn can_cast(kind: SyntaxKind) -> bool { kind == USE_ITEM } +impl AstNode for Use { + fn can_cast(kind: SyntaxKind) -> bool { kind == USE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2811,15 +2811,16 @@ impl From for Item { impl From for Item { fn from(node: UnionDef) -> Item { Item::UnionDef(node) } } -impl From for Item { - fn from(node: UseItem) -> Item { Item::UseItem(node) } +impl From for Item { + fn from(node: Use) -> Item { Item::Use(node) } } impl AstNode for Item { fn can_cast(kind: SyntaxKind) -> bool { match kind { CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE | FN_DEF | IMPL_DEF | MACRO_CALL - | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF - | USE_ITEM => true, + | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF | USE => { + true + } _ => false, } } @@ -2838,7 +2839,7 @@ impl AstNode for Item { TRAIT_DEF => Item::TraitDef(TraitDef { syntax }), TYPE_ALIAS_DEF => Item::TypeAliasDef(TypeAliasDef { syntax }), UNION_DEF => Item::UnionDef(UnionDef { syntax }), - USE_ITEM => Item::UseItem(UseItem { syntax }), + USE => Item::Use(Use { syntax }), _ => return None, }; Some(res) @@ -2858,7 +2859,7 @@ impl AstNode for Item { Item::TraitDef(it) => &it.syntax, Item::TypeAliasDef(it) => &it.syntax, Item::UnionDef(it) => &it.syntax, - Item::UseItem(it) => &it.syntax, + Item::Use(it) => &it.syntax, } } } @@ -3531,7 +3532,7 @@ impl std::fmt::Display for UnionDef { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for UseItem { +impl std::fmt::Display for Use { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 2b05ed2d4..0ff69bc2d 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -60,7 +60,7 @@ pub fn use_tree_list(use_trees: impl IntoIterator) -> ast:: ast_from_text(&format!("use {{{}}};", use_trees)) } -pub fn use_item(use_tree: ast::UseTree) -> ast::UseItem { +pub fn use_item(use_tree: ast::UseTree) -> ast::Use { ast_from_text(&format!("use {};", use_tree)) } -- cgit v1.2.3