Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vscode-lean4/src/leanclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export class LeanClient implements Disposable {

const progressOptions: ProgressOptions = {
location: ProgressLocation.Notification,
title: '[Server Startup] Starting Lean language server and cloning missing packages [(Click for details)](command:lean4.troubleshooting.showOutput)',
title: '[Server Startup] Starting Lean language server and cloning missing project dependencies [(Click for details)](command:lean4.troubleshooting.showOutput)',
cancellable: false,
}
await window.withProgress(
Expand Down
15 changes: 13 additions & 2 deletions vscode-lean4/src/projectinit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,23 @@ Open this project instead?`
return
}

const fetchResult: 'Success' | 'Failure' = await lake({
const lakeRunner = lake({
channel: this.channel,
cwdUri: projectFolder,
context: downloadProjectContext,
toolchainUpdateMode: 'UpdateAutomatically',
}).tryFetchMathlibCacheWithError()
})

const resolveResult: LakeRunnerResult = await lakeRunner.resolveDeps()
if (resolveResult.kind === 'Cancelled') {
return
}
if (resolveResult.kind !== 'Success') {
displayLakeRunnerError(resolveResult, 'Cannot clone missing project dependencies.')
return
}

const fetchResult: 'Success' | 'Failure' = await lakeRunner.tryFetchMathlibCacheWithError()
if (fetchResult !== 'Success') {
return
}
Expand Down
49 changes: 27 additions & 22 deletions vscode-lean4/src/projectoperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { commands, Disposable, OutputChannel, QuickPickItem, window } from 'vsco
import { LeanClient } from './leanclient'
import { LeanClientProvider } from './utils/clientProvider'
import {
CacheGetAvailabilityResult,
displayLakeRunnerError,
FetchMathlibCacheResult,
lake,
Expand Down Expand Up @@ -39,6 +38,15 @@ export class ProjectOperationProvider implements Disposable {

private async buildProject() {
await this.runOperation('Build Project', async lakeRunner => {
const resolveResult: LakeRunnerResult = await lakeRunner.resolveDeps()
if (resolveResult.kind === 'Cancelled') {
return
}
if (resolveResult.kind !== 'Success') {
displayLakeRunnerError(resolveResult, 'Cannot clone missing project dependencies.')
return
}

const fetchResult: 'Success' | 'Failure' = await lakeRunner.tryFetchMathlibCacheWithError()
if (fetchResult !== 'Success') {
return
Expand Down Expand Up @@ -79,36 +87,33 @@ export class ProjectOperationProvider implements Disposable {
return
}

const checkResult: CacheGetAvailabilityResult = await lakeRunner.isMathlibCacheGetAvailable()
if (checkResult.kind === 'Cancelled') {
return
}
if (checkResult.kind === 'CacheUnavailable') {
displayNotification('Information', 'Project cleaned successfully.')
return
}
if (checkResult.kind !== 'CacheAvailable') {
displayLakeRunnerError(checkResult, 'Cannot check availability of Mathlib cache.')
return
}

const fetchMessage = "Project cleaned successfully. Do you wish to fetch Mathlib's build artifact cache?"
const fetchInput = 'Fetch Cache'
const fetchChoice: string | undefined = await displayNotificationWithInput(
const rebuildMessage = 'Project cleaned successfully. Do you wish to rebuild the project?'
const rebuildInput = 'Rebuild Project'
const rebuildChoice: string | undefined = await displayNotificationWithInput(
'Information',
fetchMessage,
[fetchInput],
'Do Not Fetch Cache',
rebuildMessage,
[rebuildInput],
'Do Not Rebuild',
)
if (fetchChoice !== fetchInput) {
if (rebuildChoice !== rebuildInput) {
return
}

const fetchResult: 'Success' | 'Failure' = await lakeRunner.tryFetchMathlibCacheWithError()
if (fetchResult !== 'Success') {
return
}
displayNotification('Information', 'Mathlib build artifact cache fetched successfully.')

const buildResult: LakeRunnerResult = await lakeRunner.build()
if (buildResult.kind === 'Cancelled') {
return
}
if (buildResult.kind !== 'Success') {
displayLakeRunnerError(buildResult, 'Cannot build project.')
return
}

displayNotification('Information', 'Project rebuilt successfully.')
})
}

Expand Down
4 changes: 4 additions & 0 deletions vscode-lean4/src/utils/lake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export class LakeRunner {
)
}

async resolveDeps(): Promise<LakeRunnerResult> {
return this.runLakeCommandWithProgress('resolve-deps', [], 'Cloning missing project dependencies')
}

async isMathlibCacheGetAvailable(): Promise<CacheGetAvailabilityResult> {
const result: LakeRunnerResult = await this.runLakeCommandWithProgress(
'exe',
Expand Down
Loading