Skip to content

Commit 9fdb8f9

Browse files
Make it opt-in
1 parent e5a2c65 commit 9fdb8f9

File tree

9 files changed

+44
-4
lines changed

9 files changed

+44
-4
lines changed

crates/hir_def/src/db.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pub trait InternDatabase: SourceDatabase {
5151

5252
#[salsa::query_group(DefDatabaseStorage)]
5353
pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
54+
#[salsa::input]
55+
fn enable_proc_attr_macros(&self) -> bool;
56+
5457
#[salsa::invoke(ItemTree::file_item_tree_query)]
5558
fn file_item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>;
5659

crates/hir_def/src/nameres/collector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,10 @@ impl DefCollector<'_> {
10671067
}
10681068
}
10691069

1070+
if !self.db.enable_proc_attr_macros() {
1071+
return true;
1072+
}
1073+
10701074
// Not resolved to a derive helper, so try to resolve as a macro.
10711075
match attr_macro_as_call_id(
10721076
ast_id,

crates/hir_def/src/test_db.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@ use crate::{
3030
crate::db::InternDatabaseStorage,
3131
crate::db::DefDatabaseStorage
3232
)]
33-
#[derive(Default)]
3433
pub(crate) struct TestDB {
3534
storage: salsa::Storage<TestDB>,
3635
events: Mutex<Option<Vec<salsa::Event>>>,
3736
}
3837

38+
impl Default for TestDB {
39+
fn default() -> Self {
40+
let mut this = Self { storage: Default::default(), events: Default::default() };
41+
this.set_enable_proc_attr_macros(true);
42+
this
43+
}
44+
}
45+
3946
impl Upcast<dyn AstDatabase> for TestDB {
4047
fn upcast(&self) -> &(dyn AstDatabase + 'static) {
4148
&*self

crates/ide_db/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl RootDatabase {
9393
db.set_crate_graph_with_durability(Default::default(), Durability::HIGH);
9494
db.set_local_roots_with_durability(Default::default(), Durability::HIGH);
9595
db.set_library_roots_with_durability(Default::default(), Durability::HIGH);
96+
db.set_enable_proc_attr_macros(Default::default());
9697
db.update_lru_capacity(lru_capacity);
9798
db
9899
}

crates/rust-analyzer/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ config_data! {
126126
/// and a blue icon in the `Problems Panel`.
127127
diagnostics_warningsAsInfo: Vec<String> = "[]",
128128

129+
/// Expand attribute macros.
130+
experimental_procAttrMacros: bool = "false",
131+
129132
/// Controls file watching implementation.
130133
files_watcher: String = "\"client\"",
131134
/// These directories will be ignored by rust-analyzer.
@@ -546,6 +549,9 @@ impl Config {
546549
let path = self.data.procMacro_server.clone().or_else(|| std::env::current_exe().ok())?;
547550
Some((path, vec!["proc-macro".into()]))
548551
}
552+
pub fn expand_proc_attr_macros(&self) -> bool {
553+
self.data.experimental_procAttrMacros
554+
}
549555
pub fn files(&self) -> FilesConfig {
550556
FilesConfig {
551557
watcher: match self.data.files_watcher.as_str() {

crates/rust-analyzer/src/global_state.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ impl GlobalState {
119119

120120
let analysis_host = AnalysisHost::new(config.lru_capacity());
121121
let (flycheck_sender, flycheck_receiver) = unbounded();
122-
GlobalState {
122+
let mut this = GlobalState {
123123
sender,
124124
req_queue: ReqQueue::default(),
125125
task_pool,
126126
loader,
127-
config: Arc::new(config),
127+
config: Arc::new(config.clone()),
128128
analysis_host,
129129
diagnostics: Default::default(),
130130
mem_docs: FxHashMap::default(),
@@ -151,7 +151,10 @@ impl GlobalState {
151151

152152
fetch_build_data_queue: OpQueue::default(),
153153
latest_requests: Default::default(),
154-
}
154+
};
155+
// Apply any required database inputs from the config.
156+
this.update_configuration(config);
157+
this
155158
}
156159

157160
pub(crate) fn process_changes(&mut self) -> bool {

crates/rust-analyzer/src/reload.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use std::{mem, sync::Arc};
33

44
use flycheck::{FlycheckConfig, FlycheckHandle};
5+
use hir::db::DefDatabase;
56
use ide::Change;
67
use ide_db::base_db::{CrateGraph, SourceRoot, VfsPath};
78
use project_model::{BuildDataCollector, BuildDataResult, ProcMacroClient, ProjectWorkspace};
@@ -47,6 +48,11 @@ impl GlobalState {
4748
} else if self.config.flycheck() != old_config.flycheck() {
4849
self.reload_flycheck();
4950
}
51+
52+
// Apply experimental feature flags.
53+
self.analysis_host
54+
.raw_database_mut()
55+
.set_enable_proc_attr_macros(self.config.expand_proc_attr_macros());
5056
}
5157
pub(crate) fn maybe_refresh(&mut self, changes: &[(AbsPathBuf, ChangeKind)]) {
5258
if !changes.iter().any(|(path, kind)| is_interesting(path, *kind)) {

docs/user/generated_config.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ List of warnings that should be displayed with info severity.
181181
The warnings will be indicated by a blue squiggly underline in code
182182
and a blue icon in the `Problems Panel`.
183183
--
184+
[[rust-analyzer.experimental.procAttrMacros]]rust-analyzer.experimental.procAttrMacros (default: `false`)::
185+
+
186+
--
187+
Expand attribute macros.
188+
--
184189
[[rust-analyzer.files.watcher]]rust-analyzer.files.watcher (default: `"client"`)::
185190
+
186191
--

editors/code/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,11 @@
617617
"type": "string"
618618
}
619619
},
620+
"rust-analyzer.experimental.procAttrMacros": {
621+
"markdownDescription": "Expand attribute macros.",
622+
"default": false,
623+
"type": "boolean"
624+
},
620625
"rust-analyzer.files.watcher": {
621626
"markdownDescription": "Controls file watching implementation.",
622627
"default": "client",

0 commit comments

Comments
 (0)