Skip to content

Commit 8bec878

Browse files
committed
Auto merge of rust-lang#125887 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents 13e2d72 + 4717bdf commit 8bec878

File tree

22 files changed

+1715
-191
lines changed

22 files changed

+1715
-191
lines changed

src/tools/rust-analyzer/Cargo.lock

+60-38
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,6 @@ dependencies = [
216216
"tracing",
217217
]
218218

219-
[[package]]
220-
name = "command-group"
221-
version = "2.1.0"
222-
source = "registry+https://github.com/rust-lang/crates.io-index"
223-
checksum = "5080df6b0f0ecb76cab30808f00d937ba725cebe266a3da8cd89dff92f2a9916"
224-
dependencies = [
225-
"nix 0.26.4",
226-
"winapi",
227-
]
228-
229219
[[package]]
230220
name = "countme"
231221
version = "3.0.1"
@@ -292,7 +282,7 @@ version = "3.4.4"
292282
source = "registry+https://github.com/rust-lang/crates.io-index"
293283
checksum = "672465ae37dc1bc6380a6547a8883d5dd397b0f1faaad4f265726cc7042a5345"
294284
dependencies = [
295-
"nix 0.28.0",
285+
"nix",
296286
"windows-sys 0.52.0",
297287
]
298288

@@ -432,9 +422,9 @@ name = "flycheck"
432422
version = "0.0.0"
433423
dependencies = [
434424
"cargo_metadata",
435-
"command-group",
436425
"crossbeam-channel",
437426
"paths",
427+
"process-wrap",
438428
"rustc-hash",
439429
"serde",
440430
"serde_json",
@@ -1121,17 +1111,6 @@ dependencies = [
11211111
"windows-sys 0.48.0",
11221112
]
11231113

1124-
[[package]]
1125-
name = "nix"
1126-
version = "0.26.4"
1127-
source = "registry+https://github.com/rust-lang/crates.io-index"
1128-
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
1129-
dependencies = [
1130-
"bitflags 1.3.2",
1131-
"cfg-if",
1132-
"libc",
1133-
]
1134-
11351114
[[package]]
11361115
name = "nix"
11371116
version = "0.28.0"
@@ -1397,6 +1376,18 @@ dependencies = [
13971376
"unicode-ident",
13981377
]
13991378

1379+
[[package]]
1380+
name = "process-wrap"
1381+
version = "8.0.2"
1382+
source = "registry+https://github.com/rust-lang/crates.io-index"
1383+
checksum = "38ee68ae331824036479c84060534b18254c864fa73366c58d86db3b7b811619"
1384+
dependencies = [
1385+
"indexmap",
1386+
"nix",
1387+
"tracing",
1388+
"windows",
1389+
]
1390+
14001391
[[package]]
14011392
name = "profile"
14021393
version = "0.0.0"
@@ -2375,35 +2366,66 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
23752366
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
23762367

23772368
[[package]]
2378-
name = "winapi"
2379-
version = "0.3.9"
2369+
name = "winapi-util"
2370+
version = "0.1.8"
2371+
source = "registry+https://github.com/rust-lang/crates.io-index"
2372+
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
2373+
dependencies = [
2374+
"windows-sys 0.52.0",
2375+
]
2376+
2377+
[[package]]
2378+
name = "windows"
2379+
version = "0.56.0"
23802380
source = "registry+https://github.com/rust-lang/crates.io-index"
2381-
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
2381+
checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132"
23822382
dependencies = [
2383-
"winapi-i686-pc-windows-gnu",
2384-
"winapi-x86_64-pc-windows-gnu",
2383+
"windows-core",
2384+
"windows-targets 0.52.5",
23852385
]
23862386

23872387
[[package]]
2388-
name = "winapi-i686-pc-windows-gnu"
2389-
version = "0.4.0"
2388+
name = "windows-core"
2389+
version = "0.56.0"
23902390
source = "registry+https://github.com/rust-lang/crates.io-index"
2391-
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
2391+
checksum = "4698e52ed2d08f8658ab0c39512a7c00ee5fe2688c65f8c0a4f06750d729f2a6"
2392+
dependencies = [
2393+
"windows-implement",
2394+
"windows-interface",
2395+
"windows-result",
2396+
"windows-targets 0.52.5",
2397+
]
23922398

23932399
[[package]]
2394-
name = "winapi-util"
2395-
version = "0.1.8"
2400+
name = "windows-implement"
2401+
version = "0.56.0"
23962402
source = "registry+https://github.com/rust-lang/crates.io-index"
2397-
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
2403+
checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b"
23982404
dependencies = [
2399-
"windows-sys 0.52.0",
2405+
"proc-macro2",
2406+
"quote",
2407+
"syn",
24002408
]
24012409

24022410
[[package]]
2403-
name = "winapi-x86_64-pc-windows-gnu"
2404-
version = "0.4.0"
2411+
name = "windows-interface"
2412+
version = "0.56.0"
24052413
source = "registry+https://github.com/rust-lang/crates.io-index"
2406-
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
2414+
checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc"
2415+
dependencies = [
2416+
"proc-macro2",
2417+
"quote",
2418+
"syn",
2419+
]
2420+
2421+
[[package]]
2422+
name = "windows-result"
2423+
version = "0.1.1"
2424+
source = "registry+https://github.com/rust-lang/crates.io-index"
2425+
checksum = "749f0da9cc72d82e600d8d2e44cadd0b9eedb9038f71a1c58556ac1c5791813b"
2426+
dependencies = [
2427+
"windows-targets 0.52.5",
2428+
]
24072429

24082430
[[package]]
24092431
name = "windows-sys"

src/tools/rust-analyzer/Cargo.toml

+1-1
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"

src/tools/rust-analyzer/crates/flycheck/Cargo.toml

+1-1
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

src/tools/rust-analyzer/crates/flycheck/src/command.rs

+11-5
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)

src/tools/rust-analyzer/crates/flycheck/src/lib.rs

+27
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

src/tools/rust-analyzer/crates/hir-expand/src/db.rs

+1-1
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
}

src/tools/rust-analyzer/crates/hir-expand/src/files.rs

+9-13
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
}

src/tools/rust-analyzer/crates/hir-expand/src/lib.rs

+14-2
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)