diff options
author | Jonas Schievink <[email protected]> | 2021-06-03 15:11:20 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-06-03 17:09:21 +0100 |
commit | 9fdb8f90376c02ec2a267cf9eb3bdb7b6027e1e6 (patch) | |
tree | b816f97fd66df5bb827d7e2456b6a492a7199d34 /crates | |
parent | e5a2c6596ddd11b0d57042224ac7c1d7691ec33b (diff) |
Make it opt-in
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/db.rs | 3 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/test_db.rs | 9 | ||||
-rw-r--r-- | crates/ide_db/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 9 | ||||
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 6 |
7 files changed, 34 insertions, 4 deletions
diff --git a/crates/hir_def/src/db.rs b/crates/hir_def/src/db.rs index 7eadc8e0d..c977971cd 100644 --- a/crates/hir_def/src/db.rs +++ b/crates/hir_def/src/db.rs | |||
@@ -51,6 +51,9 @@ pub trait InternDatabase: SourceDatabase { | |||
51 | 51 | ||
52 | #[salsa::query_group(DefDatabaseStorage)] | 52 | #[salsa::query_group(DefDatabaseStorage)] |
53 | pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> { | 53 | pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> { |
54 | #[salsa::input] | ||
55 | fn enable_proc_attr_macros(&self) -> bool; | ||
56 | |||
54 | #[salsa::invoke(ItemTree::file_item_tree_query)] | 57 | #[salsa::invoke(ItemTree::file_item_tree_query)] |
55 | fn file_item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>; | 58 | fn file_item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>; |
56 | 59 | ||
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 874a4ebb1..b2ce739bd 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -1067,6 +1067,10 @@ impl DefCollector<'_> { | |||
1067 | } | 1067 | } |
1068 | } | 1068 | } |
1069 | 1069 | ||
1070 | if !self.db.enable_proc_attr_macros() { | ||
1071 | return true; | ||
1072 | } | ||
1073 | |||
1070 | // Not resolved to a derive helper, so try to resolve as a macro. | 1074 | // Not resolved to a derive helper, so try to resolve as a macro. |
1071 | match attr_macro_as_call_id( | 1075 | match attr_macro_as_call_id( |
1072 | ast_id, | 1076 | ast_id, |
diff --git a/crates/hir_def/src/test_db.rs b/crates/hir_def/src/test_db.rs index e840fe5e8..b20b066e2 100644 --- a/crates/hir_def/src/test_db.rs +++ b/crates/hir_def/src/test_db.rs | |||
@@ -30,12 +30,19 @@ use crate::{ | |||
30 | crate::db::InternDatabaseStorage, | 30 | crate::db::InternDatabaseStorage, |
31 | crate::db::DefDatabaseStorage | 31 | crate::db::DefDatabaseStorage |
32 | )] | 32 | )] |
33 | #[derive(Default)] | ||
34 | pub(crate) struct TestDB { | 33 | pub(crate) struct TestDB { |
35 | storage: salsa::Storage<TestDB>, | 34 | storage: salsa::Storage<TestDB>, |
36 | events: Mutex<Option<Vec<salsa::Event>>>, | 35 | events: Mutex<Option<Vec<salsa::Event>>>, |
37 | } | 36 | } |
38 | 37 | ||
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 | |||
39 | impl Upcast<dyn AstDatabase> for TestDB { | 46 | impl Upcast<dyn AstDatabase> for TestDB { |
40 | fn upcast(&self) -> &(dyn AstDatabase + 'static) { | 47 | fn upcast(&self) -> &(dyn AstDatabase + 'static) { |
41 | &*self | 48 | &*self |
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index 1f900aef4..105607dca 100644 --- a/crates/ide_db/src/lib.rs +++ b/crates/ide_db/src/lib.rs | |||
@@ -93,6 +93,7 @@ impl RootDatabase { | |||
93 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); | 93 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); |
94 | db.set_local_roots_with_durability(Default::default(), Durability::HIGH); | 94 | db.set_local_roots_with_durability(Default::default(), Durability::HIGH); |
95 | db.set_library_roots_with_durability(Default::default(), Durability::HIGH); | 95 | db.set_library_roots_with_durability(Default::default(), Durability::HIGH); |
96 | db.set_enable_proc_attr_macros(Default::default()); | ||
96 | db.update_lru_capacity(lru_capacity); | 97 | db.update_lru_capacity(lru_capacity); |
97 | db | 98 | db |
98 | } | 99 | } |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index c33cdb740..d1f3c1b06 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -126,6 +126,9 @@ config_data! { | |||
126 | /// and a blue icon in the `Problems Panel`. | 126 | /// and a blue icon in the `Problems Panel`. |
127 | diagnostics_warningsAsInfo: Vec<String> = "[]", | 127 | diagnostics_warningsAsInfo: Vec<String> = "[]", |
128 | 128 | ||
129 | /// Expand attribute macros. | ||
130 | experimental_procAttrMacros: bool = "false", | ||
131 | |||
129 | /// Controls file watching implementation. | 132 | /// Controls file watching implementation. |
130 | files_watcher: String = "\"client\"", | 133 | files_watcher: String = "\"client\"", |
131 | /// These directories will be ignored by rust-analyzer. | 134 | /// These directories will be ignored by rust-analyzer. |
@@ -546,6 +549,9 @@ impl Config { | |||
546 | let path = self.data.procMacro_server.clone().or_else(|| std::env::current_exe().ok())?; | 549 | let path = self.data.procMacro_server.clone().or_else(|| std::env::current_exe().ok())?; |
547 | Some((path, vec!["proc-macro".into()])) | 550 | Some((path, vec!["proc-macro".into()])) |
548 | } | 551 | } |
552 | pub fn expand_proc_attr_macros(&self) -> bool { | ||
553 | self.data.experimental_procAttrMacros | ||
554 | } | ||
549 | pub fn files(&self) -> FilesConfig { | 555 | pub fn files(&self) -> FilesConfig { |
550 | FilesConfig { | 556 | FilesConfig { |
551 | watcher: match self.data.files_watcher.as_str() { | 557 | watcher: match self.data.files_watcher.as_str() { |
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index ea9dbf7fc..582a89667 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -119,12 +119,12 @@ impl GlobalState { | |||
119 | 119 | ||
120 | let analysis_host = AnalysisHost::new(config.lru_capacity()); | 120 | let analysis_host = AnalysisHost::new(config.lru_capacity()); |
121 | let (flycheck_sender, flycheck_receiver) = unbounded(); | 121 | let (flycheck_sender, flycheck_receiver) = unbounded(); |
122 | GlobalState { | 122 | let mut this = GlobalState { |
123 | sender, | 123 | sender, |
124 | req_queue: ReqQueue::default(), | 124 | req_queue: ReqQueue::default(), |
125 | task_pool, | 125 | task_pool, |
126 | loader, | 126 | loader, |
127 | config: Arc::new(config), | 127 | config: Arc::new(config.clone()), |
128 | analysis_host, | 128 | analysis_host, |
129 | diagnostics: Default::default(), | 129 | diagnostics: Default::default(), |
130 | mem_docs: FxHashMap::default(), | 130 | mem_docs: FxHashMap::default(), |
@@ -151,7 +151,10 @@ impl GlobalState { | |||
151 | 151 | ||
152 | fetch_build_data_queue: OpQueue::default(), | 152 | fetch_build_data_queue: OpQueue::default(), |
153 | latest_requests: Default::default(), | 153 | latest_requests: Default::default(), |
154 | } | 154 | }; |
155 | // Apply any required database inputs from the config. | ||
156 | this.update_configuration(config); | ||
157 | this | ||
155 | } | 158 | } |
156 | 159 | ||
157 | pub(crate) fn process_changes(&mut self) -> bool { | 160 | pub(crate) fn process_changes(&mut self) -> bool { |
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 93b5ff55f..bd31d1d13 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | use std::{mem, sync::Arc}; | 2 | use std::{mem, sync::Arc}; |
3 | 3 | ||
4 | use flycheck::{FlycheckConfig, FlycheckHandle}; | 4 | use flycheck::{FlycheckConfig, FlycheckHandle}; |
5 | use hir::db::DefDatabase; | ||
5 | use ide::Change; | 6 | use ide::Change; |
6 | use ide_db::base_db::{CrateGraph, SourceRoot, VfsPath}; | 7 | use ide_db::base_db::{CrateGraph, SourceRoot, VfsPath}; |
7 | use project_model::{BuildDataCollector, BuildDataResult, ProcMacroClient, ProjectWorkspace}; | 8 | use project_model::{BuildDataCollector, BuildDataResult, ProcMacroClient, ProjectWorkspace}; |
@@ -47,6 +48,11 @@ impl GlobalState { | |||
47 | } else if self.config.flycheck() != old_config.flycheck() { | 48 | } else if self.config.flycheck() != old_config.flycheck() { |
48 | self.reload_flycheck(); | 49 | self.reload_flycheck(); |
49 | } | 50 | } |
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()); | ||
50 | } | 56 | } |
51 | pub(crate) fn maybe_refresh(&mut self, changes: &[(AbsPathBuf, ChangeKind)]) { | 57 | pub(crate) fn maybe_refresh(&mut self, changes: &[(AbsPathBuf, ChangeKind)]) { |
52 | if !changes.iter().any(|(path, kind)| is_interesting(path, *kind)) { | 58 | if !changes.iter().any(|(path, kind)| is_interesting(path, *kind)) { |