Skip to content

Commit b29404f

Browse files
Fixing issue when rust-analyzer binary is not found
Signed-off-by: Dusan Malusev <dusan@dusanmalusev.dev>
1 parent c3dbeae commit b29404f

File tree

6 files changed

+93
-69
lines changed

6 files changed

+93
-69
lines changed

Cargo.lock

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

rad/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rad"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
readme = "../README.md"
66
license = "Apache-2.0"

rad/src/commands/check.rs

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::io::ErrorKind;
2+
13
use futures::future::join_all;
24
use time::ext::NumericalDuration;
35
use time::format_description::FormatItem;
@@ -6,7 +8,7 @@ use time::{format_description, Date};
68
use tracing::{debug, info, warn};
79

810
use super::command::{Command, Errors};
9-
use rust_analyzer_downloader::rust_analyzer::version::{get, Version};
11+
use rust_analyzer_downloader::rust_analyzer::version::{get, Error as VersionError, Version};
1012
use rust_analyzer_downloader::services::downloader::Downloader;
1113
use rust_analyzer_downloader::services::versions::{Paging, ReleasesJsonResponse, Versions};
1214

@@ -64,7 +66,7 @@ impl CheckCommand {
6466
async fn download(
6567
self,
6668
data: Vec<ReleasesJsonResponse>,
67-
current_version: Version,
69+
current_version: Option<Version>,
6870
) -> Result<(), Errors> {
6971
let futures = data.iter().map(|release| async {
7072
let release = release.tag_name.as_str();
@@ -82,11 +84,14 @@ impl CheckCommand {
8284
return Ok(());
8385
}
8486

85-
let new_version_exists = compare_versions(
86-
&self.date_format,
87-
current_version.date_version.as_str(),
88-
release,
89-
)?;
87+
let new_version_exists = match current_version {
88+
Some(ref current_version) => compare_versions(
89+
&self.date_format,
90+
current_version.date_version.as_str(),
91+
release,
92+
)?,
93+
None => true,
94+
};
9095

9196
if new_version_exists {
9297
if self.should_download {
@@ -101,9 +106,10 @@ impl CheckCommand {
101106
} else {
102107
info!(release = release, "New version available");
103108
}
109+
} else {
110+
info!("Current version is up to date");
104111
}
105112

106-
info!("Current version is up to date");
107113
Result::<(), Errors>::Ok(())
108114
});
109115

@@ -123,12 +129,26 @@ impl CheckCommand {
123129
impl Command for CheckCommand {
124130
#[tracing::instrument]
125131
async fn execute(self) -> Result<(), Errors> {
126-
let current_version = get().await?;
132+
let current_version = match get().await {
133+
Ok(version) => Some(version),
134+
Err(VersionError::Io(err)) if err.kind() == ErrorKind::NotFound => {
135+
warn!("No rust-analyzer binary found, downloading latest version");
136+
None
137+
}
138+
Err(err) => {
139+
warn!(error = ?err, "Failed to get current version");
140+
return Err(err.into());
141+
}
142+
};
143+
144+
if current_version.is_some() {
145+
let current_version = current_version.as_ref().unwrap();
146+
debug!(
147+
"Current version is {} (Semantic Version: {})",
148+
current_version.date_version, current_version.semantic_version
149+
);
150+
}
127151

128-
debug!(
129-
"Current version is {} (Semantic Version: {})",
130-
current_version.date_version, current_version.semantic_version
131-
);
132152
let version = self.versions.get(1, 2).await?;
133153

134154
if let Paging::Next(_, data) = version {

0 commit comments

Comments
 (0)