diff options
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r-- | editors/code/src/main.ts | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index fb9d38a14..f58d26215 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -1,7 +1,5 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as path from "path"; | ||
3 | import * as os from "os"; | 2 | import * as os from "os"; |
4 | import { promises as fs, PathLike } from "fs"; | ||
5 | 3 | ||
6 | import * as commands from './commands'; | 4 | import * as commands from './commands'; |
7 | import { activateInlayHints } from './inlay_hints'; | 5 | import { activateInlayHints } from './inlay_hints'; |
@@ -222,7 +220,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi | |||
222 | const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === "rust-analyzer.vsix"); | 220 | const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === "rust-analyzer.vsix"); |
223 | assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`); | 221 | assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`); |
224 | 222 | ||
225 | const dest = path.join(config.globalStorageUri.path, "rust-analyzer.vsix"); | 223 | const dest = vscode.Uri.joinPath(config.globalStorageUri, "rust-analyzer.vsix"); |
226 | 224 | ||
227 | await downloadWithRetryDialog(state, async () => { | 225 | await downloadWithRetryDialog(state, async () => { |
228 | await download({ | 226 | await download({ |
@@ -233,8 +231,8 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi | |||
233 | }); | 231 | }); |
234 | }); | 232 | }); |
235 | 233 | ||
236 | await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest)); | 234 | await vscode.commands.executeCommand("workbench.extensions.installExtension", dest); |
237 | await fs.unlink(dest); | 235 | await vscode.workspace.fs.delete(dest); |
238 | 236 | ||
239 | await state.updateNightlyReleaseId(latestNightlyRelease.id); | 237 | await state.updateNightlyReleaseId(latestNightlyRelease.id); |
240 | await state.updateLastCheck(now); | 238 | await state.updateLastCheck(now); |
@@ -259,7 +257,7 @@ async function bootstrapServer(config: Config, state: PersistentState): Promise< | |||
259 | return path; | 257 | return path; |
260 | } | 258 | } |
261 | 259 | ||
262 | async function patchelf(dest: PathLike): Promise<void> { | 260 | async function patchelf(dest: vscode.Uri): Promise<void> { |
263 | await vscode.window.withProgress( | 261 | await vscode.window.withProgress( |
264 | { | 262 | { |
265 | location: vscode.ProgressLocation.Notification, | 263 | location: vscode.ProgressLocation.Notification, |
@@ -279,11 +277,11 @@ async function patchelf(dest: PathLike): Promise<void> { | |||
279 | ''; | 277 | ''; |
280 | } | 278 | } |
281 | `; | 279 | `; |
282 | const origFile = dest + "-orig"; | 280 | const origFile = vscode.Uri.file(dest.path + "-orig"); |
283 | await fs.rename(dest, origFile); | 281 | await vscode.workspace.fs.rename(dest, origFile); |
284 | progress.report({ message: "Patching executable", increment: 20 }); | 282 | progress.report({ message: "Patching executable", increment: 20 }); |
285 | await new Promise((resolve, reject) => { | 283 | await new Promise((resolve, reject) => { |
286 | const handle = exec(`nix-build -E - --argstr srcStr '${origFile}' -o '${dest}'`, | 284 | const handle = exec(`nix-build -E - --argstr srcStr '${origFile.path}' -o '${dest.path}'`, |
287 | (err, stdout, stderr) => { | 285 | (err, stdout, stderr) => { |
288 | if (err != null) { | 286 | if (err != null) { |
289 | reject(Error(stderr)); | 287 | reject(Error(stderr)); |
@@ -294,7 +292,7 @@ async function patchelf(dest: PathLike): Promise<void> { | |||
294 | handle.stdin?.write(expression); | 292 | handle.stdin?.write(expression); |
295 | handle.stdin?.end(); | 293 | handle.stdin?.end(); |
296 | }); | 294 | }); |
297 | await fs.unlink(origFile); | 295 | await vscode.workspace.fs.delete(origFile); |
298 | } | 296 | } |
299 | ); | 297 | ); |
300 | } | 298 | } |
@@ -334,20 +332,20 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
334 | platform = "x86_64-unknown-linux-musl"; | 332 | platform = "x86_64-unknown-linux-musl"; |
335 | } | 333 | } |
336 | const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : ""; | 334 | const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : ""; |
337 | const dest = path.join(config.globalStorageUri.path, `rust-analyzer-${platform}${ext}`); | 335 | const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer-${platform}${ext}`); |
338 | const exists = await fs.stat(dest).then(() => true, () => false); | 336 | const exists = await vscode.workspace.fs.stat(dest).then(() => true, () => false); |
339 | if (!exists) { | 337 | if (!exists) { |
340 | await state.updateServerVersion(undefined); | 338 | await state.updateServerVersion(undefined); |
341 | } | 339 | } |
342 | 340 | ||
343 | if (state.serverVersion === config.package.version) return dest; | 341 | if (state.serverVersion === config.package.version) return dest.path; |
344 | 342 | ||
345 | if (config.askBeforeDownload) { | 343 | if (config.askBeforeDownload) { |
346 | const userResponse = await vscode.window.showInformationMessage( | 344 | const userResponse = await vscode.window.showInformationMessage( |
347 | `Language server version ${config.package.version} for rust-analyzer is not installed.`, | 345 | `Language server version ${config.package.version} for rust-analyzer is not installed.`, |
348 | "Download now" | 346 | "Download now" |
349 | ); | 347 | ); |
350 | if (userResponse !== "Download now") return dest; | 348 | if (userResponse !== "Download now") return dest.path; |
351 | } | 349 | } |
352 | 350 | ||
353 | const releaseTag = config.package.releaseTag; | 351 | const releaseTag = config.package.releaseTag; |
@@ -374,7 +372,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
374 | } | 372 | } |
375 | 373 | ||
376 | await state.updateServerVersion(config.package.version); | 374 | await state.updateServerVersion(config.package.version); |
377 | return dest; | 375 | return dest.path; |
378 | } | 376 | } |
379 | 377 | ||
380 | function serverPath(config: Config): string | null { | 378 | function serverPath(config: Config): string | null { |
@@ -383,7 +381,7 @@ function serverPath(config: Config): string | null { | |||
383 | 381 | ||
384 | async function isNixOs(): Promise<boolean> { | 382 | async function isNixOs(): Promise<boolean> { |
385 | try { | 383 | try { |
386 | const contents = await fs.readFile("/etc/os-release"); | 384 | const contents = (await vscode.workspace.fs.readFile(vscode.Uri.file("/etc/os-release"))).toString(); |
387 | return contents.indexOf("ID=nixos") !== -1; | 385 | return contents.indexOf("ID=nixos") !== -1; |
388 | } catch (e) { | 386 | } catch (e) { |
389 | return false; | 387 | return false; |