aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/installation
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/installation')
-rw-r--r--editors/code/src/installation/download_file.ts8
-rw-r--r--editors/code/src/installation/language_server.ts27
2 files changed, 19 insertions, 16 deletions
diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts
index ec16dcd66..53bf46d78 100644
--- a/editors/code/src/installation/download_file.ts
+++ b/editors/code/src/installation/download_file.ts
@@ -1,20 +1,18 @@
1import fetch from "node-fetch"; 1import fetch from "node-fetch";
2import { throttle } from "throttle-debounce";
3import * as fs from "fs"; 2import * as fs from "fs";
4import { strict as assert } from "assert"; 3import { strict as assert } from "assert";
5 4
6/** 5/**
7 * Downloads file from `url` and stores it at `destFilePath`. 6 * Downloads file from `url` and stores it at `destFilePath`.
8 * `onProgress` callback is periodically called to track the progress of downloading, 7 * `onProgress` callback is called on recieveing each chunk of bytes
9 * it gets the already read and total amount of bytes to read as its parameters. 8 * to track the progress of downloading, it gets the already read and total
9 * amount of bytes to read as its parameters.
10 */ 10 */
11export async function downloadFile( 11export async function downloadFile(
12 url: string, 12 url: string,
13 destFilePath: fs.PathLike, 13 destFilePath: fs.PathLike,
14 onProgress: (readBytes: number, totalBytes: number) => void 14 onProgress: (readBytes: number, totalBytes: number) => void
15): Promise<void> { 15): Promise<void> {
16 onProgress = throttle(200, /* noTrailing: */ true, onProgress);
17
18 const response = await fetch(url); 16 const response = await fetch(url);
19 17
20 const totalBytes = Number(response.headers.get('content-length')); 18 const totalBytes = Number(response.headers.get('content-length'));
diff --git a/editors/code/src/installation/language_server.ts b/editors/code/src/installation/language_server.ts
index a169eae47..c1f37f978 100644
--- a/editors/code/src/installation/language_server.ts
+++ b/editors/code/src/installation/language_server.ts
@@ -1,8 +1,9 @@
1import { spawnSync } from "child_process";
2import * as vscode from "vscode"; 1import * as vscode from "vscode";
3import * as path from "path"; 2import * as path from "path";
4import { strict as assert } from "assert"; 3import { strict as assert } from "assert";
5import { promises as fs } from "fs"; 4import { promises as fs } from "fs";
5import { spawnSync } from "child_process";
6import { throttle } from "throttle-debounce";
6 7
7import { BinarySource } from "./interfaces"; 8import { BinarySource } from "./interfaces";
8import { fetchLatestArtifactMetadata } from "./fetch_latest_artifact_metadata"; 9import { fetchLatestArtifactMetadata } from "./fetch_latest_artifact_metadata";
@@ -28,19 +29,23 @@ export async function downloadLatestLanguageServer(
28 { 29 {
29 location: vscode.ProgressLocation.Notification, 30 location: vscode.ProgressLocation.Notification,
30 cancellable: false, // FIXME: add support for canceling download? 31 cancellable: false, // FIXME: add support for canceling download?
31 title: `Downloading language server ${releaseName}` 32 title: `Downloading language server (${releaseName})`
32 }, 33 },
33 async (progress, _cancellationToken) => { 34 async (progress, _cancellationToken) => {
34 let lastPrecentage = 0; 35 let lastPrecentage = 0;
35 await downloadFile(downloadUrl, installationPath, (readBytes, totalBytes) => { 36 await downloadFile(downloadUrl, installationPath, throttle(
36 const newPercentage = (readBytes / totalBytes) * 100; 37 200,
37 progress.report({ 38 /* noTrailing: */ true,
38 message: newPercentage.toFixed(0) + "%", 39 (readBytes, totalBytes) => {
39 increment: newPercentage - lastPrecentage 40 const newPercentage = (readBytes / totalBytes) * 100;
40 }); 41 progress.report({
41 42 message: newPercentage.toFixed(0) + "%",
42 lastPrecentage = newPercentage; 43 increment: newPercentage - lastPrecentage
43 }); 44 });
45
46 lastPrecentage = newPercentage;
47 })
48 );
44 } 49 }
45 ); 50 );
46 51