Skip to content

Commit 03668e9

Browse files
committed
Auto merge of #13038 - Veykril:rev-12947, r=Veykril
Revert #12947, trigger workspace switches on all structure changes again Closes #13029
2 parents 8fa8bf1 + c5c1bbf commit 03668e9

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

crates/hir-def/src/body/lower.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use syntax::{
2424

2525
use crate::{
2626
adt::StructKind,
27+
attr::Attrs,
2728
body::{Body, BodySourceMap, Expander, LabelSource, PatPtr, SyntheticSyntax},
2829
body::{BodyDiagnostic, ExprSource, PatSource},
2930
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
@@ -204,7 +205,7 @@ impl ExprCollector<'_> {
204205
/// Returns `None` if and only if the expression is `#[cfg]`d out.
205206
fn maybe_collect_expr(&mut self, expr: ast::Expr) -> Option<ExprId> {
206207
let syntax_ptr = AstPtr::new(&expr);
207-
self.check_cfg(&expr)?;
208+
let attrs = self.check_cfg(&expr)?;
208209

209210
Some(match expr {
210211
ast::Expr::IfExpr(e) => {
@@ -313,7 +314,7 @@ impl ExprCollector<'_> {
313314
match_arm_list
314315
.arms()
315316
.filter_map(|arm| {
316-
self.check_cfg(&arm).map(|()| MatchArm {
317+
self.check_cfg(&arm).map(|_| MatchArm {
317318
pat: self.collect_pat_opt(arm.pat()),
318319
expr: self.collect_expr_opt(arm.expr()),
319320
guard: arm
@@ -969,13 +970,10 @@ impl ExprCollector<'_> {
969970

970971
/// Returns `None` (and emits diagnostics) when `owner` if `#[cfg]`d out, and `Some(())` when
971972
/// not.
972-
fn check_cfg(&mut self, owner: &dyn ast::HasAttrs) -> Option<()> {
973-
match self.expander.parse_attrs(self.db, owner).cfg() {
974-
Some(cfg) => {
975-
if self.expander.cfg_options().check(&cfg) != Some(false) {
976-
return Some(());
977-
}
978-
973+
fn check_cfg(&mut self, owner: &dyn ast::HasAttrs) -> Option<Attrs> {
974+
let attrs = self.expander.parse_attrs(self.db, owner);
975+
match attrs.cfg() {
976+
Some(cfg) if self.expander.cfg_options().check(&cfg) == Some(false) => {
979977
self.source_map.diagnostics.push(BodyDiagnostic::InactiveCode {
980978
node: InFile::new(
981979
self.expander.current_file_id,
@@ -984,10 +982,9 @@ impl ExprCollector<'_> {
984982
cfg,
985983
opts: self.expander.cfg_options().clone(),
986984
});
987-
988-
None
985+
return None;
989986
}
990-
None => Some(()),
987+
_ => Some(attrs),
991988
}
992989
}
993990
}

crates/rust-analyzer/src/global_state.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{sync::Arc, time::Instant};
88
use crossbeam_channel::{unbounded, Receiver, Sender};
99
use flycheck::FlycheckHandle;
1010
use ide::{Analysis, AnalysisHost, Cancellable, Change, FileId};
11-
use ide_db::base_db::{CrateId, FileLoader, SourceDatabase, SourceDatabaseExt};
11+
use ide_db::base_db::{CrateId, FileLoader, SourceDatabase};
1212
use lsp_types::{SemanticTokens, Url};
1313
use parking_lot::{Mutex, RwLock};
1414
use proc_macro_api::ProcMacroServer;
@@ -176,9 +176,9 @@ impl GlobalState {
176176

177177
pub(crate) fn process_changes(&mut self) -> bool {
178178
let _p = profile::span("GlobalState::process_changes");
179-
let mut fs_refresh_changes = Vec::new();
180179
// A file was added or deleted
181180
let mut has_structure_changes = false;
181+
let mut workspace_structure_change = None;
182182

183183
let (change, changed_files) = {
184184
let mut change = Change::new();
@@ -192,7 +192,7 @@ impl GlobalState {
192192
if let Some(path) = vfs.file_path(file.file_id).as_path() {
193193
let path = path.to_path_buf();
194194
if reload::should_refresh_for_change(&path, file.change_kind) {
195-
fs_refresh_changes.push((path, file.file_id));
195+
workspace_structure_change = Some(path);
196196
}
197197
if file.is_created_or_deleted() {
198198
has_structure_changes = true;
@@ -227,11 +227,10 @@ impl GlobalState {
227227

228228
{
229229
let raw_database = self.analysis_host.raw_database();
230-
let workspace_structure_change =
231-
fs_refresh_changes.into_iter().find(|&(_, file_id)| {
232-
!raw_database.source_root(raw_database.file_source_root(file_id)).is_library
233-
});
234-
if let Some((path, _)) = workspace_structure_change {
230+
// FIXME: ideally we should only trigger a workspace fetch for non-library changes
231+
// but somethings going wrong with the source root business when we add a new local
232+
// crate see https://github.com/rust-lang/rust-analyzer/issues/13029
233+
if let Some(path) = workspace_structure_change {
235234
self.fetch_workspaces_queue
236235
.request_op(format!("workspace vfs file change: {}", path.display()));
237236
}

0 commit comments

Comments
 (0)