From 072028e67996162f5a9da14cfd59ed64de5e8729 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 28 Dec 2018 13:27:30 +0300 Subject: add macro-call node --- crates/ra_analysis/src/syntax_highlighting.rs | 6 ++-- crates/ra_syntax/src/ast/generated.rs | 41 +++++++++++++++++++++++++++ crates/ra_syntax/src/grammar.ron | 1 + 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/crates/ra_analysis/src/syntax_highlighting.rs b/crates/ra_analysis/src/syntax_highlighting.rs index 65409beb2..0bf19eea0 100644 --- a/crates/ra_analysis/src/syntax_highlighting.rs +++ b/crates/ra_analysis/src/syntax_highlighting.rs @@ -7,6 +7,8 @@ use crate::{ }; pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable> { - let file = db.source_file(file_id); - Ok(ra_editor::highlight(&file)) + let source_file = db.source_file(file_id); + let mut res = ra_editor::highlight(&source_file); + for node in source_file.syntax().descendants() {} + Ok(res) } diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index c22e026cf..b0d2c3e20 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -1838,6 +1838,47 @@ impl> LoopExprNode { impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {} impl<'a> LoopExpr<'a> {} +// MacroCall +#[derive(Debug, Clone, Copy,)] +pub struct MacroCallNode = OwnedRoot> { + pub(crate) syntax: SyntaxNode, +} +pub type MacroCall<'a> = MacroCallNode>; + +impl, R2: TreeRoot> PartialEq> for MacroCallNode { + fn eq(&self, other: &MacroCallNode) -> bool { self.syntax == other.syntax } +} +impl> Eq for MacroCallNode {} +impl> Hash for MacroCallNode { + fn hash(&self, state: &mut H) { self.syntax.hash(state) } +} + +impl<'a> AstNode<'a> for MacroCall<'a> { + fn cast(syntax: SyntaxNodeRef<'a>) -> Option { + match syntax.kind() { + MACRO_CALL => Some(MacroCall { syntax }), + _ => None, + } + } + fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } +} + +impl> MacroCallNode { + pub fn borrowed(&self) -> MacroCall { + MacroCallNode { syntax: self.syntax.borrowed() } + } + pub fn owned(&self) -> MacroCallNode { + MacroCallNode { syntax: self.syntax.owned() } + } +} + + +impl<'a> MacroCall<'a> { + pub fn token_tree(self) -> Option> { + super::child_opt(self) + } +} + // MatchArm #[derive(Debug, Clone, Copy,)] pub struct MatchArmNode = OwnedRoot> { diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 4bcff4e14..07b8433b2 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -484,6 +484,7 @@ Grammar( "Name": (), "NameRef": (), + "MacroCall": ( options: [ "TokenTree" ] ), "Attr": ( options: [ ["value", "TokenTree"] ] ), "TokenTree": (), "TypeParamList": ( -- cgit v1.2.3