Skip to content

Commit 1b9ab04

Browse files
author
Veetaha
committed
vscode: migrate to more type-safe assert impl
1 parent d2bf2ad commit 1b9ab04

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

editors/code/src/installation/download_file.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import fetch from "node-fetch";
22
import * as fs from "fs";
33
import * as stream from "stream";
44
import * as util from "util";
5-
import { strict as assert } from "assert";
6-
import { log } from "../util";
5+
import { log, assert } from "../util";
76

87
const pipeline = util.promisify(stream.pipeline);
98

editors/code/src/installation/server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import * as vscode from "vscode";
22
import * as path from "path";
3-
import { strict as assert } from "assert";
43
import { promises as dns } from "dns";
54
import { spawnSync } from "child_process";
65

76
import { BinarySource } from "./interfaces";
87
import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info";
98
import { downloadArtifact } from "./download_artifact";
10-
import { log } from "../util";
9+
import { log, assert } from "../util";
1110

1211
export async function ensureServerBinary(source: null | BinarySource): Promise<null | string> {
1312
if (!source) {

editors/code/src/util.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import * as lc from "vscode-languageclient";
22
import * as vscode from "vscode";
3+
import { strict as nodeAssert } from "assert";
34

4-
let enabled: boolean = false;
5+
export function assert(condition: unknown, explanation: string): asserts condition {
6+
nodeAssert(condition, explanation);
7+
}
58

69
export const log = {
10+
enabled: true,
711
debug(message?: any, ...optionalParams: any[]): void {
8-
if (!enabled) return;
12+
if (!log.enabled) return;
913
// eslint-disable-next-line no-console
1014
console.log(message, ...optionalParams);
1115
},
1216
error(message?: any, ...optionalParams: any[]): void {
13-
if (!enabled) return;
17+
if (!log.enabled) return;
1418
debugger;
1519
// eslint-disable-next-line no-console
1620
console.error(message, ...optionalParams);
1721
},
1822
setEnabled(yes: boolean): void {
19-
enabled = yes;
23+
log.enabled = yes;
2024
}
2125
};
2226

0 commit comments

Comments
 (0)