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:
bors 2023-03-30 13:21:49 +00:00
commit 562477b4da
11 changed files with 33 additions and 28 deletions

View file

@ -590,7 +590,7 @@ impl<'a> AssocItemCollector<'a> {
) {
self.attr_calls.push((ast_id, call_id));
// 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;
}
let loc = self.db.lookup_intern_macro_call(call_id);

View file

@ -66,7 +66,7 @@ pub trait InternDatabase: SourceDatabase {
#[salsa::query_group(DefDatabaseStorage)]
pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDatabase> {
#[salsa::input]
fn enable_proc_attr_macros(&self) -> bool;
fn expand_proc_attr_macros(&self) -> bool;
#[salsa::invoke(ItemTree::file_item_tree_query)]
fn file_item_tree(&self, file_id: HirFileId) -> Arc<ItemTree>;

View file

@ -1282,7 +1282,7 @@ impl DefCollector<'_> {
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call_id);
// 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(
directive.module_id,
loc.kind,

View file

@ -6,8 +6,9 @@ use std::{
};
use base_db::{
salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, FilePosition,
SourceDatabase, Upcast,
salsa::{self, Durability},
AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, FilePosition, SourceDatabase,
Upcast,
};
use hir_expand::{db::ExpandDatabase, InFile};
use stdx::hash::NoHashHashSet;
@ -35,7 +36,7 @@ pub(crate) struct TestDB {
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.set_expand_proc_attr_macros_with_durability(true, Durability::HIGH);
this
}
}

View file

@ -6,7 +6,8 @@ use std::{
};
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_expand::db::ExpandDatabase;
@ -30,7 +31,7 @@ pub(crate) struct TestDB {
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.set_expand_proc_attr_macros_with_durability(true, Durability::HIGH);
this
}
}

View file

@ -3,7 +3,7 @@ mod generated;
mod sourcegen;
use expect_test::expect;
use hir::{db::DefDatabase, Semantics};
use hir::Semantics;
use ide_db::{
base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt},
imports::insert_use::{ImportGranularity, InsertUseConfig},
@ -161,7 +161,7 @@ fn check_with_config(
assist_label: Option<&str>,
) {
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 frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() };

View file

@ -23,7 +23,7 @@ mod type_pos;
mod use_tree;
mod visibility;
use hir::{db::DefDatabase, PrefixKind};
use hir::PrefixKind;
use ide_db::{
base_db::{fixture::ChangeFixture, FileLoader, FilePosition},
imports::insert_use::{ImportGranularity, InsertUseConfig},
@ -120,7 +120,7 @@ fn completion_list_with_config(
pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) {
let change_fixture = ChangeFixture::parse(ra_fixture);
let mut database = RootDatabase::default();
database.set_enable_proc_attr_macros(true);
database.enable_proc_attr_macros();
database.apply_change(change_fixture.change);
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
let offset = range_or_offset.expect_offset();

View file

@ -140,11 +140,15 @@ impl RootDatabase {
db.set_proc_macros_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(false);
db.set_expand_proc_attr_macros_with_durability(false, Durability::HIGH);
db.update_parse_query_lru_capacity(lru_capacity);
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>) {
let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_LRU_CAP);
base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity);

View file

@ -1,5 +1,4 @@
//! Utilities for creating `Analysis` instances for tests.
use hir::db::DefDatabase;
use ide_db::base_db::fixture::ChangeFixture;
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) {
let mut host = AnalysisHost::default();
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.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) {
let mut host = AnalysisHost::default();
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);
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
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) {
let mut host = AnalysisHost::default();
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);
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
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) {
let mut host = AnalysisHost::default();
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);
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
(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)>) {
let mut host = AnalysisHost::default();
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);
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
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)>) {
let mut host = AnalysisHost::default();
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);
let annotations = change_fixture

View file

@ -4,7 +4,6 @@ use std::{convert::identity, path::Path, sync::Arc};
use anyhow::Result;
use crossbeam_channel::{unbounded, Receiver};
use hir::db::DefDatabase;
use ide::{AnalysisHost, Change};
use ide_db::{
base_db::{CrateGraph, ProcMacros},
@ -143,7 +142,7 @@ fn load_crate_graph(
let mut host = AnalysisHost::new(lru_cap);
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
for task in receiver {

View file

@ -19,8 +19,8 @@ use hir::db::DefDatabase;
use ide::Change;
use ide_db::{
base_db::{
CrateGraph, Env, ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroKind,
ProcMacroLoadResult, ProcMacroPaths, ProcMacros, SourceRoot, VfsPath,
salsa::Durability, CrateGraph, Env, ProcMacro, ProcMacroExpander, ProcMacroExpansionError,
ProcMacroKind, ProcMacroLoadResult, ProcMacroPaths, ProcMacros, SourceRoot, VfsPath,
},
FxHashMap,
};
@ -88,12 +88,13 @@ impl GlobalState {
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.analysis_host
.raw_database_mut()
.set_enable_proc_attr_macros(self.config.expand_proc_attr_macros());
self.analysis_host.raw_database_mut().set_expand_proc_attr_macros_with_durability(
self.config.expand_proc_attr_macros(),
Durability::HIGH,
);
}
}