From 3fd49d8b94c604cf672fe4dae5962b075a486475 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 22 Jun 2020 21:18:36 +0300 Subject: Make bootstrap error message more informative and better-fitting --- editors/code/src/main.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 670f2ebfd..301754733 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -43,12 +43,16 @@ export async function activate(context: vscode.ExtensionContext) { const config = new Config(context); const state = new PersistentState(context.globalState); const serverPath = await bootstrap(config, state).catch(err => { - let message = "Failed to bootstrap rust-analyzer."; + let message = "bootstrap error. "; + if (err.code === "EBUSY" || err.code === "ETXTBSY") { - message += " Other vscode windows might be using rust-analyzer, " + - "you should close them and reload this window to retry."; + message += "Other vscode windows might be using rust-analyzer, "; + message += "you should close them and reload this window to retry. "; } - message += " Open \"Help > Toggle Developer Tools > Console\" to see the logs"; + + message += 'Open "Help > Toggle Developer Tools > Console" to see the logs '; + message += '(enable verbose logs with "rust-analyzer.trace.extension")'; + log.error("Bootstrap error", err); throw new Error(message); }); -- cgit v1.2.3 From c2221ff7e8d60e666474e60bb3258137019952fb Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 22 Jun 2020 20:53:17 +0300 Subject: Never disable error logging on the frontend --- editors/code/src/util.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index fe3fb71cd..fec4c3295 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts @@ -26,7 +26,6 @@ export const log = new class { } error(message?: any, ...optionalParams: any[]): void { - if (!log.enabled) return; debugger; // eslint-disable-next-line no-console console.error(message, ...optionalParams); -- cgit v1.2.3 From 0514d817db84c683aaf250b823edc8b08bfee3da Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 22 Jun 2020 21:36:56 +0300 Subject: Decouple http file stream logic from temp dir logic --- editors/code/src/main.ts | 13 +++++-- editors/code/src/net.ts | 88 +++++++++++++++++++++++++----------------------- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 670f2ebfd..7bae8bb33 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -178,7 +178,11 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix"); - await download(artifact.browser_download_url, dest, "Downloading rust-analyzer extension"); + await download({ + url: artifact.browser_download_url, + dest, + progressTitle: "Downloading rust-analyzer extension", + }); await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest)); await fs.unlink(dest); @@ -299,7 +303,12 @@ async function getServer(config: Config, state: PersistentState): Promise true).catch(_ => false)) { diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index 9debdc57b..e02fd6d4f 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts @@ -60,32 +60,40 @@ export interface GithubRelease { }>; } +interface DownloadOpts { + progressTitle: string; + url: string; + dest: string; + mode?: number; +} -export async function download( - downloadUrl: string, - destinationPath: string, - progressTitle: string, - { mode }: { mode?: number } = {}, -) { - await vscode.window.withProgress( - { - location: vscode.ProgressLocation.Notification, - cancellable: false, - title: progressTitle - }, - async (progress, _cancellationToken) => { - let lastPercentage = 0; - await downloadFile(downloadUrl, destinationPath, mode, (readBytes, totalBytes) => { - const newPercentage = (readBytes / totalBytes) * 100; - progress.report({ - message: newPercentage.toFixed(0) + "%", - increment: newPercentage - lastPercentage +export async function download(opts: DownloadOpts) { + // Put the artifact into a temporary folder to prevent partially downloaded files when user kills vscode + await withTempDir(async tempDir => { + const tempFile = path.join(tempDir, path.basename(opts.dest)); + + await vscode.window.withProgress( + { + location: vscode.ProgressLocation.Notification, + cancellable: false, + title: opts.progressTitle + }, + async (progress, _cancellationToken) => { + let lastPercentage = 0; + await downloadFile(opts.url, tempFile, opts.mode, (readBytes, totalBytes) => { + const newPercentage = (readBytes / totalBytes) * 100; + progress.report({ + message: newPercentage.toFixed(0) + "%", + increment: newPercentage - lastPercentage + }); + + lastPercentage = newPercentage; }); + } + ); - lastPercentage = newPercentage; - }); - } - ); + await moveFile(tempFile, opts.dest); + }); } /** @@ -114,28 +122,23 @@ async function downloadFile( log.debug("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); - // Put the artifact into a temporary folder to prevent partially downloaded files when user kills vscode - await withTempFile(async tempFilePath => { - const destFileStream = fs.createWriteStream(tempFilePath, { mode }); - - let readBytes = 0; - res.body.on("data", (chunk: Buffer) => { - readBytes += chunk.length; - onProgress(readBytes, totalBytes); - }); + let readBytes = 0; + res.body.on("data", (chunk: Buffer) => { + readBytes += chunk.length; + onProgress(readBytes, totalBytes); + }); - await pipeline(res.body, destFileStream); - await new Promise(resolve => { - destFileStream.on("close", resolve); - destFileStream.destroy(); - // This workaround is awaiting to be removed when vscode moves to newer nodejs version: - // https://github.com/rust-analyzer/rust-analyzer/issues/3167 - }); - await moveFile(tempFilePath, destFilePath); + const destFileStream = fs.createWriteStream(destFilePath, { mode }); + await pipeline(res.body, destFileStream); + await new Promise(resolve => { + destFileStream.on("close", resolve); + destFileStream.destroy(); + // This workaround is awaiting to be removed when vscode moves to newer nodejs version: + // https://github.com/rust-analyzer/rust-analyzer/issues/3167 }); } -async function withTempFile(scope: (tempFilePath: string) => Promise) { +async function withTempDir(scope: (tempDirPath: string) => Promise) { // Based on the great article: https://advancedweb.hu/secure-tempfiles-in-nodejs-without-dependencies/ // `.realpath()` should handle the cases where os.tmpdir() contains symlinks @@ -144,7 +147,7 @@ async function withTempFile(scope: (tempFilePath: string) => Promise) { const tempDir = await fs.promises.mkdtemp(path.join(osTempDir, "rust-analyzer")); try { - return await scope(path.join(tempDir, "file")); + return await scope(tempDir); } finally { // We are good citizens :D void fs.promises.rmdir(tempDir, { recursive: true }).catch(log.error); @@ -161,6 +164,7 @@ async function moveFile(src: fs.PathLike, dest: fs.PathLike) { await fs.promises.unlink(src); } else { log.error(`Failed to rename the file ${src} -> ${dest}`, err); + throw err; } } } -- cgit v1.2.3 From 965900c88c1b0c6ff78e02d9fcd8da6b7aaedcc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Wagner?= Date: Mon, 22 Jun 2020 22:38:43 +0200 Subject: Update manual.adoc GNOME Builder (Nightly) supports now rust-analyzer --- docs/user/manual.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index ea714f49a..453b5d0b1 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc @@ -269,6 +269,10 @@ Gnome Builder currently has support for RLS, and there's no way to configure the 1. Rename, symlink or copy the `rust-analyzer` binary to `rls` and place it somewhere Builder can find (in `PATH`, or under `~/.cargo/bin`). 2. Enable the Rust Builder plugin. +==== GNOME Builder (Nightly) + +https://nightly.gnome.org/repo/appstream/org.gnome.Builder.flatpakref[GNOME Builder (Nightly)] has now native support for `rust-analyzer` out of the box. If the `rust-analyzer` binary is not installed GNOME Builder will ask for installing the binary for you when opening up the first time a Rust source file. + == Non-Cargo Based Projects rust-analyzer does not require Cargo. -- cgit v1.2.3 From 426122ffc0e924f64cd35628250dfd307c632bb9 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Mon, 22 Jun 2020 23:57:36 +0300 Subject: Disrecommend trace.server: "verbose" for regular users --- editors/code/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editors/code/package.json b/editors/code/package.json index e6ceb235f..68484a370 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -426,7 +426,7 @@ "Full log" ], "default": "off", - "description": "Trace requests to the rust-analyzer" + "description": "Trace requests to the rust-analyzer (this is usually overly verbose and not recommended for regular users)" }, "rust-analyzer.trace.extension": { "description": "Enable logging of VS Code extensions itself", -- cgit v1.2.3 From 837d6013b50bc8db7234d0a8b155e5710cb0b2b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Wagner?= Date: Tue, 23 Jun 2020 07:18:46 +0200 Subject: Update docs/user/manual.adoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Laurențiu Nicola --- docs/user/manual.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index 453b5d0b1..f1b7ed7fc 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc @@ -271,7 +271,7 @@ Gnome Builder currently has support for RLS, and there's no way to configure the ==== GNOME Builder (Nightly) -https://nightly.gnome.org/repo/appstream/org.gnome.Builder.flatpakref[GNOME Builder (Nightly)] has now native support for `rust-analyzer` out of the box. If the `rust-analyzer` binary is not installed GNOME Builder will ask for installing the binary for you when opening up the first time a Rust source file. +https://nightly.gnome.org/repo/appstream/org.gnome.Builder.flatpakref[GNOME Builder (Nightly)] has now native support for `rust-analyzer` out of the box. If the `rust-analyzer` binary is not available, GNOME Builder can install it when opening a Rust source file. == Non-Cargo Based Projects -- cgit v1.2.3