Skip to content

Commit 74f9b0f

Browse files
committed
Auto merge of #125887 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents a4e8ca6 + 6b9baed commit 74f9b0f

File tree

22 files changed

+1715
-191
lines changed

22 files changed

+1715
-191
lines changed

Cargo.lock

Lines changed: 60 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ chalk-solve = { version = "0.97.0", default-features = false }
111111
chalk-ir = "0.97.0"
112112
chalk-recursive = { version = "0.97.0", default-features = false }
113113
chalk-derive = "0.97.0"
114-
command-group = "2.0.1"
115114
crossbeam-channel = "0.5.8"
116115
dissimilar = "1.0.7"
117116
dot = "0.1.4"
@@ -132,6 +131,7 @@ object = { version = "0.33.0", default-features = false, features = [
132131
"macho",
133132
"pe",
134133
] }
134+
process-wrap = { version = "8.0.2", features = ["std"] }
135135
pulldown-cmark-to-cmark = "10.0.4"
136136
pulldown-cmark = { version = "0.9.0", default-features = false }
137137
rayon = "1.8.0"

crates/flycheck/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tracing.workspace = true
1818
rustc-hash.workspace = true
1919
serde_json.workspace = true
2020
serde.workspace = true
21-
command-group.workspace = true
21+
process-wrap.workspace = true
2222

2323
# local deps
2424
paths.workspace = true

crates/flycheck/src/command.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use std::{
99
process::{ChildStderr, ChildStdout, Command, Stdio},
1010
};
1111

12-
use command_group::{CommandGroup, GroupChild};
1312
use crossbeam_channel::Sender;
13+
use process_wrap::std::{StdChildWrapper, StdCommandWrap};
1414
use stdx::process::streaming_output;
1515

1616
/// Cargo output is structured as a one JSON per line. This trait abstracts parsing one line of
@@ -85,7 +85,7 @@ impl<T: ParseFromLine> CargoActor<T> {
8585
}
8686
}
8787

88-
struct JodGroupChild(GroupChild);
88+
struct JodGroupChild(Box<dyn StdChildWrapper>);
8989

9090
impl Drop for JodGroupChild {
9191
fn drop(&mut self) {
@@ -119,14 +119,20 @@ impl<T> fmt::Debug for CommandHandle<T> {
119119
impl<T: ParseFromLine> CommandHandle<T> {
120120
pub(crate) fn spawn(mut command: Command, sender: Sender<T>) -> std::io::Result<Self> {
121121
command.stdout(Stdio::piped()).stderr(Stdio::piped()).stdin(Stdio::null());
122-
let mut child = command.group_spawn().map(JodGroupChild)?;
123122

124123
let program = command.get_program().into();
125124
let arguments = command.get_args().map(|arg| arg.into()).collect::<Vec<OsString>>();
126125
let current_dir = command.get_current_dir().map(|arg| arg.to_path_buf());
127126

128-
let stdout = child.0.inner().stdout.take().unwrap();
129-
let stderr = child.0.inner().stderr.take().unwrap();
127+
let mut child = StdCommandWrap::from(command);
128+
#[cfg(unix)]
129+
child.wrap(process_wrap::std::ProcessSession);
130+
#[cfg(windows)]
131+
child.wrap(process_wrap::std::JobObject);
132+
let mut child = child.spawn().map(JodGroupChild)?;
133+
134+
let stdout = child.0.stdout().take().unwrap();
135+
let stderr = child.0.stderr().take().unwrap();
130136

131137
let actor = CargoActor::<T>::new(sender, stdout, stderr);
132138
let thread = stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)

crates/flycheck/src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ pub enum Message {
163163
/// Request adding a diagnostic with fixes included to a file
164164
AddDiagnostic { id: usize, workspace_root: AbsPathBuf, diagnostic: Diagnostic },
165165

166+
/// Request clearing all previous diagnostics
167+
ClearDiagnostics { id: usize },
168+
166169
/// Request check progress notification to client
167170
Progress {
168171
/// Flycheck instance ID
@@ -180,6 +183,9 @@ impl fmt::Debug for Message {
180183
.field("workspace_root", workspace_root)
181184
.field("diagnostic_code", &diagnostic.code.as_ref().map(|it| &it.code))
182185
.finish(),
186+
Message::ClearDiagnostics { id } => {
187+
f.debug_struct("ClearDiagnostics").field("id", id).finish()
188+
}
183189
Message::Progress { id, progress } => {
184190
f.debug_struct("Progress").field("id", id).field("progress", progress).finish()
185191
}
@@ -220,13 +226,22 @@ struct FlycheckActor {
220226
command_handle: Option<CommandHandle<CargoCheckMessage>>,
221227
/// The receiver side of the channel mentioned above.
222228
command_receiver: Option<Receiver<CargoCheckMessage>>,
229+
230+
status: FlycheckStatus,
223231
}
224232

225233
enum Event {
226234
RequestStateChange(StateChange),
227235
CheckEvent(Option<CargoCheckMessage>),
228236
}
229237

238+
#[derive(PartialEq)]
239+
enum FlycheckStatus {
240+
Started,
241+
DiagnosticSent,
242+
Finished,
243+
}
244+
230245
const SAVED_FILE_PLACEHOLDER: &str = "$saved_file";
231246

232247
impl FlycheckActor {
@@ -248,6 +263,7 @@ impl FlycheckActor {
248263
manifest_path,
249264
command_handle: None,
250265
command_receiver: None,
266+
status: FlycheckStatus::Finished,
251267
}
252268
}
253269

@@ -298,12 +314,14 @@ impl FlycheckActor {
298314
self.command_handle = Some(command_handle);
299315
self.command_receiver = Some(receiver);
300316
self.report_progress(Progress::DidStart);
317+
self.status = FlycheckStatus::Started;
301318
}
302319
Err(error) => {
303320
self.report_progress(Progress::DidFailToRestart(format!(
304321
"Failed to run the following command: {} error={}",
305322
formatted_command, error
306323
)));
324+
self.status = FlycheckStatus::Finished;
307325
}
308326
}
309327
}
@@ -323,7 +341,11 @@ impl FlycheckActor {
323341
error
324342
);
325343
}
344+
if self.status == FlycheckStatus::Started {
345+
self.send(Message::ClearDiagnostics { id: self.id });
346+
}
326347
self.report_progress(Progress::DidFinish(res));
348+
self.status = FlycheckStatus::Finished;
327349
}
328350
Event::CheckEvent(Some(message)) => match message {
329351
CargoCheckMessage::CompilerArtifact(msg) => {
@@ -341,11 +363,15 @@ impl FlycheckActor {
341363
message = msg.message,
342364
"diagnostic received"
343365
);
366+
if self.status == FlycheckStatus::Started {
367+
self.send(Message::ClearDiagnostics { id: self.id });
368+
}
344369
self.send(Message::AddDiagnostic {
345370
id: self.id,
346371
workspace_root: self.root.clone(),
347372
diagnostic: msg,
348373
});
374+
self.status = FlycheckStatus::DiagnosticSent;
349375
}
350376
},
351377
}
@@ -362,6 +388,7 @@ impl FlycheckActor {
362388
);
363389
command_handle.cancel();
364390
self.report_progress(Progress::DidCancel);
391+
self.status = FlycheckStatus::Finished;
365392
}
366393
}
367394

crates/hir-expand/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub fn expand_speculative(
298298
// prefer tokens of the same kind and text
299299
// Note the inversion of the score here, as we want to prefer the first token in case
300300
// of all tokens having the same score
301-
(t.kind() != token_to_map.kind()) as u8 + (t.text() != token_to_map.text()) as u8
301+
(t.kind() != token_to_map.kind()) as u8 + 2 * ((t.text() != token_to_map.text()) as u8)
302302
})?;
303303
Some((node.syntax_node(), token))
304304
}

crates/hir-expand/src/files.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,24 +153,20 @@ impl<FileId: Copy, N: AstNode> InFileWrapper<FileId, N> {
153153
// region:specific impls
154154

155155
impl InFile<&SyntaxNode> {
156-
/// Skips the attributed item that caused the macro invocation we are climbing up
157-
pub fn ancestors_with_macros_skip_attr_item(
156+
/// Traverse up macro calls and skips the macro invocation node
157+
pub fn ancestors_with_macros(
158158
self,
159159
db: &dyn db::ExpandDatabase,
160160
) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
161161
let succ = move |node: &InFile<SyntaxNode>| match node.value.parent() {
162162
Some(parent) => Some(node.with_value(parent)),
163-
None => {
164-
let macro_file_id = node.file_id.macro_file()?;
165-
let parent_node = macro_file_id.call_node(db);
166-
if macro_file_id.is_attr_macro(db) {
167-
// macro call was an attributed item, skip it
168-
// FIXME: does this fail if this is a direct expansion of another macro?
169-
parent_node.map(|node| node.parent()).transpose()
170-
} else {
171-
Some(parent_node)
172-
}
173-
}
163+
None => db
164+
.lookup_intern_macro_call(node.file_id.macro_file()?.macro_call_id)
165+
.to_node_item(db)
166+
.syntax()
167+
.cloned()
168+
.map(|node| node.parent())
169+
.transpose(),
174170
};
175171
iter::successors(succ(&self.cloned()), succ)
176172
}

crates/hir-expand/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use std::{fmt, hash::Hash};
3333
use base_db::{salsa::impl_intern_value_trivial, CrateId, FileId};
3434
use either::Either;
3535
use span::{
36-
Edition, ErasedFileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor, SyntaxContextData,
37-
SyntaxContextId,
36+
Edition, ErasedFileAstId, FileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor,
37+
SyntaxContextData, SyntaxContextId,
3838
};
3939
use syntax::{
4040
ast::{self, AstNode},
@@ -546,6 +546,18 @@ impl MacroCallLoc {
546546
}
547547
}
548548

549+
pub fn to_node_item(&self, db: &dyn ExpandDatabase) -> InFile<ast::Item> {
550+
match self.kind {
551+
MacroCallKind::FnLike { ast_id, .. } => {
552+
InFile::new(ast_id.file_id, ast_id.map(FileAstId::upcast).to_node(db))
553+
}
554+
MacroCallKind::Derive { ast_id, .. } => {
555+
InFile::new(ast_id.file_id, ast_id.map(FileAstId::upcast).to_node(db))
556+
}
557+
MacroCallKind::Attr { ast_id, .. } => InFile::new(ast_id.file_id, ast_id.to_node(db)),
558+
}
559+
}
560+
549561
fn expand_to(&self) -> ExpandTo {
550562
match self.kind {
551563
MacroCallKind::FnLike { expand_to, .. } => expand_to,

0 commit comments

Comments
 (0)