Skip to content

Commit 5c6a124

Browse files
committed
Pop up a notification for the MSRV project loading warning
1 parent c8d9d5a commit 5c6a124

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

Diff for: src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs

+19
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,25 @@ impl GlobalState {
637637
}
638638
});
639639
}
640+
641+
pub(crate) fn check_workspaces_msrv(&self) -> impl Iterator<Item = String> + '_ {
642+
self.workspaces.iter().filter_map(|ws| {
643+
if let Some(toolchain) = &ws.toolchain {
644+
if *toolchain < crate::MINIMUM_SUPPORTED_TOOLCHAIN_VERSION {
645+
return Some(format!(
646+
"Workspace `{}` is using an outdated toolchain version `{}` but \
647+
rust-analyzer only supports `{}` and higher.\n\
648+
Consider using the rust-analyzer rustup component for your toolchain or
649+
upgrade your toolchain to a supported version.\n\n",
650+
ws.manifest_or_root(),
651+
toolchain,
652+
crate::MINIMUM_SUPPORTED_TOOLCHAIN_VERSION,
653+
));
654+
}
655+
}
656+
None
657+
})
658+
}
640659
}
641660

642661
impl Drop for GlobalState {

Diff for: src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,15 @@ impl GlobalState {
178178
}
179179

180180
if !self.workspaces.is_empty() {
181+
self.check_workspaces_msrv().for_each(|e| {
182+
status.health |= lsp_ext::Health::Warning;
183+
format_to!(message, "{e}");
184+
});
185+
181186
let proc_macro_clients =
182187
self.proc_macro_clients.iter().map(Some).chain(iter::repeat_with(|| None));
183188

184189
for (ws, proc_macro_client) in self.workspaces.iter().zip(proc_macro_clients) {
185-
if let Some(toolchain) = &ws.toolchain {
186-
if *toolchain < crate::MINIMUM_SUPPORTED_TOOLCHAIN_VERSION {
187-
status.health |= lsp_ext::Health::Warning;
188-
format_to!(
189-
message,
190-
"Workspace `{}` is using an outdated toolchain version `{}` but \
191-
rust-analyzer only supports `{}` and higher.\n\
192-
Consider using the rust-analyzer rustup component for your toolchain or
193-
upgrade your toolchain to a supported version.\n\n",
194-
ws.manifest_or_root(),
195-
toolchain,
196-
crate::MINIMUM_SUPPORTED_TOOLCHAIN_VERSION,
197-
);
198-
}
199-
}
200-
201190
if let ProjectWorkspaceKind::Cargo { error: Some(error), .. }
202191
| ProjectWorkspaceKind::DetachedFile {
203192
cargo: Some((_, _, Some(error))), ..
@@ -529,6 +518,11 @@ impl GlobalState {
529518
// we don't care about build-script results, they are stale.
530519
// FIXME: can we abort the build scripts here if they are already running?
531520
self.workspaces = Arc::new(workspaces);
521+
self.check_workspaces_msrv().for_each(|message| {
522+
self.send_notification::<lsp_types::notification::ShowMessage>(
523+
lsp_types::ShowMessageParams { typ: lsp_types::MessageType::WARNING, message },
524+
);
525+
});
532526

533527
if self.config.run_build_scripts(None) {
534528
self.build_deps_changed = false;

0 commit comments

Comments
 (0)