2018-08-10 12:07:43 +00:00
|
|
|
import * as vscode from 'vscode';
|
2020-03-17 11:44:31 +00:00
|
|
|
import * as path from "path";
|
|
|
|
import * as os from "os";
|
2020-05-21 15:26:50 +00:00
|
|
|
import { promises as fs, PathLike } from "fs";
|
2018-08-10 12:07:43 +00:00
|
|
|
|
2018-10-07 20:59:02 +00:00
|
|
|
import * as commands from './commands';
|
2019-12-30 19:21:25 +00:00
|
|
|
import { activateInlayHints } from './inlay_hints';
|
2019-12-30 14:11:30 +00:00
|
|
|
import { Ctx } from './ctx';
|
2020-03-17 11:44:31 +00:00
|
|
|
import { Config, NIGHTLY_TAG } from './config';
|
2020-05-05 22:42:04 +00:00
|
|
|
import { log, assert, isValidExecutable } from './util';
|
2020-03-16 18:23:38 +00:00
|
|
|
import { PersistentState } from './persistent_state';
|
2020-03-17 11:44:31 +00:00
|
|
|
import { fetchRelease, download } from './net';
|
2020-03-30 17:12:22 +00:00
|
|
|
import { activateTaskProvider } from './tasks';
|
2020-05-27 16:40:13 +00:00
|
|
|
import { setContextValue } from './util';
|
2020-05-21 15:26:50 +00:00
|
|
|
import { exec } from 'child_process';
|
2019-12-30 13:42:59 +00:00
|
|
|
|
2020-02-04 22:13:46 +00:00
|
|
|
let ctx: Ctx | undefined;
|
2018-08-10 12:07:43 +00:00
|
|
|
|
2020-05-27 16:40:13 +00:00
|
|
|
const RUST_PROJECT_CONTEXT_NAME = "inRustProject";
|
|
|
|
|
2019-12-08 12:41:44 +00:00
|
|
|
export async function activate(context: vscode.ExtensionContext) {
|
2020-07-02 02:19:02 +00:00
|
|
|
// For some reason vscode not always shows pop-up error notifications
|
|
|
|
// when an extension fails to activate, so we do it explicitly by ourselves.
|
|
|
|
// FIXME: remove this bit of code once vscode fixes this issue: https://github.com/microsoft/vscode/issues/101242
|
|
|
|
await tryActivate(context).catch(err => {
|
|
|
|
void vscode.window.showErrorMessage(`Cannot activate rust-analyzer: ${err.message}`);
|
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function tryActivate(context: vscode.ExtensionContext) {
|
2020-02-24 11:32:15 +00:00
|
|
|
// Register a "dumb" onEnter command for the case where server fails to
|
|
|
|
// start.
|
|
|
|
//
|
|
|
|
// FIXME: refactor command registration code such that commands are
|
|
|
|
// **always** registered, even if the server does not start. Use API like
|
|
|
|
// this perhaps?
|
|
|
|
//
|
|
|
|
// ```TypeScript
|
|
|
|
// registerCommand(
|
|
|
|
// factory: (Ctx) => ((Ctx) => any),
|
|
|
|
// fallback: () => any = () => vscode.window.showErrorMessage(
|
|
|
|
// "rust-analyzer is not available"
|
|
|
|
// ),
|
|
|
|
// )
|
|
|
|
const defaultOnEnter = vscode.commands.registerCommand(
|
|
|
|
'rust-analyzer.onEnter',
|
|
|
|
() => vscode.commands.executeCommand('default:type', { text: '\n' }),
|
|
|
|
);
|
|
|
|
context.subscriptions.push(defaultOnEnter);
|
|
|
|
|
2020-02-17 20:09:44 +00:00
|
|
|
const config = new Config(context);
|
2020-03-17 11:44:31 +00:00
|
|
|
const state = new PersistentState(context.globalState);
|
2020-06-20 12:38:08 +00:00
|
|
|
const serverPath = await bootstrap(config, state).catch(err => {
|
2020-06-22 18:18:36 +00:00
|
|
|
let message = "bootstrap error. ";
|
|
|
|
|
2020-07-07 09:09:37 +00:00
|
|
|
if (err.code === "EBUSY" || err.code === "ETXTBSY" || err.code === "EPERM") {
|
2020-06-22 18:18:36 +00:00
|
|
|
message += "Other vscode windows might be using rust-analyzer, ";
|
|
|
|
message += "you should close them and reload this window to retry. ";
|
2020-06-20 12:38:08 +00:00
|
|
|
}
|
2020-06-22 18:18:36 +00:00
|
|
|
|
2020-07-05 14:42:52 +00:00
|
|
|
message += 'See the logs in "OUTPUT > Rust Analyzer Client" (should open automatically). ';
|
|
|
|
message += 'To enable verbose logs use { "rust-analyzer.trace.extension": true }';
|
2020-06-22 18:18:36 +00:00
|
|
|
|
2020-06-20 12:38:08 +00:00
|
|
|
log.error("Bootstrap error", err);
|
|
|
|
throw new Error(message);
|
|
|
|
});
|
2020-02-17 13:03:33 +00:00
|
|
|
|
2020-03-31 08:05:22 +00:00
|
|
|
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
|
|
|
|
if (workspaceFolder === undefined) {
|
2020-07-02 02:19:02 +00:00
|
|
|
throw new Error("no folder is opened");
|
2020-03-31 08:05:22 +00:00
|
|
|
}
|
2020-03-30 17:12:22 +00:00
|
|
|
|
2020-02-17 12:40:20 +00:00
|
|
|
// Note: we try to start the server before we activate type hints so that it
|
|
|
|
// registers its `onDidChangeDocument` handler before us.
|
|
|
|
//
|
|
|
|
// This a horribly, horribly wrong way to deal with this problem.
|
2020-03-31 09:23:18 +00:00
|
|
|
ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath);
|
2020-02-17 12:40:20 +00:00
|
|
|
|
2020-05-27 16:40:13 +00:00
|
|
|
setContextValue(RUST_PROJECT_CONTEXT_NAME, true);
|
|
|
|
|
2020-02-17 12:40:20 +00:00
|
|
|
// Commands which invokes manually via command palette, shortcut, etc.
|
2020-03-26 21:44:19 +00:00
|
|
|
|
|
|
|
// Reloading is inspired by @DanTup maneuver: https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
|
|
|
|
ctx.registerCommand('reload', _ => async () => {
|
|
|
|
void vscode.window.showInformationMessage('Reloading rust-analyzer...');
|
|
|
|
await deactivate();
|
|
|
|
while (context.subscriptions.length > 0) {
|
|
|
|
try {
|
|
|
|
context.subscriptions.pop()!.dispose();
|
|
|
|
} catch (err) {
|
|
|
|
log.error("Dispose error:", err);
|
2020-02-17 11:17:01 +00:00
|
|
|
}
|
2020-03-26 21:44:19 +00:00
|
|
|
}
|
|
|
|
await activate(context).catch(log.error);
|
2020-02-17 20:09:44 +00:00
|
|
|
});
|
2020-02-17 11:17:01 +00:00
|
|
|
|
2020-09-23 07:50:34 +00:00
|
|
|
ctx.registerCommand('updateGithubToken', ctx => async () => {
|
|
|
|
await queryForGithubToken(new PersistentState(ctx.globalState));
|
|
|
|
});
|
|
|
|
|
2019-12-30 13:53:43 +00:00
|
|
|
ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
|
2020-07-07 10:10:14 +00:00
|
|
|
ctx.registerCommand('memoryUsage', commands.memoryUsage);
|
2020-07-01 12:57:59 +00:00
|
|
|
ctx.registerCommand('reloadWorkspace', commands.reloadWorkspace);
|
2019-12-30 14:20:13 +00:00
|
|
|
ctx.registerCommand('matchingBrace', commands.matchingBrace);
|
2019-12-30 14:50:15 +00:00
|
|
|
ctx.registerCommand('joinLines', commands.joinLines);
|
2019-12-30 16:03:05 +00:00
|
|
|
ctx.registerCommand('parentModule', commands.parentModule);
|
2019-12-30 18:05:41 +00:00
|
|
|
ctx.registerCommand('syntaxTree', commands.syntaxTree);
|
2019-12-30 18:30:30 +00:00
|
|
|
ctx.registerCommand('expandMacro', commands.expandMacro);
|
2019-12-30 18:58:44 +00:00
|
|
|
ctx.registerCommand('run', commands.run);
|
2020-05-11 13:06:57 +00:00
|
|
|
ctx.registerCommand('debug', commands.debug);
|
2020-05-11 15:00:15 +00:00
|
|
|
ctx.registerCommand('newDebugConfig', commands.newDebugConfig);
|
2020-08-30 08:02:29 +00:00
|
|
|
ctx.registerCommand('openDocs', commands.openDocs);
|
2020-11-13 01:48:07 +00:00
|
|
|
ctx.registerCommand('openCargoToml', commands.openCargoToml);
|
2020-02-24 11:32:15 +00:00
|
|
|
|
|
|
|
defaultOnEnter.dispose();
|
2020-02-02 01:21:04 +00:00
|
|
|
ctx.registerCommand('onEnter', commands.onEnter);
|
2020-02-24 11:32:15 +00:00
|
|
|
|
2020-02-17 20:09:44 +00:00
|
|
|
ctx.registerCommand('ssr', commands.ssr);
|
2020-02-21 02:04:03 +00:00
|
|
|
ctx.registerCommand('serverVersion', commands.serverVersion);
|
2020-05-25 00:47:33 +00:00
|
|
|
ctx.registerCommand('toggleInlayHints', commands.toggleInlayHints);
|
2019-12-30 19:07:04 +00:00
|
|
|
|
|
|
|
// Internal commands which are invoked by the server.
|
|
|
|
ctx.registerCommand('runSingle', commands.runSingle);
|
2020-03-09 21:06:45 +00:00
|
|
|
ctx.registerCommand('debugSingle', commands.debugSingle);
|
2019-12-30 19:07:04 +00:00
|
|
|
ctx.registerCommand('showReferences', commands.showReferences);
|
2020-05-21 12:26:44 +00:00
|
|
|
ctx.registerCommand('applySnippetWorkspaceEdit', commands.applySnippetWorkspaceEditCommand);
|
2020-06-02 20:21:48 +00:00
|
|
|
ctx.registerCommand('resolveCodeAction', commands.resolveCodeAction);
|
2020-05-22 15:29:55 +00:00
|
|
|
ctx.registerCommand('applyActionGroup', commands.applyActionGroup);
|
2020-06-10 20:01:19 +00:00
|
|
|
ctx.registerCommand('gotoLocation', commands.gotoLocation);
|
2019-12-30 13:42:59 +00:00
|
|
|
|
2020-06-18 19:20:13 +00:00
|
|
|
ctx.pushCleanup(activateTaskProvider(workspaceFolder, ctx.config));
|
2020-03-30 17:12:22 +00:00
|
|
|
|
2019-12-31 17:14:00 +00:00
|
|
|
activateInlayHints(ctx);
|
2020-03-18 23:39:12 +00:00
|
|
|
|
|
|
|
vscode.workspace.onDidChangeConfiguration(
|
|
|
|
_ => ctx?.client?.sendNotification('workspace/didChangeConfiguration', { settings: "" }),
|
|
|
|
null,
|
2020-03-21 22:40:07 +00:00
|
|
|
ctx.subscriptions,
|
2020-03-18 23:39:12 +00:00
|
|
|
);
|
2018-08-17 16:54:08 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 17:14:00 +00:00
|
|
|
export async function deactivate() {
|
2020-05-27 16:40:13 +00:00
|
|
|
setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
|
2020-03-26 21:44:19 +00:00
|
|
|
await ctx?.client.stop();
|
2020-02-17 11:17:01 +00:00
|
|
|
ctx = undefined;
|
2019-04-16 20:11:50 +00:00
|
|
|
}
|
2020-03-17 11:44:31 +00:00
|
|
|
|
|
|
|
async function bootstrap(config: Config, state: PersistentState): Promise<string> {
|
|
|
|
await fs.mkdir(config.globalStoragePath, { recursive: true });
|
|
|
|
|
|
|
|
await bootstrapExtension(config, state);
|
|
|
|
const path = await bootstrapServer(config, state);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
|
2020-03-25 18:56:48 +00:00
|
|
|
if (config.package.releaseTag === null) return;
|
2020-03-17 11:44:31 +00:00
|
|
|
if (config.channel === "stable") {
|
2020-03-24 08:31:42 +00:00
|
|
|
if (config.package.releaseTag === NIGHTLY_TAG) {
|
2020-03-25 18:56:48 +00:00
|
|
|
void vscode.window.showWarningMessage(
|
|
|
|
`You are running a nightly version of rust-analyzer extension. ` +
|
|
|
|
`To switch to stable, uninstall the extension and re-install it from the marketplace`
|
|
|
|
);
|
2020-03-17 11:44:31 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
const now = Date.now();
|
2020-07-02 01:56:50 +00:00
|
|
|
if (config.package.releaseTag === NIGHTLY_TAG) {
|
|
|
|
// Check if we should poll github api for the new nightly version
|
|
|
|
// if we haven't done it during the past hour
|
|
|
|
const lastCheck = state.lastCheck;
|
2020-03-17 11:44:31 +00:00
|
|
|
|
2020-07-02 01:56:50 +00:00
|
|
|
const anHour = 60 * 60 * 1000;
|
|
|
|
const shouldCheckForNewNightly = state.releaseId === undefined || (now - (lastCheck ?? 0)) > anHour;
|
2020-03-17 11:44:31 +00:00
|
|
|
|
2020-07-02 01:56:50 +00:00
|
|
|
if (!shouldCheckForNewNightly) return;
|
|
|
|
}
|
2020-03-17 11:44:31 +00:00
|
|
|
|
2020-09-23 15:27:25 +00:00
|
|
|
const release = await downloadWithRetryDialog(state, async () => {
|
2020-09-23 06:12:51 +00:00
|
|
|
return await fetchRelease("nightly", state.githubToken);
|
2020-09-23 15:24:35 +00:00
|
|
|
}).catch((e) => {
|
2020-03-17 11:44:31 +00:00
|
|
|
log.error(e);
|
|
|
|
if (state.releaseId === undefined) { // Show error only for the initial download
|
|
|
|
vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`);
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
if (release === undefined || release.id === state.releaseId) return;
|
|
|
|
|
|
|
|
const userResponse = await vscode.window.showInformationMessage(
|
|
|
|
"New version of rust-analyzer (nightly) is available (requires reload).",
|
|
|
|
"Update"
|
|
|
|
);
|
|
|
|
if (userResponse !== "Update") return;
|
|
|
|
|
|
|
|
const artifact = release.assets.find(artifact => artifact.name === "rust-analyzer.vsix");
|
|
|
|
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
|
|
|
|
|
|
|
|
const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
|
2020-09-23 07:28:38 +00:00
|
|
|
|
2020-09-23 15:27:25 +00:00
|
|
|
await downloadWithRetryDialog(state, async () => {
|
2020-09-23 07:28:38 +00:00
|
|
|
await download({
|
|
|
|
url: artifact.browser_download_url,
|
|
|
|
dest,
|
|
|
|
progressTitle: "Downloading rust-analyzer extension",
|
2020-09-23 15:37:02 +00:00
|
|
|
overwrite: true,
|
2020-09-23 07:28:38 +00:00
|
|
|
});
|
2020-09-23 15:24:35 +00:00
|
|
|
});
|
2020-03-17 11:44:31 +00:00
|
|
|
|
|
|
|
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
|
|
|
|
await fs.unlink(dest);
|
|
|
|
|
|
|
|
await state.updateReleaseId(release.id);
|
|
|
|
await state.updateLastCheck(now);
|
|
|
|
await vscode.commands.executeCommand("workbench.action.reloadWindow");
|
|
|
|
}
|
|
|
|
|
|
|
|
async function bootstrapServer(config: Config, state: PersistentState): Promise<string> {
|
|
|
|
const path = await getServer(config, state);
|
|
|
|
if (!path) {
|
|
|
|
throw new Error(
|
|
|
|
"Rust Analyzer Language Server is not available. " +
|
|
|
|
"Please, ensure its [proper installation](https://rust-analyzer.github.io/manual.html#installation)."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-05 14:42:52 +00:00
|
|
|
log.info("Using server binary at", path);
|
2020-04-04 13:10:06 +00:00
|
|
|
|
2020-05-05 22:42:04 +00:00
|
|
|
if (!isValidExecutable(path)) {
|
2020-03-26 21:45:01 +00:00
|
|
|
throw new Error(`Failed to execute ${path} --version`);
|
2020-03-17 11:44:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2020-05-21 15:26:50 +00:00
|
|
|
async function patchelf(dest: PathLike): Promise<void> {
|
|
|
|
await vscode.window.withProgress(
|
|
|
|
{
|
2020-05-21 15:49:30 +00:00
|
|
|
location: vscode.ProgressLocation.Notification,
|
2020-05-21 15:50:28 +00:00
|
|
|
title: "Patching rust-analyzer for NixOS"
|
2020-05-21 15:49:30 +00:00
|
|
|
},
|
2020-05-21 15:26:50 +00:00
|
|
|
async (progress, _) => {
|
2020-05-21 18:30:56 +00:00
|
|
|
const expression = `
|
2020-05-21 15:26:50 +00:00
|
|
|
{src, pkgs ? import <nixpkgs> {}}:
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
name = "rust-analyzer";
|
|
|
|
inherit src;
|
|
|
|
phases = [ "installPhase" "fixupPhase" ];
|
|
|
|
installPhase = "cp $src $out";
|
|
|
|
fixupPhase = ''
|
|
|
|
chmod 755 $out
|
|
|
|
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out
|
|
|
|
'';
|
|
|
|
}
|
2020-05-21 18:30:56 +00:00
|
|
|
`;
|
2020-05-21 15:49:30 +00:00
|
|
|
const origFile = dest + "-orig";
|
|
|
|
await fs.rename(dest, origFile);
|
|
|
|
progress.report({ message: "Patching executable", increment: 20 });
|
2020-05-21 15:26:50 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
2020-05-21 18:30:56 +00:00
|
|
|
const handle = exec(`nix-build -E - --arg src '${origFile}' -o ${dest}`,
|
2020-05-21 15:49:30 +00:00
|
|
|
(err, stdout, stderr) => {
|
|
|
|
if (err != null) {
|
|
|
|
reject(Error(stderr));
|
|
|
|
} else {
|
|
|
|
resolve(stdout);
|
|
|
|
}
|
|
|
|
});
|
2020-05-21 18:30:56 +00:00
|
|
|
handle.stdin?.write(expression);
|
|
|
|
handle.stdin?.end();
|
2020-05-21 15:49:30 +00:00
|
|
|
});
|
|
|
|
await fs.unlink(origFile);
|
2020-05-21 15:26:50 +00:00
|
|
|
}
|
2020-05-21 15:49:30 +00:00
|
|
|
);
|
2020-05-21 15:26:50 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 11:44:31 +00:00
|
|
|
async function getServer(config: Config, state: PersistentState): Promise<string | undefined> {
|
|
|
|
const explicitPath = process.env.__RA_LSP_SERVER_DEBUG ?? config.serverPath;
|
|
|
|
if (explicitPath) {
|
|
|
|
if (explicitPath.startsWith("~/")) {
|
|
|
|
return os.homedir() + explicitPath.slice("~".length);
|
|
|
|
}
|
|
|
|
return explicitPath;
|
|
|
|
};
|
2020-03-25 18:56:48 +00:00
|
|
|
if (config.package.releaseTag === null) return "rust-analyzer";
|
2020-03-17 11:44:31 +00:00
|
|
|
|
2020-06-21 12:58:34 +00:00
|
|
|
let platform: string | undefined;
|
2020-03-25 09:51:03 +00:00
|
|
|
if (process.arch === "x64" || process.arch === "ia32") {
|
2020-06-21 12:58:34 +00:00
|
|
|
if (process.platform === "linux") platform = "linux";
|
|
|
|
if (process.platform === "darwin") platform = "mac";
|
|
|
|
if (process.platform === "win32") platform = "windows";
|
2020-03-17 11:44:31 +00:00
|
|
|
}
|
2020-06-21 12:58:34 +00:00
|
|
|
if (platform === undefined) {
|
2020-03-17 11:44:31 +00:00
|
|
|
vscode.window.showErrorMessage(
|
|
|
|
"Unfortunately we don't ship binaries for your platform yet. " +
|
|
|
|
"You need to manually clone rust-analyzer repository and " +
|
|
|
|
"run `cargo xtask install --server` to build the language server from sources. " +
|
|
|
|
"If you feel that your platform should be supported, please create an issue " +
|
|
|
|
"about that [here](https://github.com/rust-analyzer/rust-analyzer/issues) and we " +
|
|
|
|
"will consider it."
|
|
|
|
);
|
|
|
|
return undefined;
|
|
|
|
}
|
2020-06-21 12:58:34 +00:00
|
|
|
const ext = platform === "windows" ? ".exe" : "";
|
|
|
|
const dest = path.join(config.globalStoragePath, `rust-analyzer-${platform}${ext}`);
|
2020-03-17 11:44:31 +00:00
|
|
|
const exists = await fs.stat(dest).then(() => true, () => false);
|
|
|
|
if (!exists) {
|
|
|
|
await state.updateServerVersion(undefined);
|
|
|
|
}
|
|
|
|
|
2020-03-24 08:31:42 +00:00
|
|
|
if (state.serverVersion === config.package.version) return dest;
|
2020-03-17 11:44:31 +00:00
|
|
|
|
|
|
|
if (config.askBeforeDownload) {
|
|
|
|
const userResponse = await vscode.window.showInformationMessage(
|
2020-03-24 08:31:42 +00:00
|
|
|
`Language server version ${config.package.version} for rust-analyzer is not installed.`,
|
2020-03-17 11:44:31 +00:00
|
|
|
"Download now"
|
|
|
|
);
|
|
|
|
if (userResponse !== "Download now") return dest;
|
|
|
|
}
|
|
|
|
|
2020-09-23 06:12:51 +00:00
|
|
|
const releaseTag = config.package.releaseTag;
|
2020-09-23 15:27:25 +00:00
|
|
|
const release = await downloadWithRetryDialog(state, async () => {
|
2020-09-23 06:12:51 +00:00
|
|
|
return await fetchRelease(releaseTag, state.githubToken);
|
2020-09-23 15:24:35 +00:00
|
|
|
});
|
2020-06-21 12:58:34 +00:00
|
|
|
const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
|
2020-03-17 11:44:31 +00:00
|
|
|
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
|
|
|
|
|
2020-09-23 15:27:25 +00:00
|
|
|
await downloadWithRetryDialog(state, async () => {
|
2020-09-23 07:28:38 +00:00
|
|
|
await download({
|
|
|
|
url: artifact.browser_download_url,
|
|
|
|
dest,
|
|
|
|
progressTitle: "Downloading rust-analyzer server",
|
|
|
|
gunzip: true,
|
2020-09-23 15:37:02 +00:00
|
|
|
mode: 0o755,
|
|
|
|
overwrite: true,
|
2020-09-23 07:28:38 +00:00
|
|
|
});
|
2020-09-23 15:24:35 +00:00
|
|
|
});
|
2020-05-21 15:26:50 +00:00
|
|
|
|
|
|
|
// Patching executable if that's NixOS.
|
2020-05-21 18:32:27 +00:00
|
|
|
if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
|
2020-05-21 15:49:30 +00:00
|
|
|
await patchelf(dest);
|
2020-05-21 15:26:50 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 08:31:42 +00:00
|
|
|
await state.updateServerVersion(config.package.version);
|
2020-03-17 11:44:31 +00:00
|
|
|
return dest;
|
|
|
|
}
|
2020-09-23 06:12:51 +00:00
|
|
|
|
2020-09-23 15:27:25 +00:00
|
|
|
async function downloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> {
|
2020-09-23 06:12:51 +00:00
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
return await downloadFunc();
|
|
|
|
} catch (e) {
|
2020-09-23 15:14:18 +00:00
|
|
|
const selected = await vscode.window.showErrorMessage("Failed to download: " + e.message, {}, {
|
2020-09-23 06:12:51 +00:00
|
|
|
title: "Update Github Auth Token",
|
|
|
|
updateToken: true,
|
|
|
|
}, {
|
|
|
|
title: "Retry download",
|
|
|
|
retry: true,
|
|
|
|
}, {
|
|
|
|
title: "Dismiss",
|
|
|
|
});
|
2020-09-23 06:41:51 +00:00
|
|
|
|
2020-09-23 06:12:51 +00:00
|
|
|
if (selected?.updateToken) {
|
|
|
|
await queryForGithubToken(state);
|
|
|
|
continue;
|
|
|
|
} else if (selected?.retry) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function queryForGithubToken(state: PersistentState): Promise<void> {
|
|
|
|
const githubTokenOptions: vscode.InputBoxOptions = {
|
|
|
|
value: state.githubToken,
|
|
|
|
password: true,
|
|
|
|
prompt: `
|
|
|
|
This dialog allows to store a Github authorization token.
|
2020-09-23 07:28:38 +00:00
|
|
|
The usage of an authorization token will increase the rate
|
2020-09-23 06:12:51 +00:00
|
|
|
limit on the use of Github APIs and can thereby prevent getting
|
|
|
|
throttled.
|
2020-09-23 07:28:38 +00:00
|
|
|
Auth tokens can be created at https://github.com/settings/tokens`,
|
2020-09-23 06:12:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const newToken = await vscode.window.showInputBox(githubTokenOptions);
|
2020-09-23 15:24:35 +00:00
|
|
|
if (newToken === undefined) {
|
|
|
|
// The user aborted the dialog => Do not update the stored token
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newToken === "") {
|
|
|
|
log.info("Clearing github token");
|
|
|
|
await state.updateGithubToken(undefined);
|
|
|
|
} else {
|
|
|
|
log.info("Storing new github token");
|
|
|
|
await state.updateGithubToken(newToken);
|
2020-09-23 06:12:51 +00:00
|
|
|
}
|
2020-09-23 07:28:38 +00:00
|
|
|
}
|