Use executeCommand(vscode.open) instead of opn (#903)

* use vscode.open instead of opn everywhere.
For thenables, disable no-floating-promises
This commit is contained in:
Prashanth 2019-04-24 16:04:25 -07:00 коммит произвёл GitHub
Родитель 7287cd4503
Коммит baf595f118
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 55 добавлений и 33 удалений

3
.gitignore поставляемый
Просмотреть файл

@ -12,3 +12,6 @@ testOutput
test-results.xml
dist
stats.json
# Artifacts from running npm install
**/npm-debug.log

Просмотреть файл

@ -6,10 +6,10 @@ import * as ContainerModels from 'azure-arm-containerregistry/lib/models';
import { Registry } from 'azure-arm-containerregistry/lib/models';
import { ResourceGroup } from 'azure-arm-resource/lib/resource/models';
import { Location, Subscription } from 'azure-arm-resource/lib/subscription/models';
import * as opn from 'opn';
import * as vscode from "vscode";
import { IAzureQuickPickItem, UserCancelledError } from 'vscode-azureextensionui';
import { skus } from '../../constants'
import { skus } from '../../constants';
import { openExternal } from '../../explorer/utils/openExternal';
import { ext } from '../../extensionVariables';
import { ResourceManagementClient } from '../../node_modules/azure-arm-resource';
import * as acrTools from '../../utils/Azure/acrTools';
@ -79,12 +79,15 @@ export async function quickPickSubscription(): Promise<Subscription> {
const subscriptions = await AzureUtilityManager.getInstance().getFilteredSubscriptionList();
if (subscriptions.length === 0) {
let openPortal = 'Open Portal';
vscode.window.showErrorMessage("You are not signed in to Azure, or you do not have any subscriptions. To sign in, select 'Azure: Sign In' from the command palette. Subscriptions can be created in the Azure portal", openPortal).then(val => {
if (val === openPortal) {
// tslint:disable-next-line:no-unsafe-any
opn('https://portal.azure.com/');
}
});
vscode.window.showErrorMessage("You are not signed in to Azure, or you do not have any subscriptions. To sign in, select 'Azure: Sign In' from the command palette. Subscriptions can be created in the Azure portal", openPortal)
.then(response => {
if (response === openPortal) {
//don't wait for openExternal to finish. Intentional
// tslint:disable-next-line: no-floating-promises
openExternal('https://portal.azure.com/');
}
});
}
if (subscriptions.length === 1) { return subscriptions[0]; }

Просмотреть файл

@ -2,8 +2,8 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as opn from 'opn';
import { Uri } from "vscode";
import { openExternal } from '../../explorer/utils/openExternal';
export interface BrowserClient {
openBrowser(url: string): void;
@ -14,8 +14,8 @@ export class OpnBrowserClient implements BrowserClient {
const uri = Uri.parse(url);
if (uri.scheme === 'http' || uri.scheme === 'https') {
// tslint:disable-next-line:no-unsafe-any
opn(url);
// tslint:disable-next-line:no-floating-promises
openExternal(url);
}
}
}

Просмотреть файл

@ -1,7 +1,6 @@
import ContainerRegistryManagementClient from 'azure-arm-containerregistry';
import * as ContainerModels from 'azure-arm-containerregistry/lib/models';
import { SubscriptionModels } from 'azure-arm-resource';
import * as opn from 'opn';
import * as path from 'path';
import * as vscode from 'vscode';
import { callWithTelemetryAndErrorHandling, IActionContext } from 'vscode-azureextensionui';
@ -9,6 +8,7 @@ import { imagesPath } from '../../constants';
import { AzureAccount } from '../../typings/azure-account.api';
import * as acrTools from '../../utils/Azure/acrTools';
import { AzureUtilityManager } from '../../utils/azureUtilityManager';
import { openExternal } from '../utils/openExternal';
import { NodeBase } from './nodeBase';
/* Single TaskRootNode under each Repository. Labeled "Tasks" */
@ -55,12 +55,15 @@ export class TaskRootNode extends NodeBase {
tasks = await client.tasks.list(resourceGroup, element.registry.name);
if (tasks.length === 0) {
const learnHow: vscode.MessageItem = { title: "Learn How to Create Build Tasks" };
vscode.window.showInformationMessage(`You do not have any Tasks in the registry '${element.registry.name}'.`, learnHow).then(val => {
if (val === learnHow) {
// tslint:disable-next-line:no-unsafe-any
opn('https://aka.ms/acr/task');
}
})
vscode.window.showInformationMessage(`You do not have any Tasks in the registry '${element.registry.name}'.`, learnHow)
.then(response => {
if (response === learnHow) {
//don't wait for openExternal to finish. Intentional
// tslint:disable-next-line: no-floating-promises
openExternal('https://aka.ms/acr/task');
}
});
}
for (let task of tasks) {

Просмотреть файл

@ -3,10 +3,10 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as opn from 'opn';
import { AzureSession } from '../../typings/azure-account.api';
import { getTenantId, nonNullValue } from '../../utils/nonNull';
import { AzureImageTagNode, AzureRegistryNode, AzureRepositoryNode } from '../models/azureRegistryNodes';
import { openExternal } from './openExternal';
export function browseAzurePortal(node?: AzureRegistryNode | AzureRepositoryNode | AzureImageTagNode): void {
if (node && node.azureAccount) {
@ -18,7 +18,7 @@ export function browseAzurePortal(node?: AzureRegistryNode | AzureRepositoryNode
if (node.contextValue === AzureImageTagNode.contextValue || node.contextValue === AzureRepositoryNode.contextValue) {
url = `${url}/repository`;
}
// tslint:disable-next-line:no-unsafe-any
opn(url);
// tslint:disable-next-line:no-floating-promises
openExternal(url);
}
}

Просмотреть файл

@ -3,12 +3,12 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as opn from 'opn';
import { MessageItem } from "vscode";
import * as vscode from 'vscode';
import { MessageItem } from "vscode";
import { IActionContext, parseError } from "vscode-azureextensionui";
import { isLinux } from "../../helpers/osVersion";
import { wrapError } from "../../utils/wrapError";
import { openExternal } from './openExternal';
const connectionMessage = 'Unable to connect to Docker. Please make sure you have installed Docker and that it is running.';
@ -37,8 +37,8 @@ export function showDockerConnectionError(actionContext: IActionContext, error:
actionContext.suppressErrorDisplay = true;
vscode.window.showErrorMessage(parseError(wrappedError).message, ...items).then(response => {
if (response) {
// tslint:disable-next-line:no-unsafe-any
opn(response.url);
// tslint:disable-next-line:no-floating-promises
openExternal(response.url);
}
});

Просмотреть файл

@ -4,12 +4,12 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as opn from 'opn';
import * as vscode from 'vscode';
import { keytarConstants, PAGE_SIZE } from '../../constants';
import { ext } from '../../extensionVariables';
import { DockerHubImageTagNode, DockerHubOrgNode, DockerHubRepositoryNode } from '../models/dockerHubNodes';
import { NodeBase } from '../models/nodeBase';
import { openExternal } from './openExternal';
let _token: Token;
@ -261,7 +261,7 @@ export async function getRepositoryTags(repository: Repository): Promise<Tag[]>
return tagsPage.results;
}
export function browseDockerHub(node?: DockerHubImageTagNode | DockerHubRepositoryNode | DockerHubOrgNode): void {
export async function browseDockerHub(node?: DockerHubImageTagNode | DockerHubRepositoryNode | DockerHubOrgNode): Promise<void> {
if (node) {
let url: string = 'https://hub.docker.com/';
if (node instanceof DockerHubOrgNode) {
@ -274,7 +274,6 @@ export function browseDockerHub(node?: DockerHubImageTagNode | DockerHubReposito
assert(false, `browseDockerHub: Unexpected node type, contextValue=${(<NodeBase>node).contextValue}`)
}
// tslint:disable-next-line:no-unsafe-any
opn(url);
await openExternal(url);
}
}

Просмотреть файл

@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { commands, Uri } from 'vscode';
export async function openExternal(path: string, throwErrorOnFailure: boolean = false): Promise<void> {
let uri = Uri.parse(path);
let successful: boolean = await commands.executeCommand('vscode.open', uri);
if (!successful && throwErrorOnFailure) {
throw new Error(`Opening ${path} was unsuccessful`);
}
return;
}

Просмотреть файл

@ -280,7 +280,7 @@ function registerDockerCommands(): void {
registerCommand('vscode-docker.acr.viewLogs', viewACRLogs);
registerCommand('vscode-docker.api.configure', async function (this: IActionContext, options: ConfigureApiOptions): Promise<void> { await configureApi(this, options); });
registerCommand('vscode-docker.browseDockerHub', (context?: DockerHubImageTagNode | DockerHubRepositoryNode | DockerHubOrgNode) => { browseDockerHub(context); });
registerCommand('vscode-docker.browseDockerHub', async (context?: DockerHubImageTagNode | DockerHubRepositoryNode | DockerHubOrgNode) => { await browseDockerHub(context); });
registerCommand('vscode-docker.browseAzurePortal', (context?: AzureRegistryNode | AzureRepositoryNode | AzureImageTagNode) => { browseAzurePortal(context); });
registerCommand('vscode-docker.compose.down', composeDown);

Просмотреть файл

@ -9,10 +9,10 @@ import { ResourceManagementClient, SubscriptionClient, SubscriptionModels } from
import { ResourceGroup } from "azure-arm-resource/lib/resource/models";
import { Subscription } from 'azure-arm-resource/lib/subscription/models';
import { ServiceClientCredentials } from 'ms-rest';
import * as opn from 'opn';
import * as vscode from 'vscode';
import { addExtensionUserAgent, callWithTelemetryAndErrorHandling, IActionContext, parseError, UserCancelledError } from 'vscode-azureextensionui';
import { MAX_CONCURRENT_SUBSCRIPTON_REQUESTS } from '../constants';
import { openExternal } from '../explorer/utils/openExternal';
import { AzureAccount, AzureSession } from '../typings/azure-account.api';
import { AsyncPool } from './asyncpool';
import { getSubscriptionId, getTenantId } from './nonNull';
@ -75,8 +75,7 @@ export class AzureUtilityManager {
const msg = 'This functionality requires installing the Azure Account extension.';
let response = await vscode.window.showErrorMessage(msg, open);
if (response === open) {
// tslint:disable-next-line:no-unsafe-any
opn('https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account');
await openExternal('https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account');
}
throw new UserCancelledError(msg);