Skip to content

Commit e46d7a0

Browse files
committed
Auto merge of rust-lang#14651 - Veykril:workspace-vscode-fix, r=Veykril
fix: Fix vscode workspaces not working properly Fixes rust-lang/rust-analyzer#14571
2 parents 6f10ddc + 49fcd4e commit e46d7a0

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

crates/hir-expand/src/db.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub trait ExpandDatabase: SourceDatabase {
102102
#[salsa::transparent]
103103
fn parse_or_expand_with_err(&self, file_id: HirFileId) -> ExpandResult<Parse<SyntaxNode>>;
104104
/// Implementation for the macro case.
105+
// This query is LRU cached
105106
fn parse_macro_expansion(
106107
&self,
107108
macro_file: MacroFile,
@@ -130,11 +131,12 @@ pub trait ExpandDatabase: SourceDatabase {
130131
fn macro_def(&self, id: MacroDefId) -> Result<Arc<TokenExpander>, mbe::ParseError>;
131132

132133
/// Expand macro call to a token tree.
134+
// This query is LRU cached
133135
fn macro_expand(&self, macro_call: MacroCallId) -> ExpandResult<Arc<tt::Subtree>>;
134136
/// Special case of the previous query for procedural macros. We can't LRU
135137
/// proc macros, since they are not deterministic in general, and
136-
/// non-determinism breaks salsa in a very, very, very bad way. @edwin0cheng
137-
/// heroically debugged this once!
138+
/// non-determinism breaks salsa in a very, very, very bad way.
139+
/// @edwin0cheng heroically debugged this once!
138140
fn expand_proc_macro(&self, call: MacroCallId) -> ExpandResult<tt::Subtree>;
139141
/// Firewall query that returns the errors from the `parse_macro_expansion` query.
140142
fn parse_macro_expansion_error(

crates/hir-expand/src/eager.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub fn expand_eager_macro(
5454
let expand_to = ExpandTo::from_call_site(&macro_call.value);
5555

5656
// Note:
57-
// When `lazy_expand` is called, its *parent* file must be already exists.
58-
// Here we store an eager macro id for the argument expanded subtree here
57+
// When `lazy_expand` is called, its *parent* file must already exist.
58+
// Here we store an eager macro id for the argument expanded subtree
5959
// for that purpose.
6060
let arg_id = db.intern_macro_call(MacroCallLoc {
6161
def,
@@ -79,7 +79,11 @@ pub fn expand_eager_macro(
7979
let Some(value ) = value else {
8080
return Ok(ExpandResult { value: None, err })
8181
};
82-
let subtree = to_subtree(&value);
82+
let subtree = {
83+
let mut subtree = mbe::syntax_node_to_token_tree(&value).0;
84+
subtree.delimiter = crate::tt::Delimiter::unspecified();
85+
subtree
86+
};
8387

8488
let res = eager.expand(db, arg_id, &subtree);
8589
if err.is_none() {
@@ -100,12 +104,6 @@ pub fn expand_eager_macro(
100104
Ok(ExpandResult { value: Some(db.intern_macro_call(loc)), err })
101105
}
102106

103-
fn to_subtree(node: &SyntaxNode) -> crate::tt::Subtree {
104-
let mut subtree = mbe::syntax_node_to_token_tree(node).0;
105-
subtree.delimiter = crate::tt::Delimiter::unspecified();
106-
subtree
107-
}
108-
109107
fn lazy_expand(
110108
db: &dyn ExpandDatabase,
111109
def: &MacroDefId,
@@ -121,7 +119,8 @@ fn lazy_expand(
121119
MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id), expand_to },
122120
);
123121

124-
db.parse_or_expand_with_err(id.as_file()).map(|parse| InFile::new(id.as_file(), parse))
122+
let file_id = id.as_file();
123+
db.parse_or_expand_with_err(file_id).map(|parse| InFile::new(file_id, parse))
125124
}
126125

127126
fn eager_macro_recur(

crates/rust-analyzer/src/reload.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,17 @@ impl GlobalState {
215215
let mut i = 0;
216216
while i < workspaces.len() {
217217
if let Ok(w) = &workspaces[i] {
218-
if let Some(dupe) = workspaces[i + 1..]
218+
let dupes: Vec<_> = workspaces
219219
.iter()
220-
.filter_map(|it| it.as_ref().ok())
221-
.position(|ws| ws.eq_ignore_build_data(w))
222-
{
223-
_ = workspaces.remove(dupe);
224-
}
220+
.enumerate()
221+
.skip(i + 1)
222+
.filter_map(|(i, it)| {
223+
it.as_ref().ok().filter(|ws| ws.eq_ignore_build_data(w)).map(|_| i)
224+
})
225+
.collect();
226+
dupes.into_iter().rev().for_each(|d| {
227+
_ = workspaces.remove(d);
228+
});
225229
}
226230
i += 1;
227231
}

0 commit comments

Comments
 (0)