mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
Auto merge of #14439 - Veykril:proc-mac-attr-durability, r=Veykril
internal: Set Durability to HIGH for enable_proc_attr_macros input
This commit is contained in:
commit
562477b4da
11 changed files with 33 additions and 28 deletions
|
@ -590,7 +590,7 @@ impl<'a> AssocItemCollector<'a> {
|
||||||
) {
|
) {
|
||||||
self.attr_calls.push((ast_id, call_id));
|
self.attr_calls.push((ast_id, call_id));
|
||||||
// If proc attribute macro expansion is disabled, skip expanding it here
|
// If proc attribute macro expansion is disabled, skip expanding it here
|
||||||
if !self.db.enable_proc_attr_macros() {
|
if !self.db.expand_proc_attr_macros() {
|
||||||
continue 'attrs;
|
continue 'attrs;
|
||||||
}
|
}
|
||||||
let loc = self.db.lookup_intern_macro_call(call_id);
|
let loc = self.db.lookup_intern_macro_call(call_id);
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub trait InternDatabase: SourceDatabase {
|
||||||
#[salsa::query_group(DefDatabaseStorage)]
|
#[salsa::query_group(DefDatabaseStorage)]
|
||||||
pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDatabase> {
|
pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDatabase> {
|
||||||
#[salsa::input]
|
#[salsa::input]
|
||||||
fn enable_proc_attr_macros(&self) -> bool;
|
fn expand_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>;
|
||||||
|
|
|
@ -1282,7 +1282,7 @@ impl DefCollector<'_> {
|
||||||
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call_id);
|
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call_id);
|
||||||
|
|
||||||
// If proc attribute macro expansion is disabled, skip expanding it here
|
// If proc attribute macro expansion is disabled, skip expanding it here
|
||||||
if !self.db.enable_proc_attr_macros() {
|
if !self.db.expand_proc_attr_macros() {
|
||||||
self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro(
|
self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro(
|
||||||
directive.module_id,
|
directive.module_id,
|
||||||
loc.kind,
|
loc.kind,
|
||||||
|
|
|
@ -6,8 +6,9 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use base_db::{
|
use base_db::{
|
||||||
salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, FilePosition,
|
salsa::{self, Durability},
|
||||||
SourceDatabase, Upcast,
|
AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, FilePosition, SourceDatabase,
|
||||||
|
Upcast,
|
||||||
};
|
};
|
||||||
use hir_expand::{db::ExpandDatabase, InFile};
|
use hir_expand::{db::ExpandDatabase, InFile};
|
||||||
use stdx::hash::NoHashHashSet;
|
use stdx::hash::NoHashHashSet;
|
||||||
|
@ -35,7 +36,7 @@ pub(crate) struct TestDB {
|
||||||
impl Default for TestDB {
|
impl Default for TestDB {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let mut this = Self { storage: Default::default(), events: Default::default() };
|
let mut this = Self { storage: Default::default(), events: Default::default() };
|
||||||
this.set_enable_proc_attr_macros(true);
|
this.set_expand_proc_attr_macros_with_durability(true, Durability::HIGH);
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use base_db::{
|
use base_db::{
|
||||||
salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast,
|
salsa::{self, Durability},
|
||||||
|
AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast,
|
||||||
};
|
};
|
||||||
use hir_def::{db::DefDatabase, ModuleId};
|
use hir_def::{db::DefDatabase, ModuleId};
|
||||||
use hir_expand::db::ExpandDatabase;
|
use hir_expand::db::ExpandDatabase;
|
||||||
|
@ -30,7 +31,7 @@ pub(crate) struct TestDB {
|
||||||
impl Default for TestDB {
|
impl Default for TestDB {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let mut this = Self { storage: Default::default(), events: Default::default() };
|
let mut this = Self { storage: Default::default(), events: Default::default() };
|
||||||
this.set_enable_proc_attr_macros(true);
|
this.set_expand_proc_attr_macros_with_durability(true, Durability::HIGH);
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod generated;
|
||||||
mod sourcegen;
|
mod sourcegen;
|
||||||
|
|
||||||
use expect_test::expect;
|
use expect_test::expect;
|
||||||
use hir::{db::DefDatabase, Semantics};
|
use hir::Semantics;
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt},
|
base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt},
|
||||||
imports::insert_use::{ImportGranularity, InsertUseConfig},
|
imports::insert_use::{ImportGranularity, InsertUseConfig},
|
||||||
|
@ -161,7 +161,7 @@ fn check_with_config(
|
||||||
assist_label: Option<&str>,
|
assist_label: Option<&str>,
|
||||||
) {
|
) {
|
||||||
let (mut db, file_with_caret_id, range_or_offset) = RootDatabase::with_range_or_offset(before);
|
let (mut db, file_with_caret_id, range_or_offset) = RootDatabase::with_range_or_offset(before);
|
||||||
db.set_enable_proc_attr_macros(true);
|
db.enable_proc_attr_macros();
|
||||||
let text_without_caret = db.file_text(file_with_caret_id).to_string();
|
let text_without_caret = db.file_text(file_with_caret_id).to_string();
|
||||||
|
|
||||||
let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() };
|
let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() };
|
||||||
|
|
|
@ -23,7 +23,7 @@ mod type_pos;
|
||||||
mod use_tree;
|
mod use_tree;
|
||||||
mod visibility;
|
mod visibility;
|
||||||
|
|
||||||
use hir::{db::DefDatabase, PrefixKind};
|
use hir::PrefixKind;
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::{fixture::ChangeFixture, FileLoader, FilePosition},
|
base_db::{fixture::ChangeFixture, FileLoader, FilePosition},
|
||||||
imports::insert_use::{ImportGranularity, InsertUseConfig},
|
imports::insert_use::{ImportGranularity, InsertUseConfig},
|
||||||
|
@ -120,7 +120,7 @@ fn completion_list_with_config(
|
||||||
pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) {
|
pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) {
|
||||||
let change_fixture = ChangeFixture::parse(ra_fixture);
|
let change_fixture = ChangeFixture::parse(ra_fixture);
|
||||||
let mut database = RootDatabase::default();
|
let mut database = RootDatabase::default();
|
||||||
database.set_enable_proc_attr_macros(true);
|
database.enable_proc_attr_macros();
|
||||||
database.apply_change(change_fixture.change);
|
database.apply_change(change_fixture.change);
|
||||||
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
|
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
|
||||||
let offset = range_or_offset.expect_offset();
|
let offset = range_or_offset.expect_offset();
|
||||||
|
|
|
@ -140,11 +140,15 @@ impl RootDatabase {
|
||||||
db.set_proc_macros_with_durability(Default::default(), Durability::HIGH);
|
db.set_proc_macros_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(false);
|
db.set_expand_proc_attr_macros_with_durability(false, Durability::HIGH);
|
||||||
db.update_parse_query_lru_capacity(lru_capacity);
|
db.update_parse_query_lru_capacity(lru_capacity);
|
||||||
db
|
db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn enable_proc_attr_macros(&mut self) {
|
||||||
|
self.set_expand_proc_attr_macros_with_durability(true, Durability::HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_parse_query_lru_capacity(&mut self, lru_capacity: Option<usize>) {
|
pub fn update_parse_query_lru_capacity(&mut self, lru_capacity: Option<usize>) {
|
||||||
let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_LRU_CAP);
|
let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_LRU_CAP);
|
||||||
base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
|
base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
//! Utilities for creating `Analysis` instances for tests.
|
//! Utilities for creating `Analysis` instances for tests.
|
||||||
use hir::db::DefDatabase;
|
|
||||||
use ide_db::base_db::fixture::ChangeFixture;
|
use ide_db::base_db::fixture::ChangeFixture;
|
||||||
use test_utils::{extract_annotations, RangeOrOffset};
|
use test_utils::{extract_annotations, RangeOrOffset};
|
||||||
|
|
||||||
|
@ -9,7 +8,7 @@ use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange};
|
||||||
pub(crate) fn file(ra_fixture: &str) -> (Analysis, FileId) {
|
pub(crate) fn file(ra_fixture: &str) -> (Analysis, FileId) {
|
||||||
let mut host = AnalysisHost::default();
|
let mut host = AnalysisHost::default();
|
||||||
let change_fixture = ChangeFixture::parse(ra_fixture);
|
let change_fixture = ChangeFixture::parse(ra_fixture);
|
||||||
host.db.set_enable_proc_attr_macros(true);
|
host.db.enable_proc_attr_macros();
|
||||||
host.db.apply_change(change_fixture.change);
|
host.db.apply_change(change_fixture.change);
|
||||||
(host.analysis(), change_fixture.files[0])
|
(host.analysis(), change_fixture.files[0])
|
||||||
}
|
}
|
||||||
|
@ -18,7 +17,7 @@ pub(crate) fn file(ra_fixture: &str) -> (Analysis, FileId) {
|
||||||
pub(crate) fn position(ra_fixture: &str) -> (Analysis, FilePosition) {
|
pub(crate) fn position(ra_fixture: &str) -> (Analysis, FilePosition) {
|
||||||
let mut host = AnalysisHost::default();
|
let mut host = AnalysisHost::default();
|
||||||
let change_fixture = ChangeFixture::parse(ra_fixture);
|
let change_fixture = ChangeFixture::parse(ra_fixture);
|
||||||
host.db.set_enable_proc_attr_macros(true);
|
host.db.enable_proc_attr_macros();
|
||||||
host.db.apply_change(change_fixture.change);
|
host.db.apply_change(change_fixture.change);
|
||||||
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
|
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
|
||||||
let offset = range_or_offset.expect_offset();
|
let offset = range_or_offset.expect_offset();
|
||||||
|
@ -29,7 +28,7 @@ pub(crate) fn position(ra_fixture: &str) -> (Analysis, FilePosition) {
|
||||||
pub(crate) fn range(ra_fixture: &str) -> (Analysis, FileRange) {
|
pub(crate) fn range(ra_fixture: &str) -> (Analysis, FileRange) {
|
||||||
let mut host = AnalysisHost::default();
|
let mut host = AnalysisHost::default();
|
||||||
let change_fixture = ChangeFixture::parse(ra_fixture);
|
let change_fixture = ChangeFixture::parse(ra_fixture);
|
||||||
host.db.set_enable_proc_attr_macros(true);
|
host.db.enable_proc_attr_macros();
|
||||||
host.db.apply_change(change_fixture.change);
|
host.db.apply_change(change_fixture.change);
|
||||||
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
|
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
|
||||||
let range = range_or_offset.expect_range();
|
let range = range_or_offset.expect_range();
|
||||||
|
@ -40,7 +39,7 @@ pub(crate) fn range(ra_fixture: &str) -> (Analysis, FileRange) {
|
||||||
pub(crate) fn range_or_position(ra_fixture: &str) -> (Analysis, FileId, RangeOrOffset) {
|
pub(crate) fn range_or_position(ra_fixture: &str) -> (Analysis, FileId, RangeOrOffset) {
|
||||||
let mut host = AnalysisHost::default();
|
let mut host = AnalysisHost::default();
|
||||||
let change_fixture = ChangeFixture::parse(ra_fixture);
|
let change_fixture = ChangeFixture::parse(ra_fixture);
|
||||||
host.db.set_enable_proc_attr_macros(true);
|
host.db.enable_proc_attr_macros();
|
||||||
host.db.apply_change(change_fixture.change);
|
host.db.apply_change(change_fixture.change);
|
||||||
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
|
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
|
||||||
(host.analysis(), file_id, range_or_offset)
|
(host.analysis(), file_id, range_or_offset)
|
||||||
|
@ -50,7 +49,7 @@ pub(crate) fn range_or_position(ra_fixture: &str) -> (Analysis, FileId, RangeOrO
|
||||||
pub(crate) fn annotations(ra_fixture: &str) -> (Analysis, FilePosition, Vec<(FileRange, String)>) {
|
pub(crate) fn annotations(ra_fixture: &str) -> (Analysis, FilePosition, Vec<(FileRange, String)>) {
|
||||||
let mut host = AnalysisHost::default();
|
let mut host = AnalysisHost::default();
|
||||||
let change_fixture = ChangeFixture::parse(ra_fixture);
|
let change_fixture = ChangeFixture::parse(ra_fixture);
|
||||||
host.db.set_enable_proc_attr_macros(true);
|
host.db.enable_proc_attr_macros();
|
||||||
host.db.apply_change(change_fixture.change);
|
host.db.apply_change(change_fixture.change);
|
||||||
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
|
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
|
||||||
let offset = range_or_offset.expect_offset();
|
let offset = range_or_offset.expect_offset();
|
||||||
|
@ -71,7 +70,7 @@ pub(crate) fn annotations(ra_fixture: &str) -> (Analysis, FilePosition, Vec<(Fil
|
||||||
pub(crate) fn annotations_without_marker(ra_fixture: &str) -> (Analysis, Vec<(FileRange, String)>) {
|
pub(crate) fn annotations_without_marker(ra_fixture: &str) -> (Analysis, Vec<(FileRange, String)>) {
|
||||||
let mut host = AnalysisHost::default();
|
let mut host = AnalysisHost::default();
|
||||||
let change_fixture = ChangeFixture::parse(ra_fixture);
|
let change_fixture = ChangeFixture::parse(ra_fixture);
|
||||||
host.db.set_enable_proc_attr_macros(true);
|
host.db.enable_proc_attr_macros();
|
||||||
host.db.apply_change(change_fixture.change);
|
host.db.apply_change(change_fixture.change);
|
||||||
|
|
||||||
let annotations = change_fixture
|
let annotations = change_fixture
|
||||||
|
|
|
@ -4,7 +4,6 @@ use std::{convert::identity, path::Path, sync::Arc};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use crossbeam_channel::{unbounded, Receiver};
|
use crossbeam_channel::{unbounded, Receiver};
|
||||||
use hir::db::DefDatabase;
|
|
||||||
use ide::{AnalysisHost, Change};
|
use ide::{AnalysisHost, Change};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::{CrateGraph, ProcMacros},
|
base_db::{CrateGraph, ProcMacros},
|
||||||
|
@ -143,7 +142,7 @@ fn load_crate_graph(
|
||||||
let mut host = AnalysisHost::new(lru_cap);
|
let mut host = AnalysisHost::new(lru_cap);
|
||||||
let mut analysis_change = Change::new();
|
let mut analysis_change = Change::new();
|
||||||
|
|
||||||
host.raw_database_mut().set_enable_proc_attr_macros(true);
|
host.raw_database_mut().enable_proc_attr_macros();
|
||||||
|
|
||||||
// wait until Vfs has loaded all roots
|
// wait until Vfs has loaded all roots
|
||||||
for task in receiver {
|
for task in receiver {
|
||||||
|
|
|
@ -19,8 +19,8 @@ use hir::db::DefDatabase;
|
||||||
use ide::Change;
|
use ide::Change;
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::{
|
base_db::{
|
||||||
CrateGraph, Env, ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind,
|
salsa::Durability, CrateGraph, Env, ProcMacro, ProcMacroExpander, ProcMacroExpansionError,
|
||||||
ProcMacroLoadResult, ProcMacroPaths, ProcMacros, SourceRoot, VfsPath,
|
ProcMacroKind, ProcMacroLoadResult, ProcMacroPaths, ProcMacros, SourceRoot, VfsPath,
|
||||||
},
|
},
|
||||||
FxHashMap,
|
FxHashMap,
|
||||||
};
|
};
|
||||||
|
@ -88,12 +88,13 @@ impl GlobalState {
|
||||||
self.reload_flycheck();
|
self.reload_flycheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.analysis_host.raw_database().enable_proc_attr_macros()
|
if self.analysis_host.raw_database().expand_proc_attr_macros()
|
||||||
!= self.config.expand_proc_attr_macros()
|
!= self.config.expand_proc_attr_macros()
|
||||||
{
|
{
|
||||||
self.analysis_host
|
self.analysis_host.raw_database_mut().set_expand_proc_attr_macros_with_durability(
|
||||||
.raw_database_mut()
|
self.config.expand_proc_attr_macros(),
|
||||||
.set_enable_proc_attr_macros(self.config.expand_proc_attr_macros());
|
Durability::HIGH,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue