@@ -4,7 +4,7 @@ import { commands, Disposable, OutputChannel, QuickPickItem, window } from 'vsco
44import { LeanClient } from './leanclient'
55import { batchExecute , displayResultError , ExecutionExitCode , ExecutionResult } from './utils/batch'
66import { LeanClientProvider } from './utils/clientProvider'
7- import { cacheNotFoundError , lake , LakeRunner } from './utils/lake'
7+ import { FetchMathlibCacheResult , lake , LakeRunner } from './utils/lake'
88import { lean } from './utils/leanEditorProvider'
99import { DirectGitDependency , Manifest , ManifestReadError , parseManifestInFolder } from './utils/manifest'
1010import { displayNotification , displayNotificationWithInput , displayNotificationWithOptionalInput } from './utils/notifs'
@@ -33,8 +33,8 @@ export class ProjectOperationProvider implements Disposable {
3333
3434 private async buildProject ( ) {
3535 await this . runOperation ( 'Build Project' , async lakeRunner => {
36- const fetchResult : 'Success' | 'CacheNotAvailable' | 'Cancelled' = await this . tryFetchingCache ( lakeRunner )
37- if ( fetchResult === 'Cancelled ') {
36+ const fetchResult : 'Success' | 'Failure' = await lakeRunner . tryFetchMathlibCacheWithError ( )
37+ if ( fetchResult !== 'Success ') {
3838 return
3939 }
4040
@@ -73,11 +73,11 @@ export class ProjectOperationProvider implements Disposable {
7373 return
7474 }
7575
76- const checkResult : 'Yes ' | 'No ' | 'Cancelled' = await lakeRunner . isMathlibCacheGetAvailable ( )
76+ const checkResult : 'Available ' | 'Unavailable ' | 'Cancelled' = await lakeRunner . isMathlibCacheGetAvailable ( )
7777 if ( checkResult === 'Cancelled' ) {
7878 return
7979 }
80- if ( checkResult === 'No ' ) {
80+ if ( checkResult === 'Unavailable ' ) {
8181 displayNotification ( 'Information' , 'Project cleaned successfully.' )
8282 return
8383 }
@@ -94,12 +94,8 @@ export class ProjectOperationProvider implements Disposable {
9494 return
9595 }
9696
97- const fetchResult : ExecutionResult = await lakeRunner . fetchMathlibCache ( )
98- if ( fetchResult . exitCode === ExecutionExitCode . Cancelled ) {
99- return
100- }
101- if ( fetchResult . exitCode !== ExecutionExitCode . Success ) {
102- void displayResultError ( fetchResult , 'Cannot fetch Mathlib build artifact cache.' )
97+ const fetchResult : 'Success' | 'Failure' = await lakeRunner . tryFetchMathlibCacheWithError ( )
98+ if ( fetchResult !== 'Success' ) {
10399 return
104100 }
105101 displayNotification ( 'Information' , 'Mathlib build artifact cache fetched successfully.' )
@@ -108,16 +104,19 @@ export class ProjectOperationProvider implements Disposable {
108104
109105 private async fetchMathlibCache ( ) {
110106 await this . runOperation ( 'Fetch Mathlib Build Cache' , async lakeRunner => {
111- const result : ExecutionResult = await lakeRunner . fetchMathlibCache ( )
112- if ( result . exitCode === ExecutionExitCode . Cancelled ) {
107+ const fetchResult : FetchMathlibCacheResult = await lakeRunner . fetchMathlibCache ( )
108+ if ( fetchResult . kind === ' Cancelled' ) {
113109 return
114110 }
115- if ( result . exitCode !== ExecutionExitCode . Success ) {
116- if ( result . stderr . includes ( cacheNotFoundError ) ) {
117- displayNotification ( 'Error' , 'This command cannot be used in non-Mathlib projects.' )
118- return
119- }
120- displayResultError ( result , 'Cannot fetch Mathlib build artifact cache.' )
111+ if ( fetchResult . kind === 'CacheUnavailable' ) {
112+ displayNotification ( 'Error' , 'This command cannot be used in non-Mathlib projects.' )
113+ return
114+ }
115+ if ( fetchResult . result . exitCode === ExecutionExitCode . Cancelled ) {
116+ return
117+ }
118+ if ( fetchResult . result . exitCode !== ExecutionExitCode . Success ) {
119+ displayResultError ( fetchResult . result , 'Cannot fetch Mathlib build artifact cache.' )
121120 return
122121 }
123122
@@ -175,12 +174,22 @@ export class ProjectOperationProvider implements Disposable {
175174 return
176175 }
177176
178- const result : ExecutionResult = await lakeRunner . fetchMathlibCacheForFile ( relativeDocUri )
179- if ( result . exitCode === ExecutionExitCode . Cancelled ) {
177+ const fetchResult : FetchMathlibCacheResult = await lakeRunner . fetchMathlibCacheForFile ( relativeDocUri )
178+ if ( fetchResult . kind === ' Cancelled' ) {
180179 return
181180 }
182- if ( result . exitCode !== ExecutionExitCode . Success ) {
183- displayResultError ( result , `Cannot fetch Mathlib build artifact cache for '${ relativeDocUri . fsPath } '.` )
181+ if ( fetchResult . kind === 'CacheUnavailable' ) {
182+ displayNotification ( 'Error' , 'This command cannot be used in non-Mathlib projects.' )
183+ return
184+ }
185+ if ( fetchResult . result . exitCode === ExecutionExitCode . Cancelled ) {
186+ return
187+ }
188+ if ( fetchResult . result . exitCode !== ExecutionExitCode . Success ) {
189+ displayResultError (
190+ fetchResult . result ,
191+ `Cannot fetch Mathlib build artifact cache for '${ relativeDocUri . fsPath } '.` ,
192+ )
184193 return
185194 }
186195
@@ -260,7 +269,10 @@ export class ProjectOperationProvider implements Disposable {
260269 return
261270 }
262271
263- await this . tryFetchingCache ( lakeRunner )
272+ const fetchResult : 'Success' | 'Failure' = await lakeRunner . tryFetchMathlibCacheWithError ( )
273+ if ( fetchResult !== 'Success' ) {
274+ return
275+ }
264276
265277 const localToolchainPath : string = join ( activeFolderUri . fsPath , 'lean-toolchain' )
266278 const dependencyToolchainPath : string = join (
@@ -378,18 +390,6 @@ export class ProjectOperationProvider implements Disposable {
378390 return [ localToolchain , dependencyToolchain ]
379391 }
380392
381- private async tryFetchingCache ( lakeRunner : LakeRunner ) : Promise < 'Success' | 'CacheNotAvailable' | 'Cancelled' > {
382- const fetchResult : ExecutionResult = await lakeRunner . fetchMathlibCache ( true )
383- switch ( fetchResult . exitCode ) {
384- case ExecutionExitCode . Success :
385- return 'Success'
386- case ExecutionExitCode . Cancelled :
387- return 'Cancelled'
388- default :
389- return 'CacheNotAvailable'
390- }
391- }
392-
393393 private async runOperation ( context : string , command : ( lakeRunner : LakeRunner ) => Promise < void > ) {
394394 if ( this . isRunningOperation ) {
395395 displayNotification (
0 commit comments