diff options
Diffstat (limited to 'editors/code/src/installation/language_server.ts')
-rw-r--r-- | editors/code/src/installation/language_server.ts | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/editors/code/src/installation/language_server.ts b/editors/code/src/installation/language_server.ts index c1f37f978..1ce67b8b2 100644 --- a/editors/code/src/installation/language_server.ts +++ b/editors/code/src/installation/language_server.ts | |||
@@ -2,6 +2,7 @@ import * as vscode from "vscode"; | |||
2 | import * as path from "path"; | 2 | import * as path from "path"; |
3 | import { strict as assert } from "assert"; | 3 | import { strict as assert } from "assert"; |
4 | import { promises as fs } from "fs"; | 4 | import { promises as fs } from "fs"; |
5 | import { promises as dns } from "dns"; | ||
5 | import { spawnSync } from "child_process"; | 6 | import { spawnSync } from "child_process"; |
6 | import { throttle } from "throttle-debounce"; | 7 | import { throttle } from "throttle-debounce"; |
7 | 8 | ||
@@ -25,6 +26,7 @@ export async function downloadLatestLanguageServer( | |||
25 | 26 | ||
26 | const installationPath = path.join(installationDir, artifactFileName); | 27 | const installationPath = path.join(installationDir, artifactFileName); |
27 | 28 | ||
29 | console.time("Downloading ra_lsp_server"); | ||
28 | await vscode.window.withProgress( | 30 | await vscode.window.withProgress( |
29 | { | 31 | { |
30 | location: vscode.ProgressLocation.Notification, | 32 | location: vscode.ProgressLocation.Notification, |
@@ -48,6 +50,7 @@ export async function downloadLatestLanguageServer( | |||
48 | ); | 50 | ); |
49 | } | 51 | } |
50 | ); | 52 | ); |
53 | console.timeEnd("Downloading ra_lsp_server"); | ||
51 | 54 | ||
52 | await fs.chmod(installationPath, 0o755); // Set (rwx, r_x, r_x) permissions | 55 | await fs.chmod(installationPath, 0o755); // Set (rwx, r_x, r_x) permissions |
53 | } | 56 | } |
@@ -101,15 +104,21 @@ export async function ensureLanguageServerBinary( | |||
101 | `Failed to download language server from ${langServerSource.repo.name} ` + | 104 | `Failed to download language server from ${langServerSource.repo.name} ` + |
102 | `GitHub repository: ${err.message}` | 105 | `GitHub repository: ${err.message}` |
103 | ); | 106 | ); |
107 | |||
108 | await dns.resolve('www.google.com').catch(err => { | ||
109 | console.error("DNS resolution failed, there might be an issue with Internet availability"); | ||
110 | console.error(err); | ||
111 | }); | ||
112 | |||
104 | return null; | 113 | return null; |
105 | } | 114 | } |
106 | 115 | ||
107 | 116 | if (!isBinaryAvailable(prebuiltBinaryPath)) assert(false, | |
108 | assert( | 117 | `Downloaded language server binary is not functional.` + |
109 | isBinaryAvailable(prebuiltBinaryPath), | 118 | `Downloaded from: ${JSON.stringify(langServerSource)}` |
110 | "Downloaded language server binary is not functional" | ||
111 | ); | 119 | ); |
112 | 120 | ||
121 | |||
113 | vscode.window.showInformationMessage( | 122 | vscode.window.showInformationMessage( |
114 | "Rust analyzer language server was successfully installed 🦀" | 123 | "Rust analyzer language server was successfully installed 🦀" |
115 | ); | 124 | ); |
@@ -119,6 +128,14 @@ export async function ensureLanguageServerBinary( | |||
119 | } | 128 | } |
120 | 129 | ||
121 | function isBinaryAvailable(binaryPath: string) { | 130 | function isBinaryAvailable(binaryPath: string) { |
122 | return spawnSync(binaryPath, ["--version"]).status === 0; | 131 | const res = spawnSync(binaryPath, ["--version"]); |
132 | |||
133 | // ACHTUNG! `res` type declaration is inherently wrong, see | ||
134 | // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42221 | ||
135 | |||
136 | console.log("Checked binary availablity via --version", res); | ||
137 | console.log(binaryPath, "--version output:", res.output?.map(String)); | ||
138 | |||
139 | return res.status === 0; | ||
123 | } | 140 | } |
124 | } | 141 | } |