1
+ use std:: io:: ErrorKind ;
2
+
1
3
use futures:: future:: join_all;
2
4
use time:: ext:: NumericalDuration ;
3
5
use time:: format_description:: FormatItem ;
@@ -6,7 +8,7 @@ use time::{format_description, Date};
6
8
use tracing:: { debug, info, warn} ;
7
9
8
10
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 } ;
10
12
use rust_analyzer_downloader:: services:: downloader:: Downloader ;
11
13
use rust_analyzer_downloader:: services:: versions:: { Paging , ReleasesJsonResponse , Versions } ;
12
14
@@ -64,7 +66,7 @@ impl CheckCommand {
64
66
async fn download (
65
67
self ,
66
68
data : Vec < ReleasesJsonResponse > ,
67
- current_version : Version ,
69
+ current_version : Option < Version > ,
68
70
) -> Result < ( ) , Errors > {
69
71
let futures = data. iter ( ) . map ( |release| async {
70
72
let release = release. tag_name . as_str ( ) ;
@@ -82,11 +84,14 @@ impl CheckCommand {
82
84
return Ok ( ( ) ) ;
83
85
}
84
86
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
+ } ;
90
95
91
96
if new_version_exists {
92
97
if self . should_download {
@@ -101,9 +106,10 @@ impl CheckCommand {
101
106
} else {
102
107
info ! ( release = release, "New version available" ) ;
103
108
}
109
+ } else {
110
+ info ! ( "Current version is up to date" ) ;
104
111
}
105
112
106
- info ! ( "Current version is up to date" ) ;
107
113
Result :: < ( ) , Errors > :: Ok ( ( ) )
108
114
} ) ;
109
115
@@ -123,12 +129,26 @@ impl CheckCommand {
123
129
impl Command for CheckCommand {
124
130
#[ tracing:: instrument]
125
131
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
+ }
127
151
128
- debug ! (
129
- "Current version is {} (Semantic Version: {})" ,
130
- current_version. date_version, current_version. semantic_version
131
- ) ;
132
152
let version = self . versions . get ( 1 , 2 ) . await ?;
133
153
134
154
if let Paging :: Next ( _, data) = version {
0 commit comments