This commit is contained in:
Eric Jizba 2020-02-07 11:04:19 -08:00 коммит произвёл GitHub
Родитель 6fc3c2ef00
Коммит 67c8ebc6b8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 54 добавлений и 203 удалений

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

@ -535,6 +535,11 @@
"when": "view == azFuncTree && viewItem =~ /Function;Timer;/i",
"group": "1@1"
},
{
"command": "azureFunctions.addBinding",
"when": "view == azFuncTree && viewItem =~ /Local;ReadWrite;Function;/i",
"group": "2@1"
},
{
"command": "azureFunctions.deleteFunction",
"when": "view == azFuncTree && viewItem =~ /Remote;ReadWrite;Function;/i",
@ -550,16 +555,6 @@
"when": "view == azFuncTree && viewItem =~ /Remote;.*;Function;/i",
"group": "3@2"
},
{
"command": "azureFunctions.viewProperties",
"when": "view == azFuncTree && viewItem =~ /Remote;.*;Function;/i",
"group": "4@1"
},
{
"command": "azureFunctions.viewProperties",
"when": "view == azFuncTree && viewItem =~ /Remote;.*;Binding;/i",
"group": "1@1"
},
{
"command": "azureFunctions.appSettings.add",
"when": "view == azFuncTree && viewItem == applicationSettings",
@ -645,10 +640,6 @@
"when": "view == azFuncTree && viewItem =~ /^deployment//",
"group": "inline"
},
{
"command": "azureFunctions.addBinding",
"when": "view == azFuncTree && viewItem =~ /Local;ReadWrite;Bindings;/i"
},
{
"command": "azureFunctions.refresh",
"when": "view == azFuncTree && viewItem == siteFiles",

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

@ -6,29 +6,41 @@
import { Uri, WorkspaceFolder } from "vscode";
import { AzureWizard, IActionContext } from "vscode-azureextensionui";
import { ProjectLanguage } from "../../constants";
import { ext } from "../../extensionVariables";
import { FuncVersion } from "../../FuncVersion";
import { LocalBindingsTreeItem } from "../../tree/localProject/LocalBindingsTreeItem";
import { LocalFunctionTreeItem } from "../../tree/localProject/LocalFunctionTreeItem";
import { nonNullValue } from "../../utils/nonNull";
import { getContainingWorkspace } from "../../utils/workspace";
import { verifyInitForVSCode } from "../../vsCodeConfig/verifyInitForVSCode";
import { createChildNode } from "../createChildNode";
import { tryGetFunctionProjectRoot } from "../createNewProject/verifyIsProject";
import { createBindingWizard } from "./createBindingWizard";
import { IBindingWizardContext } from "./IBindingWizardContext";
export async function addBinding(context: IActionContext, data: Uri | LocalBindingsTreeItem | undefined): Promise<void> {
if (data instanceof Uri) {
const functionJsonPath: string = data.fsPath;
const workspaceFolder: WorkspaceFolder = nonNullValue(getContainingWorkspace(functionJsonPath), 'workspaceFolder');
const workspacePath: string = workspaceFolder.uri.fsPath;
const projectPath: string | undefined = await tryGetFunctionProjectRoot(workspacePath) || workspacePath;
const [language, version]: [ProjectLanguage, FuncVersion] = await verifyInitForVSCode(context, projectPath);
export async function addBinding(context: IActionContext, data: Uri | LocalFunctionTreeItem | undefined): Promise<void> {
let functionJsonPath: string;
let workspaceFolder: WorkspaceFolder;
let workspacePath: string;
let projectPath: string | undefined;
const wizardContext: IBindingWizardContext = Object.assign(context, { functionJsonPath: data.fsPath, workspacePath, projectPath, workspaceFolder, language, version });
const wizard: AzureWizard<IBindingWizardContext> = createBindingWizard(wizardContext);
await wizard.prompt();
await wizard.execute();
if (data instanceof Uri) {
functionJsonPath = data.fsPath;
workspaceFolder = nonNullValue(getContainingWorkspace(functionJsonPath), 'workspaceFolder');
workspacePath = workspaceFolder.uri.fsPath;
projectPath = await tryGetFunctionProjectRoot(workspacePath) || workspacePath;
} else {
await createChildNode(context, /Local;ReadWrite;Bindings;/i, data);
if (!data) {
data = await ext.tree.showTreeItemPicker<LocalFunctionTreeItem>(/Local;ReadWrite;Function;/i, context);
}
functionJsonPath = data.functionJsonPath;
workspaceFolder = data.parent.parent.workspaceFolder;
workspacePath = data.parent.parent.workspacePath;
projectPath = data.parent.parent.projectPath;
}
const [language, version]: [ProjectLanguage, FuncVersion] = await verifyInitForVSCode(context, projectPath);
const wizardContext: IBindingWizardContext = Object.assign(context, { functionJsonPath, workspacePath, projectPath, workspaceFolder, language, version });
const wizard: AzureWizard<IBindingWizardContext> = createBindingWizard(wizardContext);
await wizard.prompt();
await wizard.execute();
}

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

@ -3,26 +3,29 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Uri, window } from 'vscode';
import { IActionContext, openReadOnlyJson } from 'vscode-azureextensionui';
import { ext } from '../extensionVariables';
import { BindingTreeItem } from '../tree/BindingTreeItem';
import { FunctionTreeItemBase } from '../tree/FunctionTreeItemBase';
import { LocalFunctionTreeItem } from '../tree/localProject/LocalFunctionTreeItem';
import { ProductionSlotTreeItem } from '../tree/ProductionSlotTreeItem';
import { RemoteFunctionTreeItem } from '../tree/remoteProject/RemoteFunctionTreeItem';
import { SlotTreeItemBase } from '../tree/SlotTreeItemBase';
export async function viewProperties(context: IActionContext, node?: SlotTreeItemBase | FunctionTreeItemBase | BindingTreeItem): Promise<void> {
export async function viewProperties(context: IActionContext, node?: SlotTreeItemBase | RemoteFunctionTreeItem | LocalFunctionTreeItem): Promise<void> {
if (!node) {
node = await ext.tree.showTreeItemPicker<ProductionSlotTreeItem>(ProductionSlotTreeItem.contextValue, context);
}
let data: {};
if (node instanceof SlotTreeItemBase) {
data = node.site;
} else if (node instanceof FunctionTreeItemBase) {
data = node.config.data;
if (node instanceof LocalFunctionTreeItem) {
await window.showTextDocument(Uri.file(node.functionJsonPath));
} else {
data = node.binding;
}
let data: {};
if (node instanceof SlotTreeItemBase) {
data = node.site;
} else {
data = node.config.data;
}
await openReadOnlyJson(node, data);
await openReadOnlyJson(node, data);
}
}

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

@ -1,39 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzExtTreeItem } from 'vscode-azureextensionui';
import { IFunctionBinding } from '../funcConfig/function';
import { nonNullProp } from '../utils/nonNull';
import { BindingsTreeItem } from './BindingsTreeItem';
import { getProjectContextValue, ProjectResource } from './projectContextValues';
export class BindingTreeItem extends AzExtTreeItem {
public readonly parent: BindingsTreeItem;
public binding: IFunctionBinding;
private readonly _name: string;
public constructor(parent: BindingsTreeItem, binding: IFunctionBinding) {
super(parent);
this.binding = binding;
this._name = nonNullProp(binding, 'name');
}
public get contextValue(): string {
return getProjectContextValue(this.parent.parent.parent.parent.source, this.parent.parent.parent.access, ProjectResource.Binding);
}
public get id(): string {
return this._name;
}
public get label(): string {
return this._name;
}
public get description(): string | undefined {
return this.binding.direction;
}
}

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

@ -1,41 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzExtParentTreeItem, TreeItemIconPath } from 'vscode-azureextensionui';
import { localize } from '../localize';
import { treeUtils } from '../utils/treeUtils';
import { BindingTreeItem } from './BindingTreeItem';
import { FunctionTreeItemBase } from './FunctionTreeItemBase';
import { getProjectContextValue, ProjectResource } from './projectContextValues';
export class BindingsTreeItem extends AzExtParentTreeItem {
public readonly label: string = localize('bindings', 'Bindings');
public readonly childTypeLabel: string = localize('binding', 'binding');
public readonly parent: FunctionTreeItemBase;
public constructor(parent: FunctionTreeItemBase) {
super(parent);
}
public get contextValue(): string {
return getProjectContextValue(this.parent.parent.parent.source, this.parent.parent.access, ProjectResource.Bindings);
}
public get id(): string {
return 'bindings';
}
public get iconPath(): TreeItemIconPath {
return treeUtils.getThemedIconPath('list-unordered');
}
public hasMoreChildrenImpl(): boolean {
return false;
}
public async loadMoreChildrenImpl(_clearCache: boolean): Promise<BindingTreeItem[]> {
return this.parent.config.bindings.map(b => new BindingTreeItem(this, b));
}
}

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

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as url from 'url';
import { AzExtParentTreeItem, TreeItemIconPath } from 'vscode-azureextensionui';
import { AzExtTreeItem, TreeItemIconPath } from 'vscode-azureextensionui';
import { ParsedFunctionJson } from '../funcConfig/function';
import { IParsedHostJson } from '../funcConfig/host';
import { FuncVersion } from '../FuncVersion';
@ -12,12 +12,13 @@ import { localize } from '../localize';
import { treeUtils } from '../utils/treeUtils';
import { FunctionsTreeItemBase } from './FunctionsTreeItemBase';
import { ApplicationSettings } from './IProjectTreeItem';
import { getProjectContextValue, matchesAnyPart, ProjectResource } from './projectContextValues';
import { getProjectContextValue, ProjectResource } from './projectContextValues';
export abstract class FunctionTreeItemBase extends AzExtParentTreeItem {
export abstract class FunctionTreeItemBase extends AzExtTreeItem {
public readonly parent: FunctionsTreeItemBase;
public readonly config: ParsedFunctionJson;
public readonly name: string;
public readonly commandId: string = 'azureFunctions.viewProperties';
public triggerUrl: string | undefined;
private _disabled: boolean;
@ -78,10 +79,6 @@ export abstract class FunctionTreeItemBase extends AzExtParentTreeItem {
await this.refreshDisabledState();
}
public isAncestorOfImpl(contextValue: string | RegExp): boolean {
return matchesAnyPart(contextValue, ProjectResource.Bindings, ProjectResource.Binding);
}
private async refreshTriggerUrl(): Promise<void> {
const triggerUrl: url.URL = new url.URL(this.parent.parent.hostUrl);

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

@ -191,7 +191,7 @@ export abstract class SlotTreeItemBase extends AzureParentTreeItem<ISiteTreeRoot
if (DeploymentTreeItem.contextValue.test(expectedContextValue)) {
return this.deploymentsNode;
}
} else if (matchesAnyPart(expectedContextValue, ProjectResource.Functions, ProjectResource.Function, ProjectResource.Bindings, ProjectResource.Binding)) {
} else if (matchesAnyPart(expectedContextValue, ProjectResource.Functions, ProjectResource.Function)) {
return this._functionsTreeItem;
}
}

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

@ -1,41 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizard, ICreateChildImplContext } from 'vscode-azureextensionui';
import { createBindingWizard } from '../../commands/addBinding/createBindingWizard';
import { IBindingWizardContext } from '../../commands/addBinding/IBindingWizardContext';
import { ProjectLanguage } from '../../constants';
import { FuncVersion } from '../../FuncVersion';
import { nonNullProp } from '../../utils/nonNull';
import { verifyInitForVSCode } from '../../vsCodeConfig/verifyInitForVSCode';
import { BindingsTreeItem } from '../BindingsTreeItem';
import { BindingTreeItem } from '../BindingTreeItem';
import { LocalFunctionTreeItem } from './LocalFunctionTreeItem';
export class LocalBindingsTreeItem extends BindingsTreeItem {
public readonly parent: LocalFunctionTreeItem;
public constructor(parent: LocalFunctionTreeItem) {
super(parent);
}
public async createChildImpl(context: ICreateChildImplContext): Promise<BindingTreeItem> {
const [language, version]: [ProjectLanguage, FuncVersion] = await verifyInitForVSCode(context, this.parent.parent.parent.projectPath);
const wizardContext: IBindingWizardContext = Object.assign(context, {
functionJsonPath: this.parent.functionJsonPath,
workspacePath: this.parent.parent.parent.workspacePath,
projectPath: this.parent.parent.parent.projectPath,
workspaceFolder: this.parent.parent.parent.workspaceFolder,
language,
version
});
const wizard: AzureWizard<IBindingWizardContext> = createBindingWizard(wizardContext);
await wizard.prompt();
await wizard.execute();
return new BindingTreeItem(this, nonNullProp(wizardContext, 'binding'));
}
}

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

@ -3,22 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzExtTreeItem } from 'vscode-azureextensionui';
import { ParsedFunctionJson } from '../../funcConfig/function';
import { FunctionTreeItemBase } from '../FunctionTreeItemBase';
import { LocalBindingsTreeItem } from './LocalBindingsTreeItem';
import { LocalFunctionsTreeItem } from './LocalFunctionsTreeItem';
export class LocalFunctionTreeItem extends FunctionTreeItemBase {
public readonly parent: LocalFunctionsTreeItem;
public readonly functionJsonPath: string;
private readonly _bindingsNode: LocalBindingsTreeItem;
private constructor(parent: LocalFunctionsTreeItem, name: string, config: ParsedFunctionJson, functionJsonPath: string) {
super(parent, config, name);
this.functionJsonPath = functionJsonPath;
this._bindingsNode = new LocalBindingsTreeItem(this);
}
public static async create(parent: LocalFunctionsTreeItem, name: string, config: ParsedFunctionJson, functionJsonPath: string): Promise<LocalFunctionTreeItem> {
@ -28,18 +23,6 @@ export class LocalFunctionTreeItem extends FunctionTreeItemBase {
return ti;
}
public hasMoreChildrenImpl(): boolean {
return false;
}
public async loadMoreChildrenImpl(_clearCache: boolean): Promise<AzExtTreeItem[]> {
return [this._bindingsNode];
}
public pickTreeItemImpl(): AzExtTreeItem {
return this._bindingsNode;
}
public async getKey(): Promise<string | undefined> {
return undefined;
}

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

@ -80,7 +80,7 @@ export class LocalProjectTreeItem extends AzExtParentTreeItem implements Disposa
public pickTreeItemImpl(expectedContextValues: (string | RegExp)[]): AzExtTreeItem | undefined {
for (const expectedContextValue of expectedContextValues) {
if (matchesAnyPart(expectedContextValue, ProjectResource.Functions, ProjectResource.Function, ProjectResource.Bindings, ProjectResource.Binding)) {
if (matchesAnyPart(expectedContextValue, ProjectResource.Functions, ProjectResource.Function)) {
return this._localFunctionsTreeItem;
}
}

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

@ -19,9 +19,7 @@ export enum ProjectAccess {
export enum ProjectResource {
Functions = 'Functions',
Function = 'Function',
Bindings = 'Bindings',
Binding = 'Binding'
Function = 'Function'
}
export function getProjectContextValue(source: ProjectSource, access: ProjectAccess, resource: ProjectResource, ...parts: string[]): string {

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

@ -6,23 +6,19 @@
import { WebSiteManagementModels } from 'azure-arm-website';
import { ProgressLocation, window } from 'vscode';
import { IFunctionKeys, IHostKeys, ISiteTreeRoot, SiteClient } from 'vscode-azureappservice';
import { AzExtTreeItem, DialogResponses } from 'vscode-azureextensionui';
import { DialogResponses } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { HttpAuthLevel, ParsedFunctionJson } from '../../funcConfig/function';
import { localize } from '../../localize';
import { nonNullProp } from '../../utils/nonNull';
import { BindingsTreeItem } from '../BindingsTreeItem';
import { FunctionTreeItemBase } from '../FunctionTreeItemBase';
import { RemoteFunctionsTreeItem } from './RemoteFunctionsTreeItem';
export class RemoteFunctionTreeItem extends FunctionTreeItemBase {
public readonly parent: RemoteFunctionsTreeItem;
private readonly _bindingsNode: BindingsTreeItem;
private constructor(parent: RemoteFunctionsTreeItem, config: ParsedFunctionJson, name: string) {
super(parent, config, name);
this._bindingsNode = new BindingsTreeItem(this);
}
public static async create(parent: RemoteFunctionsTreeItem, func: WebSiteManagementModels.FunctionEnvelope): Promise<RemoteFunctionTreeItem> {
@ -50,14 +46,6 @@ export class RemoteFunctionTreeItem extends FunctionTreeItemBase {
return `application/functions/function/${encodeURIComponent(this.name)}`;
}
public hasMoreChildrenImpl(): boolean {
return false;
}
public async loadMoreChildrenImpl(_clearCache: boolean): Promise<AzExtTreeItem[]> {
return [this._bindingsNode];
}
public async deleteTreeItemImpl(): Promise<void> {
const message: string = localize('ConfirmDeleteFunction', 'Are you sure you want to delete function "{0}"?', this.name);
const deleting: string = localize('DeletingFunction', 'Deleting function "{0}"...', this.name);

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

@ -46,7 +46,7 @@ suite('Add Binding', async () => {
});
test('Tree', async () => {
const treeItem: AzExtTreeItem | undefined = await ext.tree.findTreeItem(`/localProjecttestWorkspace/functions/${functionName}/bindings`, createTestActionContext());
const treeItem: AzExtTreeItem | undefined = await ext.tree.findTreeItem(`/localProjecttestWorkspace/functions/${functionName}`, createTestActionContext());
assert.ok(treeItem, 'Failed to find tree item');
await validateAddBinding([treeItem], []);
});