make macro parsing a query

This commit is contained in:
Aleksey Kladov 2019-03-26 14:13:17 +03:00
parent e4646ce0d5
commit e231277ab2
3 changed files with 8 additions and 5 deletions

View file

@ -4,7 +4,7 @@ use ra_syntax::{SyntaxNode, TreeArc, SourceFile};
use ra_db::{SourceDatabase, salsa};
use crate::{
HirFileId, SourceFileItems, SourceItemId, Crate, Module, HirInterner,
HirFileId, MacroDefId, SourceFileItems, SourceItemId, Crate, Module, HirInterner,
Function, FnSignature, ExprScopes, TypeAlias,
Struct, Enum, StructField,
Const, ConstSignature, Static,
@ -19,6 +19,9 @@ use crate::{
#[salsa::query_group(DefDatabaseStorage)]
pub trait DefDatabase: SourceDatabase + AsRef<HirInterner> {
#[salsa::invoke(crate::ids::macro_def_query)]
fn macro_def(&self, macro_id: MacroDefId) -> Option<Arc<mbe::MacroRules>>;
#[salsa::invoke(HirFileId::hir_parse)]
fn hir_parse(&self, file_id: HirFileId) -> TreeArc<SourceFile>;

View file

@ -101,7 +101,7 @@ fn parse_macro(db: &impl DefDatabase, macro_call_id: MacroCallId) -> Option<Tree
let macro_call = ast::MacroCall::cast(&syntax).unwrap();
let (macro_arg, _) = macro_call.token_tree().and_then(mbe::ast_to_token_tree)?;
let macro_rules = macro_def_query(db, loc.def)?;
let macro_rules = db.macro_def(loc.def)?;
let tt = macro_rules.expand(&macro_arg).ok()?;
Some(mbe::token_tree_to_ast_item_list(&tt))
}
@ -125,11 +125,11 @@ impl From<MacroCallId> for HirFileId {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) enum MacroDefId {
pub enum MacroDefId {
MacroByExample { source_item_id: SourceItemId },
}
fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
pub(crate) fn macro_def_query(db: &impl DefDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
let syntax_node = match id {
MacroDefId::MacroByExample { source_item_id } => db.file_item(source_item_id),
};

View file

@ -53,7 +53,7 @@ use crate::{
pub use self::{
path::{Path, PathKind},
name::Name,
ids::{HirFileId, MacroCallId, MacroCallLoc, HirInterner},
ids::{HirFileId, MacroDefId, MacroCallId, MacroCallLoc, HirInterner},
nameres::{PerNs, Namespace},
ty::{Ty, ApplicationTy, TypeCtor, Substs, display::HirDisplay},
impl_block::{ImplBlock, ImplItem},