Make it opt-in

This commit is contained in:
Jonas Schievink 2021-06-03 16:11:20 +02:00
parent e5a2c6596d
commit 9fdb8f9037
9 changed files with 44 additions and 4 deletions

View file

@ -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>;

View file

@ -1067,6 +1067,10 @@ fn resolve_macros(&mut self) -> ReachedFixedPoint {
}
}
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,

View file

@ -30,12 +30,19 @@
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

View file

@ -93,6 +93,7 @@ pub fn new(lru_capacity: Option<usize>) -> 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
}

View file

@ -126,6 +126,9 @@ struct ConfigData {
/// 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 @@ pub fn proc_macro_srv(&self) -> Option<(PathBuf, Vec<OsString>)> {
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() {

View file

@ -119,12 +119,12 @@ pub(crate) fn new(sender: Sender<lsp_server::Message>, config: Config) -> Global
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 @@ pub(crate) fn new(sender: Sender<lsp_server::Message>, config: Config) -> Global
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 {

View file

@ -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 @@ pub(crate) fn update_configuration(&mut self, config: Config) {
} 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)) {

View file

@ -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"`)::
+
--

View file

@ -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",