diff options
-rw-r--r-- | editors/code/.eslintrc.js | 7 | ||||
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/config.ts | 5 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 3 | ||||
-rw-r--r-- | editors/code/src/installation/download_artifact.ts | 2 | ||||
-rw-r--r-- | editors/code/src/installation/download_file.ts | 7 | ||||
-rw-r--r-- | editors/code/src/installation/fetch_artifact_release_info.ts | 3 | ||||
-rw-r--r-- | editors/code/src/installation/server.ts | 19 | ||||
-rw-r--r-- | editors/code/src/main.ts | 3 | ||||
-rw-r--r-- | editors/code/src/util.ts | 18 |
10 files changed, 51 insertions, 21 deletions
diff --git a/editors/code/.eslintrc.js b/editors/code/.eslintrc.js index d494ebce8..16f18ab2c 100644 --- a/editors/code/.eslintrc.js +++ b/editors/code/.eslintrc.js | |||
@@ -12,8 +12,10 @@ module.exports = { | |||
12 | "@typescript-eslint" | 12 | "@typescript-eslint" |
13 | ], | 13 | ], |
14 | "rules": { | 14 | "rules": { |
15 | "eqeqeq": ["error", "always", { "null": "ignore" }], | ||
16 | "camelcase": ["error"], | 15 | "camelcase": ["error"], |
16 | "eqeqeq": ["error", "always", { "null": "ignore" }], | ||
17 | "no-console": ["error"], | ||
18 | "prefer-const": "error", | ||
17 | "@typescript-eslint/member-delimiter-style": [ | 19 | "@typescript-eslint/member-delimiter-style": [ |
18 | "error", | 20 | "error", |
19 | { | 21 | { |
@@ -30,7 +32,6 @@ module.exports = { | |||
30 | "@typescript-eslint/semi": [ | 32 | "@typescript-eslint/semi": [ |
31 | "error", | 33 | "error", |
32 | "always" | 34 | "always" |
33 | ], | 35 | ] |
34 | "prefer-const": "error" | ||
35 | } | 36 | } |
36 | }; | 37 | }; |
diff --git a/editors/code/package.json b/editors/code/package.json index 72befe2b6..9ef6c6983 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -252,6 +252,11 @@ | |||
252 | "default": "off", | 252 | "default": "off", |
253 | "description": "Trace requests to the rust-analyzer" | 253 | "description": "Trace requests to the rust-analyzer" |
254 | }, | 254 | }, |
255 | "rust-analyzer.trace.extension": { | ||
256 | "description": "Enable logging of VS Code extensions itself", | ||
257 | "type": "boolean", | ||
258 | "default": false | ||
259 | }, | ||
255 | "rust-analyzer.lruCapacity": { | 260 | "rust-analyzer.lruCapacity": { |
256 | "type": [ | 261 | "type": [ |
257 | "null", | 262 | "null", |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 347c989c4..47e8cd45d 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import * as os from "os"; | 1 | import * as os from "os"; |
2 | import * as vscode from 'vscode'; | 2 | import * as vscode from 'vscode'; |
3 | import { BinarySource } from "./installation/interfaces"; | 3 | import { BinarySource } from "./installation/interfaces"; |
4 | import { log } from "./util"; | ||
4 | 5 | ||
5 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; | 6 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; |
6 | 7 | ||
@@ -46,7 +47,9 @@ export class Config { | |||
46 | 47 | ||
47 | private refreshConfig() { | 48 | private refreshConfig() { |
48 | this.cfg = vscode.workspace.getConfiguration(Config.rootSection); | 49 | this.cfg = vscode.workspace.getConfiguration(Config.rootSection); |
49 | console.log("Using configuration:", this.cfg); | 50 | const enableLogging = this.cfg.get("trace.extension") as boolean; |
51 | log.setEnabled(enableLogging); | ||
52 | log.debug("Using configuration:", this.cfg); | ||
50 | } | 53 | } |
51 | 54 | ||
52 | private async onConfigChange(event: vscode.ConfigurationChangeEvent) { | 55 | private async onConfigChange(event: vscode.ConfigurationChangeEvent) { |
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 641ec15c6..7e6c310a9 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts | |||
@@ -2,6 +2,7 @@ import * as vscode from 'vscode'; | |||
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | 3 | ||
4 | import { Ctx, sendRequestWithRetry } from './ctx'; | 4 | import { Ctx, sendRequestWithRetry } from './ctx'; |
5 | import { log } from './util'; | ||
5 | 6 | ||
6 | export function activateInlayHints(ctx: Ctx) { | 7 | export function activateInlayHints(ctx: Ctx) { |
7 | const hintsUpdater = new HintsUpdater(ctx); | 8 | const hintsUpdater = new HintsUpdater(ctx); |
@@ -71,7 +72,7 @@ class HintsUpdater { | |||
71 | } | 72 | } |
72 | 73 | ||
73 | async setEnabled(enabled: boolean): Promise<void> { | 74 | async setEnabled(enabled: boolean): Promise<void> { |
74 | console.log({ enabled, prev: this.enabled }); | 75 | log.debug({ enabled, prev: this.enabled }); |
75 | 76 | ||
76 | if (this.enabled === enabled) return; | 77 | if (this.enabled === enabled) return; |
77 | this.enabled = enabled; | 78 | this.enabled = enabled; |
diff --git a/editors/code/src/installation/download_artifact.ts b/editors/code/src/installation/download_artifact.ts index 9996c556f..356723aba 100644 --- a/editors/code/src/installation/download_artifact.ts +++ b/editors/code/src/installation/download_artifact.ts | |||
@@ -29,7 +29,6 @@ export async function downloadArtifact( | |||
29 | 29 | ||
30 | const installationPath = path.join(installationDir, artifactFileName); | 30 | const installationPath = path.join(installationDir, artifactFileName); |
31 | 31 | ||
32 | console.time(`Downloading ${artifactFileName}`); | ||
33 | await vscode.window.withProgress( | 32 | await vscode.window.withProgress( |
34 | { | 33 | { |
35 | location: vscode.ProgressLocation.Notification, | 34 | location: vscode.ProgressLocation.Notification, |
@@ -54,5 +53,4 @@ export async function downloadArtifact( | |||
54 | ); | 53 | ); |
55 | } | 54 | } |
56 | ); | 55 | ); |
57 | console.timeEnd(`Downloading ${artifactFileName}`); | ||
58 | } | 56 | } |
diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts index d154f4816..319cb995c 100644 --- a/editors/code/src/installation/download_file.ts +++ b/editors/code/src/installation/download_file.ts | |||
@@ -3,6 +3,7 @@ import * as fs from "fs"; | |||
3 | import * as stream from "stream"; | 3 | import * as stream from "stream"; |
4 | import * as util from "util"; | 4 | import * as util from "util"; |
5 | import { strict as assert } from "assert"; | 5 | import { strict as assert } from "assert"; |
6 | import { log } from "../util"; | ||
6 | 7 | ||
7 | const pipeline = util.promisify(stream.pipeline); | 8 | const pipeline = util.promisify(stream.pipeline); |
8 | 9 | ||
@@ -21,8 +22,8 @@ export async function downloadFile( | |||
21 | const res = await fetch(url); | 22 | const res = await fetch(url); |
22 | 23 | ||
23 | if (!res.ok) { | 24 | if (!res.ok) { |
24 | console.log("Error", res.status, "while downloading file from", url); | 25 | log.error("Error", res.status, "while downloading file from", url); |
25 | console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); | 26 | log.error({ body: await res.text(), headers: res.headers }); |
26 | 27 | ||
27 | throw new Error(`Got response ${res.status} when trying to download a file.`); | 28 | throw new Error(`Got response ${res.status} when trying to download a file.`); |
28 | } | 29 | } |
@@ -30,7 +31,7 @@ export async function downloadFile( | |||
30 | const totalBytes = Number(res.headers.get('content-length')); | 31 | const totalBytes = Number(res.headers.get('content-length')); |
31 | assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); | 32 | assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); |
32 | 33 | ||
33 | console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); | 34 | log.debug("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); |
34 | 35 | ||
35 | let readBytes = 0; | 36 | let readBytes = 0; |
36 | res.body.on("data", (chunk: Buffer) => { | 37 | res.body.on("data", (chunk: Buffer) => { |
diff --git a/editors/code/src/installation/fetch_artifact_release_info.ts b/editors/code/src/installation/fetch_artifact_release_info.ts index 1e764718c..1b6fc8d48 100644 --- a/editors/code/src/installation/fetch_artifact_release_info.ts +++ b/editors/code/src/installation/fetch_artifact_release_info.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import fetch from "node-fetch"; | 1 | import fetch from "node-fetch"; |
2 | import { GithubRepo, ArtifactReleaseInfo } from "./interfaces"; | 2 | import { GithubRepo, ArtifactReleaseInfo } from "./interfaces"; |
3 | import { log } from "../util"; | ||
3 | 4 | ||
4 | const GITHUB_API_ENDPOINT_URL = "https://api.github.com"; | 5 | const GITHUB_API_ENDPOINT_URL = "https://api.github.com"; |
5 | 6 | ||
@@ -24,7 +25,7 @@ export async function fetchArtifactReleaseInfo( | |||
24 | 25 | ||
25 | // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`) | 26 | // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`) |
26 | 27 | ||
27 | console.log("Issuing request for released artifacts metadata to", requestUrl); | 28 | log.debug("Issuing request for released artifacts metadata to", requestUrl); |
28 | 29 | ||
29 | // FIXME: handle non-ok response | 30 | // FIXME: handle non-ok response |
30 | const response: GithubRelease = await fetch(requestUrl, { | 31 | const response: GithubRelease = await fetch(requestUrl, { |
diff --git a/editors/code/src/installation/server.ts b/editors/code/src/installation/server.ts index 750852921..685abfdc6 100644 --- a/editors/code/src/installation/server.ts +++ b/editors/code/src/installation/server.ts | |||
@@ -7,6 +7,7 @@ import { spawnSync } from "child_process"; | |||
7 | import { BinarySource } from "./interfaces"; | 7 | import { BinarySource } from "./interfaces"; |
8 | import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info"; | 8 | import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info"; |
9 | import { downloadArtifact } from "./download_artifact"; | 9 | import { downloadArtifact } from "./download_artifact"; |
10 | import { log } from "../util"; | ||
10 | 11 | ||
11 | export async function ensureServerBinary(source: null | BinarySource): Promise<null | string> { | 12 | export async function ensureServerBinary(source: null | BinarySource): Promise<null | string> { |
12 | if (!source) { | 13 | if (!source) { |
@@ -40,7 +41,7 @@ export async function ensureServerBinary(source: null | BinarySource): Promise<n | |||
40 | const installedVersion: null | string = getServerVersion(source.storage); | 41 | const installedVersion: null | string = getServerVersion(source.storage); |
41 | const requiredVersion: string = source.version; | 42 | const requiredVersion: string = source.version; |
42 | 43 | ||
43 | console.log("Installed version:", installedVersion, "required:", requiredVersion); | 44 | log.debug("Installed version:", installedVersion, "required:", requiredVersion); |
44 | 45 | ||
45 | if (isBinaryAvailable(prebuiltBinaryPath) && installedVersion === requiredVersion) { | 46 | if (isBinaryAvailable(prebuiltBinaryPath) && installedVersion === requiredVersion) { |
46 | return prebuiltBinaryPath; | 47 | return prebuiltBinaryPath; |
@@ -72,16 +73,16 @@ async function downloadServer(source: BinarySource.GithubRelease): Promise<boole | |||
72 | `GitHub repository: ${err.message}` | 73 | `GitHub repository: ${err.message}` |
73 | ); | 74 | ); |
74 | 75 | ||
75 | console.error(err); | 76 | log.error(err); |
76 | 77 | ||
77 | dns.resolve('example.com').then( | 78 | dns.resolve('example.com').then( |
78 | addrs => console.log("DNS resolution for example.com was successful", addrs), | 79 | addrs => log.debug("DNS resolution for example.com was successful", addrs), |
79 | err => { | 80 | err => { |
80 | console.error( | 81 | log.error( |
81 | "DNS resolution for example.com failed, " + | 82 | "DNS resolution for example.com failed, " + |
82 | "there might be an issue with Internet availability" | 83 | "there might be an issue with Internet availability" |
83 | ); | 84 | ); |
84 | console.error(err); | 85 | log.error(err); |
85 | } | 86 | } |
86 | ); | 87 | ); |
87 | return false; | 88 | return false; |
@@ -105,19 +106,19 @@ function isBinaryAvailable(binaryPath: string): boolean { | |||
105 | // ACHTUNG! `res` type declaration is inherently wrong, see | 106 | // ACHTUNG! `res` type declaration is inherently wrong, see |
106 | // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42221 | 107 | // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42221 |
107 | 108 | ||
108 | console.log("Checked binary availablity via --version", res); | 109 | log.debug("Checked binary availablity via --version", res); |
109 | console.log(binaryPath, "--version output:", res.output?.map(String)); | 110 | log.debug(binaryPath, "--version output:", res.output?.map(String)); |
110 | 111 | ||
111 | return res.status === 0; | 112 | return res.status === 0; |
112 | } | 113 | } |
113 | 114 | ||
114 | function getServerVersion(storage: vscode.Memento): null | string { | 115 | function getServerVersion(storage: vscode.Memento): null | string { |
115 | const version = storage.get<null | string>("server-version", null); | 116 | const version = storage.get<null | string>("server-version", null); |
116 | console.log("Get server-version:", version); | 117 | log.debug("Get server-version:", version); |
117 | return version; | 118 | return version; |
118 | } | 119 | } |
119 | 120 | ||
120 | async function setServerVersion(storage: vscode.Memento, version: string): Promise<void> { | 121 | async function setServerVersion(storage: vscode.Memento, version: string): Promise<void> { |
121 | console.log("Set server-version:", version); | 122 | log.debug("Set server-version:", version); |
122 | await storage.update("server-version", version.toString()); | 123 | await storage.update("server-version", version.toString()); |
123 | } | 124 | } |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index de19a44e5..7b3bb6302 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -7,6 +7,7 @@ import { Ctx } from './ctx'; | |||
7 | import { activateHighlighting } from './highlighting'; | 7 | import { activateHighlighting } from './highlighting'; |
8 | import { ensureServerBinary } from './installation/server'; | 8 | import { ensureServerBinary } from './installation/server'; |
9 | import { Config } from './config'; | 9 | import { Config } from './config'; |
10 | import { log } from './util'; | ||
10 | 11 | ||
11 | let ctx: Ctx | undefined; | 12 | let ctx: Ctx | undefined; |
12 | 13 | ||
@@ -38,7 +39,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
38 | try { | 39 | try { |
39 | sub.dispose(); | 40 | sub.dispose(); |
40 | } catch (e) { | 41 | } catch (e) { |
41 | console.error(e); | 42 | log.error(e); |
42 | } | 43 | } |
43 | } | 44 | } |
44 | await activate(context); | 45 | await activate(context); |
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts new file mode 100644 index 000000000..7a6657753 --- /dev/null +++ b/editors/code/src/util.ts | |||
@@ -0,0 +1,18 @@ | |||
1 | let enabled: boolean = false; | ||
2 | |||
3 | export const log = { | ||
4 | debug(message?: any, ...optionalParams: any[]): void { | ||
5 | if (!enabled) return; | ||
6 | // eslint-disable-next-line no-console | ||
7 | console.log(message, ...optionalParams); | ||
8 | }, | ||
9 | error(message?: any, ...optionalParams: any[]): void { | ||
10 | if (!enabled) return; | ||
11 | debugger; | ||
12 | // eslint-disable-next-line no-console | ||
13 | console.error(message, ...optionalParams); | ||
14 | }, | ||
15 | setEnabled(yes: boolean): void { | ||
16 | enabled = yes; | ||
17 | } | ||
18 | }; | ||