diff --git a/extensions/positron-r/src/session.ts b/extensions/positron-r/src/session.ts index 732a6e9ea086..9e9fe1086bfc 100644 --- a/extensions/positron-r/src/session.ts +++ b/extensions/positron-r/src/session.ts @@ -23,8 +23,8 @@ import { getPandocPath } from './pandoc'; interface RPackageInstallation { packageName: string; packageVersion: string; - checkAgainst: string; - checkResult: boolean; + minimumVersion: string; + compatible: boolean; } interface EnvVar { @@ -388,15 +388,17 @@ export class RSession implements positron.LanguageRuntimeSession, vscode.Disposa * Gets information from the runtime about a specific installed package (or maybe not * installed). * @param pkgName The name of the package to check. - * @param checkAgainst Optionally, a minimum version to check for. This may seem weird, but we + * @param minimumVersion Optionally, a minimum version to check for. This may seem weird, but we * need R to compare versions for us. We can't easily do it over here. * @returns An instance of RPackageInstallation if the package is installed, `null` otherwise. */ - async packageVersion(pkgName: string, checkAgainst?: string): Promise { + async packageVersion(pkgName: string, + minimumVersion: string | null = null, + refresh: boolean = false): Promise { let pkg: any; try { - if (checkAgainst) { - pkg = await this.callMethod('packageVersion', pkgName, checkAgainst); + if (minimumVersion) { + pkg = await this.callMethod('packageVersion', pkgName, minimumVersion); } else { pkg = await this.callMethod('packageVersion', pkgName); } @@ -413,8 +415,8 @@ export class RSession implements positron.LanguageRuntimeSession, vscode.Disposa const pkgInst: RPackageInstallation = { packageName: pkgName, packageVersion: pkg.version, - checkAgainst: pkg.checkAgainst, - checkResult: pkg.checkResult + minimumVersion: minimumVersion ?? '0.0.0', + compatible: pkg.compatible }; return pkgInst; @@ -424,38 +426,38 @@ export class RSession implements positron.LanguageRuntimeSession, vscode.Disposa * Checks whether a package is installed in the runtime, possibly at a minimum version. If not, * prompts the user to install the package. * @param pkgName The name of the package to check. - * @param pkgVersion Optionally, the version of the package needed. + * @param minimumVersion Optionally, the version of the package needed. * @returns true if the package is installed, false otherwise */ - async checkInstalled(pkgName: string, pkgVersion?: string): Promise { + async checkInstalled(pkgName: string, minimumVersion: string | null = null): Promise { let pkgInst: RPackageInstallation | null = null; - if (pkgVersion) { - pkgInst = await this.packageVersion(pkgName, pkgVersion); + if (minimumVersion) { + pkgInst = await this.packageVersion(pkgName, minimumVersion); } else { pkgInst = await this.packageVersion(pkgName); } - const isInstalled = pkgInst !== null; + const installed = pkgInst !== null; - if (isInstalled && pkgVersion === undefined) { + if (installed && minimumVersion === null) { return true; } - const isSufficient = pkgInst?.checkResult ?? false; + const compatible = pkgInst?.compatible ?? false; - if (isSufficient) { + if (compatible) { return true; } // either the package is not installed or its version is insufficient - const title = isInstalled ? vscode.l10n.t('Insufficient package version') : vscode.l10n.t('Missing R package'); - const message = isInstalled ? + const title = installed ? vscode.l10n.t('Insufficient package version') : vscode.l10n.t('Missing R package'); + const message = installed ? vscode.l10n.t( 'The {0} package is installed at version {1}, but version {2} is required.', - pkgName, pkgInst!.packageVersion, pkgVersion as string + pkgName, pkgInst!.packageVersion, minimumVersion as string ) : vscode.l10n.t('The {0} package is required, but not installed.', pkgName); - const okButtonTitle = isInstalled ? vscode.l10n.t('Update now') : vscode.l10n.t('Install now'); + const okButtonTitle = installed ? vscode.l10n.t('Update now') : vscode.l10n.t('Install now'); const install = await positron.window.showSimpleModalDialogPrompt( title,