mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-22 03:14:30 +00:00
Make it opt-in
This commit is contained in:
parent
e5a2c6596d
commit
9fdb8f9037
9 changed files with 44 additions and 4 deletions
|
@ -51,6 +51,9 @@ pub trait InternDatabase: SourceDatabase {
|
||||||
|
|
||||||
#[salsa::query_group(DefDatabaseStorage)]
|
#[salsa::query_group(DefDatabaseStorage)]
|
||||||
pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
|
pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
|
||||||
|
#[salsa::input]
|
||||||
|
fn enable_proc_attr_macros(&self) -> bool;
|
||||||
|
|
||||||
#[salsa::invoke(ItemTree::file_item_tree_query)]
|
#[salsa::invoke(ItemTree::file_item_tree_query)]
|
||||||
fn file_item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>;
|
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.
|
// Not resolved to a derive helper, so try to resolve as a macro.
|
||||||
match attr_macro_as_call_id(
|
match attr_macro_as_call_id(
|
||||||
ast_id,
|
ast_id,
|
||||||
|
|
|
@ -30,12 +30,19 @@ use crate::{
|
||||||
crate::db::InternDatabaseStorage,
|
crate::db::InternDatabaseStorage,
|
||||||
crate::db::DefDatabaseStorage
|
crate::db::DefDatabaseStorage
|
||||||
)]
|
)]
|
||||||
#[derive(Default)]
|
|
||||||
pub(crate) struct TestDB {
|
pub(crate) struct TestDB {
|
||||||
storage: salsa::Storage<TestDB>,
|
storage: salsa::Storage<TestDB>,
|
||||||
events: Mutex<Option<Vec<salsa::Event>>>,
|
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 {
|
impl Upcast<dyn AstDatabase> for TestDB {
|
||||||
fn upcast(&self) -> &(dyn AstDatabase + 'static) {
|
fn upcast(&self) -> &(dyn AstDatabase + 'static) {
|
||||||
&*self
|
&*self
|
||||||
|
|
|
@ -93,6 +93,7 @@ impl RootDatabase {
|
||||||
db.set_crate_graph_with_durability(Default::default(), Durability::HIGH);
|
db.set_crate_graph_with_durability(Default::default(), Durability::HIGH);
|
||||||
db.set_local_roots_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_library_roots_with_durability(Default::default(), Durability::HIGH);
|
||||||
|
db.set_enable_proc_attr_macros(Default::default());
|
||||||
db.update_lru_capacity(lru_capacity);
|
db.update_lru_capacity(lru_capacity);
|
||||||
db
|
db
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,9 @@ config_data! {
|
||||||
/// and a blue icon in the `Problems Panel`.
|
/// and a blue icon in the `Problems Panel`.
|
||||||
diagnostics_warningsAsInfo: Vec<String> = "[]",
|
diagnostics_warningsAsInfo: Vec<String> = "[]",
|
||||||
|
|
||||||
|
/// Expand attribute macros.
|
||||||
|
experimental_procAttrMacros: bool = "false",
|
||||||
|
|
||||||
/// Controls file watching implementation.
|
/// Controls file watching implementation.
|
||||||
files_watcher: String = "\"client\"",
|
files_watcher: String = "\"client\"",
|
||||||
/// These directories will be ignored by rust-analyzer.
|
/// 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())?;
|
let path = self.data.procMacro_server.clone().or_else(|| std::env::current_exe().ok())?;
|
||||||
Some((path, vec!["proc-macro".into()]))
|
Some((path, vec!["proc-macro".into()]))
|
||||||
}
|
}
|
||||||
|
pub fn expand_proc_attr_macros(&self) -> bool {
|
||||||
|
self.data.experimental_procAttrMacros
|
||||||
|
}
|
||||||
pub fn files(&self) -> FilesConfig {
|
pub fn files(&self) -> FilesConfig {
|
||||||
FilesConfig {
|
FilesConfig {
|
||||||
watcher: match self.data.files_watcher.as_str() {
|
watcher: match self.data.files_watcher.as_str() {
|
||||||
|
|
|
@ -119,12 +119,12 @@ impl GlobalState {
|
||||||
|
|
||||||
let analysis_host = AnalysisHost::new(config.lru_capacity());
|
let analysis_host = AnalysisHost::new(config.lru_capacity());
|
||||||
let (flycheck_sender, flycheck_receiver) = unbounded();
|
let (flycheck_sender, flycheck_receiver) = unbounded();
|
||||||
GlobalState {
|
let mut this = GlobalState {
|
||||||
sender,
|
sender,
|
||||||
req_queue: ReqQueue::default(),
|
req_queue: ReqQueue::default(),
|
||||||
task_pool,
|
task_pool,
|
||||||
loader,
|
loader,
|
||||||
config: Arc::new(config),
|
config: Arc::new(config.clone()),
|
||||||
analysis_host,
|
analysis_host,
|
||||||
diagnostics: Default::default(),
|
diagnostics: Default::default(),
|
||||||
mem_docs: FxHashMap::default(),
|
mem_docs: FxHashMap::default(),
|
||||||
|
@ -151,7 +151,10 @@ impl GlobalState {
|
||||||
|
|
||||||
fetch_build_data_queue: OpQueue::default(),
|
fetch_build_data_queue: OpQueue::default(),
|
||||||
latest_requests: Default::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 {
|
pub(crate) fn process_changes(&mut self) -> bool {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
use std::{mem, sync::Arc};
|
use std::{mem, sync::Arc};
|
||||||
|
|
||||||
use flycheck::{FlycheckConfig, FlycheckHandle};
|
use flycheck::{FlycheckConfig, FlycheckHandle};
|
||||||
|
use hir::db::DefDatabase;
|
||||||
use ide::Change;
|
use ide::Change;
|
||||||
use ide_db::base_db::{CrateGraph, SourceRoot, VfsPath};
|
use ide_db::base_db::{CrateGraph, SourceRoot, VfsPath};
|
||||||
use project_model::{BuildDataCollector, BuildDataResult, ProcMacroClient, ProjectWorkspace};
|
use project_model::{BuildDataCollector, BuildDataResult, ProcMacroClient, ProjectWorkspace};
|
||||||
|
@ -47,6 +48,11 @@ impl GlobalState {
|
||||||
} else if self.config.flycheck() != old_config.flycheck() {
|
} else if self.config.flycheck() != old_config.flycheck() {
|
||||||
self.reload_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)]) {
|
pub(crate) fn maybe_refresh(&mut self, changes: &[(AbsPathBuf, ChangeKind)]) {
|
||||||
if !changes.iter().any(|(path, kind)| is_interesting(path, *kind)) {
|
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
|
The warnings will be indicated by a blue squiggly underline in code
|
||||||
and a blue icon in the `Problems Panel`.
|
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"`)::
|
[[rust-analyzer.files.watcher]]rust-analyzer.files.watcher (default: `"client"`)::
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
|
|
|
@ -617,6 +617,11 @@
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.experimental.procAttrMacros": {
|
||||||
|
"markdownDescription": "Expand attribute macros.",
|
||||||
|
"default": false,
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"rust-analyzer.files.watcher": {
|
"rust-analyzer.files.watcher": {
|
||||||
"markdownDescription": "Controls file watching implementation.",
|
"markdownDescription": "Controls file watching implementation.",
|
||||||
"default": "client",
|
"default": "client",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue