Skip to content

Commit

Permalink
Adapt to changes on the ark side
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Nov 14, 2024
1 parent 02fbe13 commit f986a4d
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions extensions/positron-r/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { getPandocPath } from './pandoc';
interface RPackageInstallation {
packageName: string;
packageVersion: string;
checkAgainst: string;
checkResult: boolean;
minimumVersion: string;
compatible: boolean;
}

interface EnvVar {
Expand Down Expand Up @@ -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<RPackageInstallation | null> {
async packageVersion(pkgName: string,
minimumVersion: string | null = null,
refresh: boolean = false): Promise<RPackageInstallation | null> {
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);
}
Expand All @@ -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;
Expand All @@ -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<boolean> {
async checkInstalled(pkgName: string, minimumVersion: string | null = null): Promise<boolean> {
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,
Expand Down

0 comments on commit f986a4d

Please sign in to comment.