Make it opt-in
This commit is contained in:
parent
e5a2c6596d
commit
9fdb8f9037
@ -51,6 +51,9 @@ pub trait InternDatabase: SourceDatabase {
|
||||
|
||||
#[salsa::query_group(DefDatabaseStorage)]
|
||||
pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
|
||||
#[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<ItemTree>;
|
||||
|
||||
|
@ -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,
|
||||
|
@ -30,12 +30,19 @@ use crate::{
|
||||
crate::db::InternDatabaseStorage,
|
||||
crate::db::DefDatabaseStorage
|
||||
)]
|
||||
#[derive(Default)]
|
||||
pub(crate) struct TestDB {
|
||||
storage: salsa::Storage<TestDB>,
|
||||
events: Mutex<Option<Vec<salsa::Event>>>,
|
||||
}
|
||||
|
||||
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<dyn AstDatabase> for TestDB {
|
||||
fn upcast(&self) -> &(dyn AstDatabase + 'static) {
|
||||
&*self
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -126,6 +126,9 @@ config_data! {
|
||||
/// and a blue icon in the `Problems Panel`.
|
||||
diagnostics_warningsAsInfo: Vec<String> = "[]",
|
||||
|
||||
/// 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() {
|
||||
|
@ -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 {
|
||||
|
@ -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)) {
|
||||
|
@ -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"`)::
|
||||
+
|
||||
--
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user