@@ -125,80 +125,74 @@ async function serverEnv(toolchain) {
125
125
return env
126
126
}
127
127
128
+ /**
129
+ * Install rls-preview, rust-src, rust-analysis
130
+ * @param {string } toolchain
131
+ */
132
+ async function installRlsComponents ( toolchain ) {
133
+ try {
134
+ await exec ( `rustup component add rls-preview --toolchain ${ toolchain } ` )
135
+ }
136
+ catch ( e ) {
137
+ let suggestedVersion
138
+ if ( toolchain . startsWith ( 'nightly' ) ) {
139
+ // 'rls-preview' not available search for a decent suggestion
140
+ suggestedVersion = await suggestChannelOrDated ( 'nightly' ) . catch ( e => console . warn ( e ) )
141
+ }
142
+ const note = {
143
+ detail : 'Try configuring another toolchain, like a dated nightly or `beta`' ,
144
+ dismissable : true ,
145
+ _src : 'ide-rust' ,
146
+ buttons : [ {
147
+ text : 'Configure' ,
148
+ onDidClick : ( ) => atom . workspace . open ( 'atom://config/packages/ide-rust' )
149
+ } ]
150
+ }
151
+ if ( suggestedVersion ) {
152
+ note . buttons . push ( {
153
+ text : `Use ${ suggestedVersion } ` ,
154
+ onDidClick : ( ) => atom . config . set ( 'ide-rust.rlsToolchain' , suggestedVersion )
155
+ } )
156
+ }
157
+ atom . notifications . addError ( `\`rls-preview\` was not found on \`${ toolchain } \`` , note )
158
+ throw e
159
+ }
160
+
161
+ try {
162
+ await exec ( `rustup component add rust-src --toolchain ${ toolchain } ` )
163
+ await exec ( `rustup component add rust-analysis --toolchain ${ toolchain } ` )
164
+ }
165
+ catch ( e ) {
166
+ atom . notifications . addError ( `\`rust-src\`/\`rust-analysis\` not found on \`${ toolchain } \`` , {
167
+ dismissable : true
168
+ } )
169
+ throw e
170
+ }
171
+ }
172
+
128
173
// ongoing promise
129
174
let _checkingRls
130
175
131
176
/**
132
177
* Check for and install Rls
133
- * @param {BusySignalService } [ busySignalService]
178
+ * @param {? BusySignalService } busySignalService
134
179
* @return {Promise<*> } rls installed
135
180
*/
136
- function checkRls ( busySignalService ) {
137
- let toolchain = configToolchain ( )
138
-
181
+ async function checkRls ( busySignalService ) {
139
182
if ( _checkingRls ) return _checkingRls
140
183
141
- _checkingRls = exec ( `rustup component list --toolchain ${ toolchain } ` ) . then ( results => {
142
- const { stdout } = results
184
+ const toolchain = configToolchain ( )
185
+ _checkingRls = ( async ( ) => {
186
+ let { stdout : toolchainList } = await exec ( `rustup component list --toolchain ${ toolchain } ` )
143
187
if (
144
- stdout . search ( / ^ r l s - p r e v i e w .* \( ( d e f a u l t | i n s t a l l e d ) \) $ / m) >= 0 &&
145
- stdout . search ( / ^ r u s t - a n a l y s i s .* \( ( d e f a u l t | i n s t a l l e d ) \) $ / m) >= 0 &&
146
- stdout . search ( / ^ r u s t - s r c .* \( ( d e f a u l t | i n s t a l l e d ) \) $ / m) >= 0
188
+ toolchainList . search ( / ^ r l s - p r e v i e w .* \( ( d e f a u l t | i n s t a l l e d ) \) $ / m) >= 0 &&
189
+ toolchainList . search ( / ^ r u s t - a n a l y s i s .* \( ( d e f a u l t | i n s t a l l e d ) \) $ / m) >= 0 &&
190
+ toolchainList . search ( / ^ r u s t - s r c .* \( ( d e f a u l t | i n s t a l l e d ) \) $ / m) >= 0
147
191
) {
148
- // Have RLS
149
- return
192
+ return // have rls
150
193
}
151
-
152
- // Don't have RLS
153
- let installRlsPromise = exec ( `rustup component add rls-preview --toolchain ${ toolchain } ` )
154
- . catch ( async e => {
155
- if ( toolchain . startsWith ( 'nightly' ) ) {
156
- // 'rls-preview' not available search for a decent suggestion
157
- let suggestedVersion
158
- try {
159
- suggestedVersion = await suggestChannelOrDated ( 'nightly' )
160
- } catch ( e ) {
161
- console . warn ( e )
162
- }
163
- if ( suggestedVersion ) throw [ e , suggestedVersion ]
164
- }
165
- throw [ e ]
166
- } )
167
- . catch ( e => {
168
- let latestRlsNightly = e [ 1 ]
169
-
170
- const note = {
171
- detail : 'Try configuring another toolchain, like a dated nightly or `beta`' ,
172
- dismissable : true ,
173
- _src : 'ide-rust' ,
174
- buttons : [ {
175
- text : 'Configure' ,
176
- onDidClick : ( ) => atom . workspace . open ( 'atom://config/packages/ide-rust' )
177
- } ]
178
- }
179
- if ( latestRlsNightly ) {
180
- note . buttons . push ( {
181
- text : `Use ${ latestRlsNightly } ` ,
182
- onDidClick : ( ) => atom . config . set ( 'ide-rust.rlsToolchain' , latestRlsNightly )
183
- } )
184
- }
185
-
186
- atom . notifications . addError ( `\`rls-preview\` was not found on \`${ toolchain } \`` , note )
187
-
188
- e [ 0 ] . _logged = true
189
- throw e [ 0 ]
190
- } )
191
- . then ( ( ) => exec ( `rustup component add rust-src --toolchain ${ toolchain } ` ) )
192
- . then ( ( ) => exec ( `rustup component add rust-analysis --toolchain ${ toolchain } ` ) )
193
- . catch ( e => {
194
- if ( ! e . _logged ) {
195
- atom . notifications . addError ( `\`rust-src\`/\`rust-analysis\` not found on \`${ toolchain } \`` , {
196
- dismissable : true
197
- } )
198
- }
199
- throw e
200
- } )
201
-
194
+ // try to install rls
195
+ const installRlsPromise = installRlsComponents ( toolchain )
202
196
if ( busySignalService ) {
203
197
busySignalService . reportBusyWhile (
204
198
`Adding components rls-preview, rust-src, rust-analysis` ,
@@ -207,14 +201,13 @@ function checkRls(busySignalService) {
207
201
}
208
202
209
203
return installRlsPromise
210
- } )
204
+ } ) ( )
211
205
212
206
try {
213
- return _checkingRls
207
+ return await _checkingRls
214
208
}
215
209
finally {
216
- let clearOngoing = ( ) => _checkingRls = null
217
- _checkingRls . then ( clearOngoing ) . catch ( clearOngoing )
210
+ _checkingRls = null
218
211
}
219
212
}
220
213
0 commit comments