Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/db.rs')
| -rw-r--r-- | crates/hir-def/src/db.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs index 1776b7c84b..9d58a5331a 100644 --- a/crates/hir-def/src/db.rs +++ b/crates/hir-def/src/db.rs @@ -4,6 +4,7 @@ use hir_expand::{ EditionedFileId, HirFileId, InFile, Lookup, MacroCallId, MacroDefId, MacroDefKind, db::ExpandDatabase, }; +use salsa::{Durability, Setter}; use triomphe::Arc; use crate::{ @@ -16,10 +17,6 @@ use crate::{ #[query_group::query_group] pub trait DefDatabase: ExpandDatabase + SourceDatabase { - /// Whether to expand procedural macros during name resolution. - #[salsa::input] - fn expand_proc_attr_macros(&self) -> bool; - /// Computes an [`ItemTree`] for the given file or macro expansion. #[salsa::invoke(file_item_tree)] #[salsa::transparent] @@ -47,6 +44,26 @@ pub trait DefDatabase: ExpandDatabase + SourceDatabase { fn include_macro_invoc(&self, crate_id: Crate) -> Arc<[(MacroCallId, EditionedFileId)]>; } +/// Whether to expand procedural macros during name resolution. +/// +/// Note: this struct shouldn't be exposed to downstream crates -- consider using +/// [`set_expand_proc_attr_macros`] instead, if possible. +#[salsa::input(singleton, debug)] +pub(crate) struct ExpandProcAttrMacros { + #[returns(copy)] + pub(crate) enabled: bool, +} + +pub fn set_expand_proc_attr_macros(db: &mut dyn DefDatabase, enabled: bool) { + if let Some(expand_proc_attr_macros) = ExpandProcAttrMacros::try_get(db) { + if expand_proc_attr_macros.enabled(db) != enabled { + expand_proc_attr_macros.set_enabled(db).with_durability(Durability::HIGH).to(enabled); + } + } else { + _ = ExpandProcAttrMacros::builder(enabled).durability(Durability::HIGH).new(db); + } +} + // return: macro call id and include file id fn include_macro_invoc( db: &dyn DefDatabase, |