diff options
author | Aleksey Kladov <[email protected]> | 2019-07-18 21:19:04 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-07-18 21:19:04 +0100 |
commit | df33e7685bdb0f63bf6aa809b9046708d563a1a7 (patch) | |
tree | 2336c03a0eeef98ac375868bd27dfe7e50668869 /crates/ra_hir/src | |
parent | a6224f36200c768d49b6450204fd95edaa559b50 (diff) |
use Parse in mbe
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 14 |
2 files changed, 9 insertions, 9 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 040c782e6..da9f3e32d 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -2,7 +2,7 @@ use std::sync::Arc; | |||
2 | 2 | ||
3 | use parking_lot::Mutex; | 3 | use parking_lot::Mutex; |
4 | use ra_db::{salsa, SourceDatabase}; | 4 | use ra_db::{salsa, SourceDatabase}; |
5 | use ra_syntax::{ast, SmolStr, SyntaxNode, TreeArc}; | 5 | use ra_syntax::{ast, Parse, SmolStr, SyntaxNode, TreeArc}; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | adt::{EnumData, StructData}, | 8 | adt::{EnumData, StructData}, |
@@ -69,7 +69,7 @@ pub trait AstDatabase: InternDatabase { | |||
69 | fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>; | 69 | fn parse_or_expand(&self, file_id: HirFileId) -> Option<TreeArc<SyntaxNode>>; |
70 | 70 | ||
71 | #[salsa::invoke(crate::ids::HirFileId::parse_macro_query)] | 71 | #[salsa::invoke(crate::ids::HirFileId::parse_macro_query)] |
72 | fn parse_macro(&self, macro_file: ids::MacroFile) -> Option<TreeArc<SyntaxNode>>; | 72 | fn parse_macro(&self, macro_file: ids::MacroFile) -> Option<Parse<SyntaxNode>>; |
73 | 73 | ||
74 | #[salsa::invoke(crate::ids::macro_def_query)] | 74 | #[salsa::invoke(crate::ids::macro_def_query)] |
75 | fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>; | 75 | fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>; |
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 80e9cccd6..83f5c3f39 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -6,7 +6,7 @@ use std::{ | |||
6 | use mbe::MacroRules; | 6 | use mbe::MacroRules; |
7 | use ra_db::{salsa, FileId}; | 7 | use ra_db::{salsa, FileId}; |
8 | use ra_prof::profile; | 8 | use ra_prof::profile; |
9 | use ra_syntax::{ast, AstNode, SyntaxNode, TreeArc}; | 9 | use ra_syntax::{ast, AstNode, Parse, SyntaxNode, TreeArc}; |
10 | 10 | ||
11 | use crate::{AstDatabase, AstId, DefDatabase, FileAstId, InternDatabase, Module, Source}; | 11 | use crate::{AstDatabase, AstId, DefDatabase, FileAstId, InternDatabase, Module, Source}; |
12 | 12 | ||
@@ -61,14 +61,16 @@ impl HirFileId { | |||
61 | ) -> Option<TreeArc<SyntaxNode>> { | 61 | ) -> Option<TreeArc<SyntaxNode>> { |
62 | match file_id.0 { | 62 | match file_id.0 { |
63 | HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree().syntax().to_owned()), | 63 | HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree().syntax().to_owned()), |
64 | HirFileIdRepr::Macro(macro_file) => db.parse_macro(macro_file), | 64 | HirFileIdRepr::Macro(macro_file) => { |
65 | db.parse_macro(macro_file).map(|it| it.tree().to_owned()) | ||
66 | } | ||
65 | } | 67 | } |
66 | } | 68 | } |
67 | 69 | ||
68 | pub(crate) fn parse_macro_query( | 70 | pub(crate) fn parse_macro_query( |
69 | db: &impl AstDatabase, | 71 | db: &impl AstDatabase, |
70 | macro_file: MacroFile, | 72 | macro_file: MacroFile, |
71 | ) -> Option<TreeArc<SyntaxNode>> { | 73 | ) -> Option<Parse<SyntaxNode>> { |
72 | let _p = profile("parse_macro_query"); | 74 | let _p = profile("parse_macro_query"); |
73 | let macro_call_id = macro_file.macro_call_id; | 75 | let macro_call_id = macro_file.macro_call_id; |
74 | let tt = db | 76 | let tt = db |
@@ -85,10 +87,8 @@ impl HirFileId { | |||
85 | }) | 87 | }) |
86 | .ok()?; | 88 | .ok()?; |
87 | match macro_file.macro_file_kind { | 89 | match macro_file.macro_file_kind { |
88 | MacroFileKind::Items => Some(mbe::token_tree_to_ast_item_list(&tt).syntax().to_owned()), | 90 | MacroFileKind::Items => Some(Parse::to_syntax(mbe::token_tree_to_ast_item_list(&tt))), |
89 | MacroFileKind::Expr => { | 91 | MacroFileKind::Expr => mbe::token_tree_to_expr(&tt).ok().map(Parse::to_syntax), |
90 | mbe::token_tree_to_expr(&tt).ok().map(|it| it.syntax().to_owned()) | ||
91 | } | ||
92 | } | 92 | } |
93 | } | 93 | } |
94 | } | 94 | } |