Skip to content

Commit e62932f

Browse files
committed
internal: report errors on failure; clippy
1 parent f240858 commit e62932f

File tree

6 files changed

+24
-23
lines changed

6 files changed

+24
-23
lines changed

crates/flycheck/src/json_workspace.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ pub struct JsonWorkspaceHandle {
4646
#[derive(Debug, Clone, Deserialize, Serialize)]
4747
#[serde(tag = "type")]
4848
pub enum DiscoverProjectMessage {
49+
Error { message: String },
4950
Progress { message: String },
5051
Finished { project_json: Vec<ProjectJsonData> },
5152
}
5253

5354
impl ParseFromLine for DiscoverProjectMessage {
5455
fn from_line(line: &str, _error: &mut String) -> Option<Self> {
55-
let value = serde_json::from_str::<serde_json::Value>(&line).unwrap();
56-
57-
// let mut deserializer = serde_json::Deserializer::from_str(line);
58-
// deserializer.disable_recursion_limit();
56+
let Ok(value) = serde_json::from_str::<serde_json::Value>(line) else {
57+
return Some(DiscoverProjectMessage::Error { message: line.to_owned() });
58+
};
5959

6060
if let Ok(project) = serde_json::from_value::<ProjectJsonData>(value.clone()) {
6161
return Some(DiscoverProjectMessage::Finished { project_json: vec![project] });

crates/project-model/src/workspace.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
utf8_stdout, CargoConfig, CargoWorkspace, InvocationStrategy, ManifestPath, Package,
3131
ProjectJson, ProjectManifest, Sysroot, TargetData, TargetKind, WorkspaceBuildScripts,
3232
};
33-
use tracing::{info, Level, error, debug};
33+
use tracing::{debug, error, info, Level};
3434

3535
pub type FileLoader<'a> = &'a mut dyn for<'b> FnMut(&'b AbsPath) -> Option<FileId>;
3636

@@ -357,7 +357,6 @@ impl ProjectWorkspace {
357357
) -> ProjectWorkspace {
358358
let sysroot = match (project_json.sysroot.clone(), project_json.sysroot_src.clone()) {
359359
(Some(sysroot), Some(sysroot_src)) => {
360-
361360
Ok(Sysroot::load(sysroot, Some(Ok(sysroot_src)), false))
362361
}
363362
(Some(sysroot), None) => {

crates/rust-analyzer/src/bin/main.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,11 @@ fn run_server() -> anyhow::Result<()> {
257257
return Err(e.into());
258258
}
259259

260-
if config.discover_command().is_none() {
261-
if !config.has_linked_projects() && config.detached_files().is_empty() {
262-
config.rediscover_workspaces();
263-
}
260+
if config.discover_command().is_none()
261+
&& !config.has_linked_projects()
262+
&& config.detached_files().is_empty()
263+
{
264+
config.rediscover_workspaces();
264265
}
265266

266267
// If the io_threads have an error, there's usually an error on the main

crates/rust-analyzer/src/lsp/utils.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,21 @@ impl GlobalState {
7575
}
7676

7777
/// Sends a notification to the client containing the error `message`.
78-
/// If `additional_info` is [`Some`], appends a note to the notification telling to check the logs.
79-
/// This will always log `message` + `additional_info` to the server's error log.
78+
/// If `additional_info` is [`Some`], the details will be included in the server's logs.
8079
pub(crate) fn show_and_log_error(&mut self, message: String, additional_info: Option<String>) {
8180
match additional_info {
8281
Some(additional_info) => {
8382
tracing::error!("{}:\n{}", &message, &additional_info);
84-
self.show_message(
85-
lsp_types::MessageType::ERROR,
86-
message,
87-
tracing::enabled!(tracing::Level::ERROR),
88-
);
8983
}
9084
None => {
9185
tracing::error!("{}", &message);
92-
self.send_notification::<lsp_types::notification::ShowMessage>(
93-
lsp_types::ShowMessageParams { typ: lsp_types::MessageType::ERROR, message },
94-
);
9586
}
9687
}
88+
self.show_message(
89+
lsp_types::MessageType::ERROR,
90+
message,
91+
tracing::enabled!(tracing::Level::ERROR),
92+
);
9793
}
9894

9995
/// rust-analyzer is resilient -- if it fails, this doesn't usually affect

crates/rust-analyzer/src/main_loop.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ impl GlobalState {
343343
}
344344
Event::DiscoverProject(message) => {
345345
self.handle_discover_msg(message);
346-
// Coalesce many project discovery events into a single loop turn
346+
// Coalesce many project discovery events into a single loop turn.
347347
while let Ok(message) = self.discover_receiver.try_recv() {
348348
self.handle_discover_msg(message);
349349
}
@@ -752,7 +752,7 @@ impl GlobalState {
752752
let id = from_proto::file_id(&snap, &uri).expect("unable to get FileId");
753753
if let Ok(crates) = &snap.analysis.crates_for(id) {
754754
if crates.is_empty() {
755-
if let Some(_) = snap.config.discover_command() {
755+
if snap.config.discover_command().is_some() {
756756
sender.send(Task::DiscoverLinkedProjects(uri)).unwrap();
757757
}
758758
} else {
@@ -794,6 +794,10 @@ impl GlobalState {
794794
flycheck::DiscoverProjectMessage::Progress { message } => {
795795
self.report_progress("Buck", Progress::Report, Some(message), None, None)
796796
}
797+
flycheck::DiscoverProjectMessage::Error { message } => {
798+
self.show_and_log_error(message.clone(), None);
799+
self.report_progress("Buck", Progress::End, Some(message), None, None)
800+
}
797801
}
798802
}
799803

crates/rust-analyzer/src/reload.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ impl GlobalState {
8383
);
8484
}
8585

86-
if self.config.linked_or_discovered_projects() != old_config.linked_or_discovered_projects() {
86+
if self.config.linked_or_discovered_projects() != old_config.linked_or_discovered_projects()
87+
{
8788
self.fetch_workspaces_queue.request_op("discovered projects changed".to_owned(), true)
8889
} else if self.config.flycheck() != old_config.flycheck() {
8990
self.reload_flycheck();

0 commit comments

Comments
 (0)