Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [lean4web] customizable project precondition checks #497

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions vscode-lean4/src/diagnostics/setupDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SemVer } from 'semver'
import { OutputChannel, commands } from 'vscode'
import { ExtUri, FileUri, extUriToCwdUri } from '../utils/exturi'
import { LeanInstaller } from '../utils/leanInstaller'
import { willUseLakeServer } from '../utils/projectInfo'
import { diagnose } from './setupDiagnoser'
import {
PreconditionCheckResult,
Expand Down Expand Up @@ -235,3 +236,19 @@ export async function checkIsVSCodeUpToDate(): Promise<PreconditionCheckResult>
return 'Fulfilled'
}
}

export async function checkLean4ProjectPreconditions(
channel: OutputChannel,
folderUri: ExtUri,
): Promise<PreconditionCheckResult> {
return await checkAll(
() => checkIsValidProjectFolder(channel, folderUri),
() => checkIsLeanVersionUpToDate(channel, folderUri, { modal: false }),
async () => {
if (!(await willUseLakeServer(folderUri))) {
return 'Fulfilled'
}
return await checkIsLakeInstalledCorrectly(channel, folderUri, {})
},
)
}
7 changes: 6 additions & 1 deletion vscode-lean4/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
checkIsElanUpToDate,
checkIsLean4Installed,
checkIsVSCodeUpToDate,
checkLean4ProjectPreconditions,
} from './diagnostics/setupDiagnostics'
import { PreconditionCheckResult } from './diagnostics/setupNotifs'
import { AlwaysEnabledFeatures, Exports, Lean4EnabledFeatures } from './exports'
Expand Down Expand Up @@ -170,7 +171,11 @@ async function activateLean4Features(
return undefined
}

const clientProvider = new LeanClientProvider(installer, installer.getOutputChannel())
const clientProvider = new LeanClientProvider(
installer,
installer.getOutputChannel(),
checkLean4ProjectPreconditions,
)
context.subscriptions.push(clientProvider)

const watchService = new LeanConfigWatchService()
Expand Down
40 changes: 14 additions & 26 deletions vscode-lean4/src/utils/clientProvider.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
import { LeanFileProgressProcessingInfo, ServerStoppedReason } from '@leanprover/infoview-api'
import { Disposable, EventEmitter, OutputChannel, TextDocument, commands, window, workspace } from 'vscode'
import {
checkAll,
checkIsLakeInstalledCorrectly,
checkIsLeanVersionUpToDate,
checkIsValidProjectFolder,
} from '../diagnostics/setupDiagnostics'
import { PreconditionCheckResult } from '../diagnostics/setupNotifs'
import { LeanClient } from '../leanclient'
import { ExtUri, FileUri, UntitledUri, getWorkspaceFolderUri, toExtUri } from './exturi'
import { LeanInstaller } from './leanInstaller'
import { logger } from './logger'
import { displayError } from './notifs'
import { findLeanProjectRoot, willUseLakeServer } from './projectInfo'

async function checkLean4ProjectPreconditions(
channel: OutputChannel,
folderUri: ExtUri,
): Promise<PreconditionCheckResult> {
return await checkAll(
() => checkIsValidProjectFolder(channel, folderUri),
() => checkIsLeanVersionUpToDate(channel, folderUri, { modal: false }),
async () => {
if (!(await willUseLakeServer(folderUri))) {
return 'Fulfilled'
}
return await checkIsLakeInstalledCorrectly(channel, folderUri, {})
},
)
}
import { findLeanProjectRoot } from './projectInfo'

// This class ensures we have one LeanClient per folder.
export class LeanClientProvider implements Disposable {
Expand All @@ -53,7 +31,14 @@ export class LeanClientProvider implements Disposable {
private clientStoppedEmitter = new EventEmitter<[LeanClient, boolean, ServerStoppedReason]>()
clientStopped = this.clientStoppedEmitter.event

constructor(installer: LeanInstaller, outputChannel: OutputChannel) {
constructor(
installer: LeanInstaller,
outputChannel: OutputChannel,
private checkLean4ProjectPreconditions: (
channel: OutputChannel,
folderUri: ExtUri,
) => Promise<PreconditionCheckResult>,
) {
this.outputChannel = outputChannel
this.installer = installer

Expand Down Expand Up @@ -122,7 +107,10 @@ export class LeanClientProvider implements Disposable {
continue
}

const preconditionCheckResult = await checkLean4ProjectPreconditions(this.outputChannel, projectUri)
const preconditionCheckResult = await this.checkLean4ProjectPreconditions(
this.outputChannel,
projectUri,
)
if (preconditionCheckResult !== 'Fatal') {
logger.log('[ClientProvider] got lean version 4')
const [cached, client] = await this.ensureClient(uri)
Expand Down Expand Up @@ -234,7 +222,7 @@ export class LeanClientProvider implements Disposable {
}
this.pending.set(key, true)

const preconditionCheckResult = await checkLean4ProjectPreconditions(this.outputChannel, folderUri)
const preconditionCheckResult = await this.checkLean4ProjectPreconditions(this.outputChannel, folderUri)
if (preconditionCheckResult === 'Fatal') {
this.pending.delete(key)
return [false, undefined]
Expand Down
Loading