Skip to content

Commit 1003808

Browse files
committed
internal: report errors on failure; clippy
1 parent f79707b commit 1003808

File tree

12 files changed

+56
-58
lines changed

12 files changed

+56
-58
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ doctest = false
1414
[dependencies]
1515
anyhow.workspace = true
1616
cargo_metadata.workspace = true
17-
crossbeam-channel.workspace = true
1817
rustc-hash.workspace = true
1918
semver.workspace = true
2019
serde_json.workspace = true

crates/project-model/src/project_json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl ProjectJson {
175175

176176
#[derive(Serialize, Deserialize, Debug, Clone)]
177177
pub struct ProjectJsonData {
178-
pub sysroot: Option<Utf8PathBuf>,
178+
sysroot: Option<Utf8PathBuf>,
179179
sysroot_src: Option<Utf8PathBuf>,
180180
crates: Vec<CrateData>,
181181
}

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/config.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,6 @@ config_data! {
272272
/// The warnings will be indicated by a blue squiggly underline in code
273273
/// and a blue icon in the `Problems Panel`.
274274
diagnostics_warningsAsInfo: Vec<String> = vec![],
275-
/// Enables automatic discovery of projects using the discoverCommand.
276-
///
277-
/// Setting this command will result in rust-analyzer starting indexing
278-
/// only once a Rust file has been opened.
279-
discoverCommand: Option<Vec<String>> = None,
280275
/// These directories will be ignored by rust-analyzer. They are
281276
/// relative to the workspace root, and globs are not supported. You may
282277
/// also need to add the folders to Code's `files.watcherExclude`.
@@ -441,6 +436,12 @@ config_data! {
441436
/// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
442437
typing_autoClosingAngleBrackets_enable: bool = false,
443438

439+
/// Enables automatic discovery of projects using the discoverCommand.
440+
///
441+
/// Setting this command will result in rust-analyzer starting indexing
442+
/// only once a Rust file has been opened.
443+
workspace_discoverCommand: Option<Vec<String>> = None,
444+
444445
/// Workspace symbol search kind.
445446
workspace_symbol_search_kind: WorkspaceSymbolSearchKindDef = WorkspaceSymbolSearchKindDef::OnlyTypes,
446447
/// Limits the number of items returned from a workspace symbol search (Defaults to 128).
@@ -656,7 +657,7 @@ config_data! {
656657

657658
#[derive(Debug, Clone)]
658659
pub struct Config {
659-
pub(crate) discovered_projects: Vec<ProjectManifest>,
660+
discovered_projects: Vec<ProjectManifest>,
660661
/// The workspace roots as registered by the LSP client
661662
workspace_roots: Vec<AbsPathBuf>,
662663
caps: lsp_types::ClientCapabilities,
@@ -933,12 +934,10 @@ impl Config {
933934
pub fn add_linked_projects(&mut self, projects: Vec<ProjectJsonData>) {
934935
let linked_projects = &mut self.client_config.global.linkedProjects;
935936

936-
let mut new_projects: Vec<_> =
937-
projects.into_iter().map(ManifestOrProjectJson::ProjectJson).collect();
938-
937+
let new_projects = projects.into_iter().map(ManifestOrProjectJson::ProjectJson);
939938
match linked_projects {
940-
Some(projects) => projects.append(&mut new_projects),
941-
None => *linked_projects = Some(new_projects),
939+
Some(projects) => projects.append(&mut new_projects.collect::<Vec<_>>()),
940+
None => *linked_projects = Some(new_projects.collect::<Vec<_>>()),
942941
}
943942
}
944943

@@ -1322,7 +1321,7 @@ impl Config {
13221321
}
13231322

13241323
pub fn discover_command(&self) -> Option<Vec<String>> {
1325-
self.discoverCommand().clone()
1324+
self.workspace_discoverCommand().clone()
13261325
}
13271326

13281327
pub fn linked_or_discovered_projects(&self) -> Vec<LinkedProject> {
@@ -1589,7 +1588,7 @@ impl Config {
15891588
}
15901589

15911590
pub fn cargo_autoreload_config(&self) -> bool {
1592-
self.cargo_autoreload().to_owned() && self.discoverCommand().is_none()
1591+
self.cargo_autoreload().to_owned() && self.workspace_discoverCommand().is_none()
15931592
}
15941593

15951594
pub fn run_build_scripts(&self) -> bool {

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();

docs/user/generated_config.adoc

+8-8
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,6 @@ List of warnings that should be displayed with info severity.
426426
The warnings will be indicated by a blue squiggly underline in code
427427
and a blue icon in the `Problems Panel`.
428428
--
429-
[[rust-analyzer.discoverCommand]]rust-analyzer.discoverCommand (default: `null`)::
430-
+
431-
--
432-
Enables automatic discovery of projects using the discoverCommand.
433-
434-
Setting this command will result in rust-analyzer starting indexing
435-
only once a Rust file has been opened.
436-
--
437429
[[rust-analyzer.files.excludeDirs]]rust-analyzer.files.excludeDirs (default: `[]`)::
438430
+
439431
--
@@ -993,6 +985,14 @@ Show documentation.
993985
--
994986
Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
995987
--
988+
[[rust-analyzer.workspace.discoverCommand]]rust-analyzer.workspace.discoverCommand (default: `null`)::
989+
+
990+
--
991+
Enables automatic discovery of projects using the discoverCommand.
992+
993+
Setting this command will result in rust-analyzer starting indexing
994+
only once a Rust file has been opened.
995+
--
996996
[[rust-analyzer.workspace.symbol.search.kind]]rust-analyzer.workspace.symbol.search.kind (default: `"only_types"`)::
997997
+
998998
--

editors/code/package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -979,17 +979,6 @@
979979
"type": "string"
980980
}
981981
},
982-
"rust-analyzer.discoverCommand": {
983-
"markdownDescription": "Enables automatic discovery of projects using the discoverCommand.\n\nSetting this command will result in rust-analyzer starting indexing\nonly once a Rust file has been opened.",
984-
"default": null,
985-
"type": [
986-
"null",
987-
"array"
988-
],
989-
"items": {
990-
"type": "string"
991-
}
992-
},
993982
"rust-analyzer.files.excludeDirs": {
994983
"markdownDescription": "These directories will be ignored by rust-analyzer. They are\nrelative to the workspace root, and globs are not supported. You may\nalso need to add the folders to Code's `files.watcherExclude`.",
995984
"default": [],
@@ -1711,6 +1700,17 @@
17111700
"default": false,
17121701
"type": "boolean"
17131702
},
1703+
"rust-analyzer.workspace.discoverCommand": {
1704+
"markdownDescription": "Enables automatic discovery of projects using the discoverCommand.\n\nSetting this command will result in rust-analyzer starting indexing\nonly once a Rust file has been opened.",
1705+
"default": null,
1706+
"type": [
1707+
"null",
1708+
"array"
1709+
],
1710+
"items": {
1711+
"type": "string"
1712+
}
1713+
},
17141714
"rust-analyzer.workspace.symbol.search.kind": {
17151715
"markdownDescription": "Workspace symbol search kind.",
17161716
"default": "only_types",

0 commit comments

Comments
 (0)