mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
4992: Never disable error logging on the frontend r=matklad a=Veetaha 4993: Make bootstrap error message more informative and better-fitting r=matklad a=Veetaha Now this better fits standard vscode extension activation failure message and suggests enabling verbose logs. ![image](https://user-images.githubusercontent.com/36276403/85321828-ffbb9400-b4cd-11ea-8adf-4032b1f62dfd.png) 4994: Decouple http file stream logic from temp dir logic r=matklad a=Veetaha Followup for #4989 4997: Update manual.adoc r=matklad a=gwutz GNOME Builder (Nightly) supports now rust-analyzer 4998: Disrecommend trace.server: "verbose" for regular users r=matklad a=Veetaha This option has never been useful for me, I wonder if anyone finds regular users can use this for sending logs Co-authored-by: Veetaha <veetaha2@gmail.com> Co-authored-by: Günther Wagner <info@gunibert.de>
This commit is contained in:
commit
45f3a5f9c1
5 changed files with 70 additions and 50 deletions
|
@ -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`).
|
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.
|
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 available, GNOME Builder can install it when opening a Rust source file.
|
||||||
|
|
||||||
== Non-Cargo Based Projects
|
== Non-Cargo Based Projects
|
||||||
|
|
||||||
rust-analyzer does not require Cargo.
|
rust-analyzer does not require Cargo.
|
||||||
|
|
|
@ -426,7 +426,7 @@
|
||||||
"Full log"
|
"Full log"
|
||||||
],
|
],
|
||||||
"default": "off",
|
"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": {
|
"rust-analyzer.trace.extension": {
|
||||||
"description": "Enable logging of VS Code extensions itself",
|
"description": "Enable logging of VS Code extensions itself",
|
||||||
|
|
|
@ -43,12 +43,16 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
const config = new Config(context);
|
const config = new Config(context);
|
||||||
const state = new PersistentState(context.globalState);
|
const state = new PersistentState(context.globalState);
|
||||||
const serverPath = await bootstrap(config, state).catch(err => {
|
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") {
|
if (err.code === "EBUSY" || err.code === "ETXTBSY") {
|
||||||
message += " Other vscode windows might be using rust-analyzer, " +
|
message += "Other vscode windows might be using rust-analyzer, ";
|
||||||
"you should close them and reload this window to retry.";
|
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);
|
log.error("Bootstrap error", err);
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
});
|
});
|
||||||
|
@ -178,7 +182,11 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
|
||||||
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
|
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
|
||||||
|
|
||||||
const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
|
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 vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
|
||||||
await fs.unlink(dest);
|
await fs.unlink(dest);
|
||||||
|
@ -299,7 +307,12 @@ async function getServer(config: Config, state: PersistentState): Promise<string
|
||||||
if (err.code !== "ENOENT") throw err;
|
if (err.code !== "ENOENT") throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
await download(artifact.browser_download_url, dest, "Downloading rust-analyzer server", { mode: 0o755 });
|
await download({
|
||||||
|
url: artifact.browser_download_url,
|
||||||
|
dest,
|
||||||
|
progressTitle: "Downloading rust-analyzer server",
|
||||||
|
mode: 0o755
|
||||||
|
});
|
||||||
|
|
||||||
// Patching executable if that's NixOS.
|
// Patching executable if that's NixOS.
|
||||||
if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
|
if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
|
||||||
|
|
|
@ -60,32 +60,40 @@ export interface GithubRelease {
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DownloadOpts {
|
||||||
|
progressTitle: string;
|
||||||
|
url: string;
|
||||||
|
dest: string;
|
||||||
|
mode?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export async function download(
|
export async function download(opts: DownloadOpts) {
|
||||||
downloadUrl: string,
|
// Put the artifact into a temporary folder to prevent partially downloaded files when user kills vscode
|
||||||
destinationPath: string,
|
await withTempDir(async tempDir => {
|
||||||
progressTitle: string,
|
const tempFile = path.join(tempDir, path.basename(opts.dest));
|
||||||
{ mode }: { mode?: number } = {},
|
|
||||||
) {
|
await vscode.window.withProgress(
|
||||||
await vscode.window.withProgress(
|
{
|
||||||
{
|
location: vscode.ProgressLocation.Notification,
|
||||||
location: vscode.ProgressLocation.Notification,
|
cancellable: false,
|
||||||
cancellable: false,
|
title: opts.progressTitle
|
||||||
title: progressTitle
|
},
|
||||||
},
|
async (progress, _cancellationToken) => {
|
||||||
async (progress, _cancellationToken) => {
|
let lastPercentage = 0;
|
||||||
let lastPercentage = 0;
|
await downloadFile(opts.url, tempFile, opts.mode, (readBytes, totalBytes) => {
|
||||||
await downloadFile(downloadUrl, destinationPath, mode, (readBytes, totalBytes) => {
|
const newPercentage = (readBytes / totalBytes) * 100;
|
||||||
const newPercentage = (readBytes / totalBytes) * 100;
|
progress.report({
|
||||||
progress.report({
|
message: newPercentage.toFixed(0) + "%",
|
||||||
message: newPercentage.toFixed(0) + "%",
|
increment: newPercentage - lastPercentage
|
||||||
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);
|
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
|
let readBytes = 0;
|
||||||
await withTempFile(async tempFilePath => {
|
res.body.on("data", (chunk: Buffer) => {
|
||||||
const destFileStream = fs.createWriteStream(tempFilePath, { mode });
|
readBytes += chunk.length;
|
||||||
|
onProgress(readBytes, totalBytes);
|
||||||
|
});
|
||||||
|
|
||||||
let readBytes = 0;
|
const destFileStream = fs.createWriteStream(destFilePath, { mode });
|
||||||
res.body.on("data", (chunk: Buffer) => {
|
await pipeline(res.body, destFileStream);
|
||||||
readBytes += chunk.length;
|
await new Promise<void>(resolve => {
|
||||||
onProgress(readBytes, totalBytes);
|
destFileStream.on("close", resolve);
|
||||||
});
|
destFileStream.destroy();
|
||||||
|
// This workaround is awaiting to be removed when vscode moves to newer nodejs version:
|
||||||
await pipeline(res.body, destFileStream);
|
// https://github.com/rust-analyzer/rust-analyzer/issues/3167
|
||||||
await new Promise<void>(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);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function withTempFile(scope: (tempFilePath: string) => Promise<void>) {
|
async function withTempDir(scope: (tempDirPath: string) => Promise<void>) {
|
||||||
// Based on the great article: https://advancedweb.hu/secure-tempfiles-in-nodejs-without-dependencies/
|
// Based on the great article: https://advancedweb.hu/secure-tempfiles-in-nodejs-without-dependencies/
|
||||||
|
|
||||||
// `.realpath()` should handle the cases where os.tmpdir() contains symlinks
|
// `.realpath()` should handle the cases where os.tmpdir() contains symlinks
|
||||||
|
@ -144,7 +147,7 @@ async function withTempFile(scope: (tempFilePath: string) => Promise<void>) {
|
||||||
const tempDir = await fs.promises.mkdtemp(path.join(osTempDir, "rust-analyzer"));
|
const tempDir = await fs.promises.mkdtemp(path.join(osTempDir, "rust-analyzer"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await scope(path.join(tempDir, "file"));
|
return await scope(tempDir);
|
||||||
} finally {
|
} finally {
|
||||||
// We are good citizens :D
|
// We are good citizens :D
|
||||||
void fs.promises.rmdir(tempDir, { recursive: true }).catch(log.error);
|
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);
|
await fs.promises.unlink(src);
|
||||||
} else {
|
} else {
|
||||||
log.error(`Failed to rename the file ${src} -> ${dest}`, err);
|
log.error(`Failed to rename the file ${src} -> ${dest}`, err);
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ export const log = new class {
|
||||||
}
|
}
|
||||||
|
|
||||||
error(message?: any, ...optionalParams: any[]): void {
|
error(message?: any, ...optionalParams: any[]): void {
|
||||||
if (!log.enabled) return;
|
|
||||||
debugger;
|
debugger;
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(message, ...optionalParams);
|
console.error(message, ...optionalParams);
|
||||||
|
|
Loading…
Reference in a new issue