From 9fdb8f90376c02ec2a267cf9eb3bdb7b6027e1e6 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 3 Jun 2021 16:11:20 +0200 Subject: Make it opt-in --- crates/hir_def/src/db.rs | 3 +++ crates/hir_def/src/nameres/collector.rs | 4 ++++ crates/hir_def/src/test_db.rs | 9 ++++++++- crates/ide_db/src/lib.rs | 1 + crates/rust-analyzer/src/config.rs | 6 ++++++ crates/rust-analyzer/src/global_state.rs | 9 ++++++--- crates/rust-analyzer/src/reload.rs | 6 ++++++ docs/user/generated_config.adoc | 5 +++++ editors/code/package.json | 5 +++++ 9 files changed, 44 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 { #[salsa::query_group(DefDatabaseStorage)] pub trait DefDatabase: InternDatabase + AstDatabase + Upcast { + #[salsa::input] + fn enable_proc_attr_macros(&self) -> bool; + #[salsa::invoke(ItemTree::file_item_tree_query)] fn file_item_tree(&self, file_id: HirFileId) -> Arc; 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<'_> { } } + if !self.db.enable_proc_attr_macros() { + return true; + } + // Not resolved to a derive helper, so try to resolve as a macro. match attr_macro_as_call_id( 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::{ crate::db::InternDatabaseStorage, crate::db::DefDatabaseStorage )] -#[derive(Default)] pub(crate) struct TestDB { storage: salsa::Storage, events: Mutex>>, } +impl Default for TestDB { + fn default() -> Self { + let mut this = Self { storage: Default::default(), events: Default::default() }; + this.set_enable_proc_attr_macros(true); + this + } +} + impl Upcast for TestDB { fn upcast(&self) -> &(dyn AstDatabase + 'static) { &*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 { db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); db.set_local_roots_with_durability(Default::default(), Durability::HIGH); db.set_library_roots_with_durability(Default::default(), Durability::HIGH); + db.set_enable_proc_attr_macros(Default::default()); db.update_lru_capacity(lru_capacity); db } 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! { /// and a blue icon in the `Problems Panel`. diagnostics_warningsAsInfo: Vec = "[]", + /// Expand attribute macros. + experimental_procAttrMacros: bool = "false", + /// Controls file watching implementation. files_watcher: String = "\"client\"", /// These directories will be ignored by rust-analyzer. @@ -546,6 +549,9 @@ impl Config { let path = self.data.procMacro_server.clone().or_else(|| std::env::current_exe().ok())?; Some((path, vec!["proc-macro".into()])) } + pub fn expand_proc_attr_macros(&self) -> bool { + self.data.experimental_procAttrMacros + } pub fn files(&self) -> FilesConfig { FilesConfig { 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 { let analysis_host = AnalysisHost::new(config.lru_capacity()); let (flycheck_sender, flycheck_receiver) = unbounded(); - GlobalState { + let mut this = GlobalState { sender, req_queue: ReqQueue::default(), task_pool, loader, - config: Arc::new(config), + config: Arc::new(config.clone()), analysis_host, diagnostics: Default::default(), mem_docs: FxHashMap::default(), @@ -151,7 +151,10 @@ impl GlobalState { fetch_build_data_queue: OpQueue::default(), latest_requests: Default::default(), - } + }; + // Apply any required database inputs from the config. + this.update_configuration(config); + this } 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 @@ use std::{mem, sync::Arc}; use flycheck::{FlycheckConfig, FlycheckHandle}; +use hir::db::DefDatabase; use ide::Change; use ide_db::base_db::{CrateGraph, SourceRoot, VfsPath}; use project_model::{BuildDataCollector, BuildDataResult, ProcMacroClient, ProjectWorkspace}; @@ -47,6 +48,11 @@ impl GlobalState { } else if self.config.flycheck() != old_config.flycheck() { self.reload_flycheck(); } + + // Apply experimental feature flags. + self.analysis_host + .raw_database_mut() + .set_enable_proc_attr_macros(self.config.expand_proc_attr_macros()); } pub(crate) fn maybe_refresh(&mut self, changes: &[(AbsPathBuf, ChangeKind)]) { if !changes.iter().any(|(path, kind)| is_interesting(path, *kind)) { diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 7f405b4d7..4eec8455d 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -181,6 +181,11 @@ List of warnings that should be displayed with info severity. The warnings will be indicated by a blue squiggly underline in code and a blue icon in the `Problems Panel`. -- +[[rust-analyzer.experimental.procAttrMacros]]rust-analyzer.experimental.procAttrMacros (default: `false`):: ++ +-- +Expand attribute macros. +-- [[rust-analyzer.files.watcher]]rust-analyzer.files.watcher (default: `"client"`):: + -- diff --git a/editors/code/package.json b/editors/code/package.json index 4a5070d02..bffc1e05b 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -617,6 +617,11 @@ "type": "string" } }, + "rust-analyzer.experimental.procAttrMacros": { + "markdownDescription": "Expand attribute macros.", + "default": false, + "type": "boolean" + }, "rust-analyzer.files.watcher": { "markdownDescription": "Controls file watching implementation.", "default": "client", -- cgit v1.2.3