Add failure loop to installation selection

[?]
Dec 22, 2020, 10:29 PM
TKKT6D4C75R7WSRJY5IWX7OJR5M6B5IWYEN5BKMVFQZTECYGWVJQC

Dependencies

  • [2] WHFIIX4Y Improve documentation and add Pijul installation configuration
  • [3] 3N3RS66T Create pijul output channel and configure activation events
  • [4] NCBEWRYE Initialize Repository
  • [5] WW67NYZV Configure eslint for JS standard formatting

Change contents

  • replacement in src/extension.ts at line 5
    [2.39][2.39:209]()
    async function checkPijulInstallation (config: vscode.WorkspaceConfiguration, outputChannel: vscode.OutputChannel) {
    let path = config.get<string>("installationPath");
    [2.39]
    [2.209]
    export interface IPijul {
    path: string;
    version: string;
    }
  • edit in src/extension.ts at line 10
    [2.210]
    [2.210]
    async function checkPijulInstallation (path: string | undefined, config: vscode.WorkspaceConfiguration, outputChannel: vscode.OutputChannel): Promise<IPijul> {
  • replacement in src/extension.ts at line 46
    [2.1622][2.1622:1640]()
    return;
    [2.1622]
    [2.1640]
    return Promise.reject(new Error("No executable selected in file dialogue"));
  • replacement in src/extension.ts at line 49
    [2.1665][2.1665:1739]()
    config.update("ignoreMissingInstallation", true);
    return;
    [2.1665]
    [2.1739]
    await config.update("ignoreMissingInstallation", true);
    return Promise.reject(new Error("Ignore"));
  • replacement in src/extension.ts at line 54
    [2.1812][2.1812:1826]()
    return;
    [2.1812]
    [2.1826]
    return Promise.reject(new Error("Ignore"));
  • replacement in src/extension.ts at line 58
    [2.1837][2.1837:1962]()
    const child = cp.spawn(path, ["--version"]);
    child.stdout.on("data", (b: Buffer) => outputChannel.append(b.toString()));
    [2.1837]
    [2.1962]
    return new Promise<IPijul>((resolve, reject) => {
    const pathDefined = path || "pijul";
    const child = cp.spawn(pathDefined || "pijul", ["--version"]);
    const buffers: Buffer[] = [];
    child.stdout.on("data", (b: Buffer) => buffers.push(b));
    child.on("error", () => reject(new Error("Error checking version at " + path)));
    child.on("close", code => {
    if (code) {
    reject(new Error("Error checking version at " + path));
    } else {
    resolve({ path: pathDefined, version: Buffer.concat(buffers).toString("utf8").trim().split(" ")[1] });
    }
    });
    });
  • replacement in src/extension.ts at line 89
    [3.107540][2.2287:2342]()
    await checkPijulInstallation(config, outputChannel);
    [3.107540]
    [3.20690]
    const installationPath = config.get<string>("installationPath");
    // Make sure that the Pijul installation is valid
    let identifiedInstallation = false;
    let pijul;
    while (!identifiedInstallation) {
    try {
    pijul = await checkPijulInstallation(installationPath, config, outputChannel);
    outputChannel.appendLine(`Using Pijul ${pijul.version} located at ${pijul.path}`);
    identifiedInstallation = true;
    } catch (err) {
    if (err.message === "Ignore") {
    // Complete activation without finding the installation
    identifiedInstallation = true;
    return;
    } else {
    // Reset the configuration and try again
    vscode.window.showErrorMessage(`Failed to find pijul installation at ${err.message.split(" ").pop()}, resetting...`);
    }
    }
    }