From 379482068d6ef985df5260473cac9d42331a6104 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 3 Dec 2019 12:03:35 -0500 Subject: Add `ModuleItemsOwner` to `Block` --- crates/ra_syntax/src/ast/generated.rs | 1 + crates/ra_syntax/src/grammar.ron | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index c06076e3d..9dd6bd3ea 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -312,6 +312,7 @@ impl AstNode for Block { } } impl ast::AttrsOwner for Block {} +impl ast::ModuleItemOwner for Block {} impl Block { pub fn statements(&self) -> AstChildren { AstChildren::new(&self.syntax) diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index d1be40abe..9ffa9095b 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -653,6 +653,7 @@ Grammar( ], traits: [ "AttrsOwner", + "ModuleItemOwner", ] ), "ParamList": ( @@ -664,14 +665,14 @@ Grammar( "SelfParam": ( traits: [ "TypeAscriptionOwner", - "AttrsOwner", + "AttrsOwner", ] ), "Param": ( options: [ "Pat" ], traits: [ "TypeAscriptionOwner", - "AttrsOwner", + "AttrsOwner", ] ), "UseItem": ( -- cgit v1.2.3 From 193b1a7437c97064a51f0c30a175665b5d6c9895 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 4 Dec 2019 17:15:55 +0100 Subject: :arrow_up: rowan --- crates/ra_syntax/src/algo.rs | 12 ++++++------ crates/ra_syntax/src/syntax_node.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index 1c075082a..e4061e994 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs @@ -140,13 +140,13 @@ pub fn insert_children( }); let new_children = match &position { - InsertPosition::First => to_insert.chain(old_children).collect::>(), - InsertPosition::Last => old_children.chain(to_insert).collect::>(), + InsertPosition::First => to_insert.chain(old_children).collect::>(), + InsertPosition::Last => old_children.chain(to_insert).collect::>(), InsertPosition::Before(anchor) | InsertPosition::After(anchor) => { let take_anchor = if let InsertPosition::After(_) = position { 1 } else { 0 }; let split_at = position_of_child(parent, anchor.clone()) + take_anchor; let before = old_children.by_ref().take(split_at).collect::>(); - before.into_iter().chain(to_insert).chain(old_children).collect::>() + before.into_iter().chain(to_insert).chain(old_children).collect::>() } }; @@ -174,7 +174,7 @@ pub fn replace_children( .into_iter() .chain(to_insert.map(to_green_element)) .chain(old_children.skip(end + 1 - start)) - .collect::>(); + .collect::>(); with_children(parent, new_children) } @@ -187,7 +187,7 @@ pub fn replace_descendants( map: &FxHashMap, ) -> SyntaxNode { // FIXME: this could be made much faster. - let new_children = parent.children_with_tokens().map(|it| go(map, it)).collect::>(); + let new_children = parent.children_with_tokens().map(|it| go(map, it)).collect::>(); return with_children(parent, new_children); fn go( @@ -211,7 +211,7 @@ pub fn replace_descendants( fn with_children( parent: &SyntaxNode, - new_children: Box<[NodeOrToken]>, + new_children: Vec>, ) -> SyntaxNode { let len = new_children.iter().map(|it| it.text_len()).sum::(); let new_node = diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index b2f5b8c64..041c6ea8d 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs @@ -40,7 +40,7 @@ pub use rowan::{Direction, NodeOrToken}; pub struct SyntaxTreeBuilder { errors: Vec, - inner: GreenNodeBuilder, + inner: GreenNodeBuilder<'static>, } impl Default for SyntaxTreeBuilder { -- cgit v1.2.3 From 8c86963d47953045f2f33ee6620d305a6589641e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 5 Dec 2019 23:34:12 +0100 Subject: DynMap This might, or might not help us to reduce boilerplate associated with plumbing values from analysis to the IDE layer --- crates/ra_syntax/src/ptr.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index e049fce61..db6230aab 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs @@ -1,6 +1,10 @@ //! FIXME: write short doc here -use std::{iter::successors, marker::PhantomData}; +use std::{ + hash::{Hash, Hasher}, + iter::successors, + marker::PhantomData, +}; use crate::{AstNode, SyntaxKind, SyntaxNode, TextRange}; @@ -43,7 +47,7 @@ impl SyntaxNodePtr { } /// Like `SyntaxNodePtr`, but remembers the type of node -#[derive(Debug, Hash)] +#[derive(Debug)] pub struct AstPtr { raw: SyntaxNodePtr, _ty: PhantomData N>, @@ -64,6 +68,12 @@ impl PartialEq for AstPtr { } } +impl Hash for AstPtr { + fn hash(&self, state: &mut H) { + self.raw.hash(state) + } +} + impl AstPtr { pub fn new(node: &N) -> AstPtr { AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } -- cgit v1.2.3 From f22aabc1360eb7e900a4495bc68f3302c7c49a7c Mon Sep 17 00:00:00 2001 From: kjeremy Date: Fri, 20 Dec 2019 09:43:30 -0500 Subject: Use unwrap_or_default --- crates/ra_syntax/src/ast/edit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 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 95bf9db14..ae5d63927 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -104,7 +104,7 @@ impl ast::ItemList { } }; - let indent = leading_indent(self.syntax()).unwrap_or("".into()); + let indent = leading_indent(self.syntax()).unwrap_or_default(); let ws = tokens::WsBuilder::new(&format!("\n{}", indent)); let to_insert = iter::once(ws.ws().into()); match existing_ws { @@ -133,7 +133,7 @@ impl ast::RecordFieldList { let space = if is_multiline { ws = tokens::WsBuilder::new(&format!( "\n{} ", - leading_indent(self.syntax()).unwrap_or("".into()) + leading_indent(self.syntax()).unwrap_or_default() )); ws.ws() } else { -- cgit v1.2.3 From 2a8c9100bfb1294a469bc039a5b9597eabed7073 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 20 Dec 2019 16:41:32 +0100 Subject: Handle closure return types Fixes #2547. --- crates/ra_syntax/src/ast/generated.rs | 3 +++ crates/ra_syntax/src/grammar.ron | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 9dd6bd3ea..8d65e2e08 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -1426,6 +1426,9 @@ impl LambdaExpr { pub fn param_list(&self) -> Option { AstChildren::new(&self.syntax).next() } + pub fn ret_type(&self) -> Option { + AstChildren::new(&self.syntax).next() + } pub fn body(&self) -> Option { AstChildren::new(&self.syntax).next() } diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 9ffa9095b..a228fa9d6 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -426,7 +426,7 @@ Grammar( "PathExpr": (options: ["Path"]), "LambdaExpr": ( options: [ - "ParamList", + "ParamList", "RetType", ["body", "Expr"], ] ), -- cgit v1.2.3 From 0d5d63a80ea08f2af439bcc72fff9b24d144c70d Mon Sep 17 00:00:00 2001 From: kjeremy Date: Fri, 20 Dec 2019 15:14:30 -0500 Subject: Clippy lints --- crates/ra_syntax/src/ast/make.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 40db570da..04a5408fe 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -168,8 +168,7 @@ pub fn let_stmt(pattern: ast::Pat, initializer: Option) -> ast::LetSt fn ast_from_text(text: &str) -> N { let parse = SourceFile::parse(text); - let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); - res + parse.tree().syntax().descendants().find_map(N::cast).unwrap() } pub mod tokens { -- cgit v1.2.3 From bea8f581186bb8d933357599468dd7d862ae847b Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 21 Dec 2019 18:29:14 +0800 Subject: Add macro 2.0 support in parser --- crates/ra_syntax/src/grammar.ron | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index a228fa9d6..3f1cd0b90 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -94,7 +94,8 @@ Grammar( "return", "try", "box", - "await" + "await", + "macro" ], contextual_keywords: [ "auto", @@ -140,6 +141,7 @@ Grammar( "TYPE_ALIAS_DEF", "MACRO_CALL", "TOKEN_TREE", + "MACRO_DEF", "PAREN_TYPE", "TUPLE_TYPE", -- cgit v1.2.3 From b04d4a88d1ba7f04445e807b6a816930b1e9bbf2 Mon Sep 17 00:00:00 2001 From: roblabla Date: Sun, 22 Dec 2019 00:38:23 +0000 Subject: Parse const generics Fixes #1574 Fixes #2281 --- crates/ra_syntax/src/ast/generated.rs | 30 ++++++++++++++++++++++++++++++ crates/ra_syntax/src/grammar.ron | 5 +++++ 2 files changed, 35 insertions(+) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 9dd6bd3ea..b917f77fe 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -551,6 +551,36 @@ impl ConstDef { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct ConstParam { + pub(crate) syntax: SyntaxNode, +} +impl AstNode for ConstParam { + fn can_cast(kind: SyntaxKind) -> bool { + match kind { + CONST_PARAM => true, + _ => false, + } + } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { + &self.syntax + } +} +impl ast::NameOwner for ConstParam {} +impl ast::AttrsOwner for ConstParam {} +impl ast::TypeAscriptionOwner for ConstParam {} +impl ConstParam { + pub fn default_val(&self) -> Option { + AstChildren::new(&self.syntax).next() + } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ContinueExpr { pub(crate) syntax: SyntaxNode, } diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 9ffa9095b..d6802b6fb 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -243,6 +243,7 @@ Grammar( "TYPE_PARAM_LIST", "LIFETIME_PARAM", "TYPE_PARAM", + "CONST_PARAM", "TYPE_ARG_LIST", "LIFETIME_ARG", "TYPE_ARG", @@ -602,6 +603,10 @@ Grammar( options: [("default_type", "TypeRef")], traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"], ), + "ConstParam": ( + options: [("default_val", "Expr")], + traits: ["NameOwner", "AttrsOwner", "TypeAscriptionOwner"], + ), "LifetimeParam": ( traits: ["AttrsOwner"], ), -- cgit v1.2.3