From 91dd61b9a662caf628a376d1e3b52b56b7ee8d31 Mon Sep 17 00:00:00 2001 From: Sahandevs Date: Tue, 9 Feb 2021 17:42:46 +0330 Subject: use await instead --- editors/code/src/commands.ts | 25 ++++++++++--------------- editors/code/src/debug.ts | 5 ++--- editors/code/src/main.ts | 15 ++++++--------- editors/code/src/run.ts | 7 +++---- 4 files changed, 21 insertions(+), 31 deletions(-) (limited to 'editors/code') diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 4170b9ccb..3729a71de 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -125,12 +125,11 @@ export function joinLines(ctx: Ctx): Cmd { ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)), textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document), }); - editor.edit((builder) => { + await editor.edit((builder) => { client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => { builder.replace(edit.range, edit.newText); }); - }) - .then(() => { }, console.error); + }); }; } @@ -237,7 +236,7 @@ export function ssr(ctx: Ctx): Cmd { const request = await vscode.window.showInputBox(options); if (!request) return; - vscode.window.withProgress({ + await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: "Structured search replace in progress...", cancellable: false, @@ -247,8 +246,7 @@ export function ssr(ctx: Ctx): Cmd { }); await vscode.workspace.applyEdit(client.protocol2CodeConverter.asWorkspaceEdit(edit)); - }) - .then(() => { }, console.error); + }); }; } @@ -459,16 +457,15 @@ export function reloadWorkspace(ctx: Ctx): Cmd { } export function showReferences(ctx: Ctx): Cmd { - return (uri: string, position: lc.Position, locations: lc.Location[]) => { + return async (uri: string, position: lc.Position, locations: lc.Location[]) => { const client = ctx.client; if (client) { - vscode.commands.executeCommand( + await vscode.commands.executeCommand( 'editor.action.showReferences', vscode.Uri.parse(uri), client.protocol2CodeConverter.asPosition(position), locations.map(client.protocol2CodeConverter.asLocation), - ) - .then(() => { }, console.error); + ); } }; } @@ -477,11 +474,10 @@ export function applyActionGroup(_ctx: Ctx): Cmd { return async (actions: { label: string; arguments: lc.CodeAction }[]) => { const selectedAction = await vscode.window.showQuickPick(actions); if (!selectedAction) return; - vscode.commands.executeCommand( + await vscode.commands.executeCommand( 'rust-analyzer.resolveCodeAction', selectedAction.arguments, - ) - .then(() => { }, console.error); + ); }; } @@ -514,8 +510,7 @@ export function openDocs(ctx: Ctx): Cmd { const doclink = await client.sendRequest(ra.openDocs, { position, textDocument }); if (doclink != null) { - vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink)) - .then(() => { }, console.error); + await vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink)); } }; diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index c72a7b278..3889a2773 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -77,9 +77,8 @@ async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise { }, console.error); + await vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)` + + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`); return; } diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index ecbe4e3c9..5c0b0be26 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -76,8 +76,7 @@ async function tryActivate(context: vscode.ExtensionContext) { // This a horribly, horribly wrong way to deal with this problem. ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath); - setContextValue(RUST_PROJECT_CONTEXT_NAME, true) - .then(() => { }, console.error); + await setContextValue(RUST_PROJECT_CONTEXT_NAME, true); // Commands which invokes manually via command palette, shortcut, etc. @@ -143,8 +142,7 @@ async function tryActivate(context: vscode.ExtensionContext) { } export async function deactivate() { - setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined) - .then(() => { }, console.error); + await setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined); await ctx?.client.stop(); ctx = undefined; } @@ -185,11 +183,10 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi const release = await downloadWithRetryDialog(state, async () => { return await fetchRelease("nightly", state.githubToken); - }).catch((e) => { + }).catch(async (e) => { log.error(e); if (state.releaseId === undefined) { // Show error only for the initial download - vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`) - .then(() => { }, console.error); + await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`); } return undefined; }); @@ -301,14 +298,14 @@ async function getServer(config: Config, state: PersistentState): Promise { }, console.error); + ); return undefined; } const ext = platform.indexOf("-windows-") !== -1 ? ".exe" : ""; diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index 331f85cd3..7ac7ca3cb 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -45,8 +45,7 @@ export async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick, if (items.length === 0) { // it is the debug case, run always has at least 'cargo check ...' // see crates\rust-analyzer\src\main_loop\handlers.rs, handle_runnables - vscode.window.showErrorMessage("There's no debug target!") - .then(() => { }, console.error); + await vscode.window.showErrorMessage("There's no debug target!"); return; } @@ -66,8 +65,8 @@ export async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick, disposables.push( quickPick.onDidHide(() => close()), quickPick.onDidAccept(() => close(quickPick.selectedItems[0])), - quickPick.onDidTriggerButton((_button) => { - makeDebugConfig(ctx, quickPick.activeItems[0].runnable).catch(console.error); + quickPick.onDidTriggerButton(async (_button) => { + await makeDebugConfig(ctx, quickPick.activeItems[0].runnable); close(); }), quickPick.onDidChangeActive((active) => { -- cgit v1.2.3