vscode: added logging when donloading binaries

This commit is contained in:
Veetaha 2020-02-09 15:01:00 +02:00
parent f3240e22c6
commit 7cba77ed4e
3 changed files with 26 additions and 5 deletions

View file

@ -20,6 +20,8 @@ export async function downloadFile(
let readBytes = 0;
console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath);
return new Promise<void>((resolve, reject) => response.body
.on("data", (chunk: Buffer) => {
readBytes += chunk.length;

View file

@ -19,6 +19,8 @@ export async function fetchLatestArtifactMetadata(
// We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`)
console.log("Issuing request for released artifacts metadata to", requestUrl);
const response: GithubRelease = await fetch(requestUrl, {
headers: { Accept: "application/vnd.github.v3+json" }
})

View file

@ -2,6 +2,7 @@ import * as vscode from "vscode";
import * as path from "path";
import { strict as assert } from "assert";
import { promises as fs } from "fs";
import { promises as dns } from "dns";
import { spawnSync } from "child_process";
import { throttle } from "throttle-debounce";
@ -25,6 +26,7 @@ export async function downloadLatestLanguageServer(
const installationPath = path.join(installationDir, artifactFileName);
console.time("Downloading ra_lsp_server");
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
@ -48,6 +50,7 @@ export async function downloadLatestLanguageServer(
);
}
);
console.timeEnd("Downloading ra_lsp_server");
await fs.chmod(installationPath, 0o755); // Set (rwx, r_x, r_x) permissions
}
@ -101,15 +104,21 @@ export async function ensureLanguageServerBinary(
`Failed to download language server from ${langServerSource.repo.name} ` +
`GitHub repository: ${err.message}`
);
await dns.resolve('www.google.com').catch(err => {
console.error("DNS resolution failed, there might be an issue with Internet availability");
console.error(err);
});
return null;
}
assert(
isBinaryAvailable(prebuiltBinaryPath),
"Downloaded language server binary is not functional"
if (!isBinaryAvailable(prebuiltBinaryPath)) assert(false,
`Downloaded language server binary is not functional.` +
`Downloaded from: ${JSON.stringify(langServerSource)}`
);
vscode.window.showInformationMessage(
"Rust analyzer language server was successfully installed 🦀"
);
@ -119,6 +128,14 @@ export async function ensureLanguageServerBinary(
}
function isBinaryAvailable(binaryPath: string) {
return spawnSync(binaryPath, ["--version"]).status === 0;
const res = spawnSync(binaryPath, ["--version"]);
// ACHTUNG! `res` type declaration is inherently wrong, see
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42221
console.log("Checked binary availablity via --version", res);
console.log(binaryPath, "--version output:", res.output?.map(String));
return res.status === 0;
}
}