Skip to content

Commit

Permalink
Initial migration to v1.5 (#2095)
Browse files Browse the repository at this point in the history
Co-authored-by: motm32 <motm32@gmail.com>
Co-authored-by: Megan Mott <59709511+motm32@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 17, 2023
1 parent 33d9460 commit bff491d
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 67 deletions.
35 changes: 28 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,42 @@
],
"contributes": {
"x-azResources": {
"activation": {
"onResolve": [
"microsoft.documentdb/databaseaccounts",
"microsoft.dbforpostgresql/servers",
"microsoft.dbforpostgresql/flexibleservers"
"azure": {
"branches": [
{
"type": "AzureCosmosDb"
},
{
"type": "PostgresqlServersStandard"
},
{
"type": "PostgresqlServersFlexible"
}
]
},
"workspace": {
"branches": [
{
"type": "ms-azuretools.vscode-cosmosdb"
}
],
"resources": true
},
"commands": [
{
"command": "azureDatabases.createServer",
"title": "Create Database Server...",
"type": "microsoft.documentdb/databaseaccounts",
"detail": "SQL or NoSQL databases for your web apps."
}
]
],
"activation": {
"onResolve": [
"microsoft.documentdb/databaseaccounts",
"microsoft.dbforpostgresql/servers",
"microsoft.dbforpostgresql/flexibleservers"
]
}
},
"languages": [
{
Expand Down Expand Up @@ -475,7 +496,7 @@
"view/item/context": [
{
"command": "azureDatabases.createServer",
"when": "view == azureResourceGroups && viewItem =~ /azureResourceTypeGroup.*(microsoft.documentdb/databaseaccounts|microsoft.dbforpostgresql/(servers|flexibleservers))/",
"when": "view == azureResourceGroups && viewItem =~ /(AzureCosmosDb|PostgreSqlServers(Standard|Flexible))/i && viewItem =~ /azureResourceTypeGroup/i",
"group": "1@1"
},
{
Expand Down
20 changes: 10 additions & 10 deletions src/docdb/registerDocDBCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzExtTreeItem, IActionContext, ITreeItemPickerContext, registerCommand } from "@microsoft/vscode-azext-utils";
import { AzExtTreeItem, IActionContext, ITreeItemPickerContext, registerCommandWithTreeNodeUnwrapping } from "@microsoft/vscode-azext-utils";
import { commands } from "vscode";
import { doubleClickDebounceDelay, sqlFilter } from "../constants";
import { ext } from "../extensionVariables";
Expand All @@ -16,41 +16,41 @@ import { DocDBStoredProceduresTreeItem } from "./tree/DocDBStoredProceduresTreeI
import { DocDBStoredProcedureTreeItem } from "./tree/DocDBStoredProcedureTreeItem";

export function registerDocDBCommands(): void {
registerCommand('cosmosDB.createDocDBDatabase', createDocDBDatabase);
registerCommand('cosmosDB.createDocDBCollection', createDocDBCollection);
registerCommand('cosmosDB.createDocDBDocument', async (context: IActionContext, node?: DocDBDocumentsTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.createDocDBDatabase', createDocDBDatabase);
registerCommandWithTreeNodeUnwrapping('cosmosDB.createDocDBCollection', createDocDBCollection);
registerCommandWithTreeNodeUnwrapping('cosmosDB.createDocDBDocument', async (context: IActionContext, node?: DocDBDocumentsTreeItem) => {
if (!node) {
node = await pickDocDBAccount<DocDBDocumentsTreeItem>(context, DocDBDocumentsTreeItem.contextValue);
}
const documentNode = <DocDBDocumentTreeItem>await node.createChild(context);
await commands.executeCommand("cosmosDB.openDocument", documentNode);

});
registerCommand('cosmosDB.createDocDBStoredProcedure', async (context: IActionContext, node?: DocDBStoredProceduresTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.createDocDBStoredProcedure', async (context: IActionContext, node?: DocDBStoredProceduresTreeItem) => {
if (!node) {
node = await pickDocDBAccount<DocDBStoredProceduresTreeItem>(context, DocDBStoredProceduresTreeItem.contextValue);
}
const childNode = await node.createChild(context);
await commands.executeCommand("cosmosDB.openStoredProcedure", childNode);

});
registerCommand('cosmosDB.deleteDocDBDatabase', deleteDocDBDatabase);
registerCommand('cosmosDB.deleteDocDBCollection', deleteDocDBCollection);
registerCommand('cosmosDB.openStoredProcedure', async (context: IActionContext, node?: DocDBStoredProcedureTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteDocDBDatabase', deleteDocDBDatabase);
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteDocDBCollection', deleteDocDBCollection);
registerCommandWithTreeNodeUnwrapping('cosmosDB.openStoredProcedure', async (context: IActionContext, node?: DocDBStoredProcedureTreeItem) => {
if (!node) {
node = await pickDocDBAccount<DocDBStoredProcedureTreeItem>(context, DocDBStoredProcedureTreeItem.contextValue);
}
await ext.fileSystem.showTextDocument(node);
}, doubleClickDebounceDelay);
registerCommand('cosmosDB.deleteDocDBDocument', async (context: IActionContext, node?: DocDBDocumentTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteDocDBDocument', async (context: IActionContext, node?: DocDBDocumentTreeItem) => {
const suppressCreateContext: ITreeItemPickerContext = context;
suppressCreateContext.suppressCreatePick = true;
if (!node) {
node = await pickDocDBAccount<DocDBDocumentTreeItem>(context, DocDBDocumentTreeItem.contextValue);
}
await node.deleteTreeItem(context);
});
registerCommand('cosmosDB.deleteDocDBStoredProcedure', async (context: IActionContext, node?: DocDBStoredProcedureTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteDocDBStoredProcedure', async (context: IActionContext, node?: DocDBStoredProcedureTreeItem) => {
const suppressCreateContext: ITreeItemPickerContext = context;
suppressCreateContext.suppressCreatePick = true;
if (!node) {
Expand Down
32 changes: 17 additions & 15 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

import { registerAzureUtilsExtensionVariables } from '@microsoft/vscode-azext-azureutils';
import { AzExtParentTreeItem, AzExtTreeItem, callWithTelemetryAndErrorHandling, createApiProvider, createAzExtOutputChannel, IActionContext, ITreeItemPickerContext, registerCommand, registerErrorHandler, registerEvent, registerReportIssueCommand, registerUIExtensionVariables } from '@microsoft/vscode-azext-utils';
import { AzExtParentTreeItem, AzExtResourceType, AzExtTreeItem, callWithTelemetryAndErrorHandling, createApiProvider, createAzExtOutputChannel, IActionContext, ITreeItemPickerContext, registerCommandWithTreeNodeUnwrapping, registerErrorHandler, registerEvent, registerReportIssueCommand, registerUIExtensionVariables } from '@microsoft/vscode-azext-utils';
import { AzureExtensionApi, AzureExtensionApiProvider } from '@microsoft/vscode-azext-utils/api';
import { platform } from 'os';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -58,11 +58,13 @@ export async function activateInternal(context: vscode.ExtensionContext, perfSta
ext.keytar = tryGetKeyTar();

ext.rgApi = await getResourceGroupsApi();
ext.rgApi.registerApplicationResourceResolver('ms-azuretools.vscode-cosmosdb', new DatabaseResolver());
ext.rgApi.registerApplicationResourceResolver(AzExtResourceType.AzureCosmosDb, new DatabaseResolver());
ext.rgApi.registerApplicationResourceResolver(AzExtResourceType.PostgresqlServersStandard, new DatabaseResolver());
ext.rgApi.registerApplicationResourceResolver(AzExtResourceType.PostgresqlServersFlexible, new DatabaseResolver());

const workspaceRootTreeItem = (ext.rgApi.workspaceResourceTree as unknown as { _rootTreeItem: AzExtParentTreeItem })._rootTreeItem;
const databaseWorkspaceProvider = new DatabaseWorkspaceProvider(workspaceRootTreeItem);
ext.rgApi.registerWorkspaceResourceProvider('ms-azuretools.vscode-cosmosdb', databaseWorkspaceProvider);
ext.rgApi.registerWorkspaceResourceProvider('AttachedDatabaseAccount', databaseWorkspaceProvider);

ext.fileSystem = new DatabasesFileSystem(ext.rgApi.appResourceTree);

Expand All @@ -73,15 +75,15 @@ export async function activateInternal(context: vscode.ExtensionContext, perfSta

context.subscriptions.push(vscode.workspace.registerFileSystemProvider(DatabasesFileSystem.scheme, ext.fileSystem));

registerCommand('cosmosDB.selectSubscriptions', () => vscode.commands.executeCommand("azure-account.selectSubscriptions"));
registerCommandWithTreeNodeUnwrapping('cosmosDB.selectSubscriptions', () => vscode.commands.executeCommand("azure-account.selectSubscriptions"));

registerCommand('azureDatabases.createServer', createServer);
registerCommand('cosmosDB.deleteAccount', deleteAccount);
registerCommand('cosmosDB.attachDatabaseAccount', async (actionContext: IActionContext) => {
registerCommandWithTreeNodeUnwrapping('azureDatabases.createServer', createServer);
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteAccount', deleteAccount);
registerCommandWithTreeNodeUnwrapping('cosmosDB.attachDatabaseAccount', async (actionContext: IActionContext) => {
await ext.attachedAccountsNode.attachNewAccount(actionContext);
await ext.rgApi.workspaceResourceTree.refresh(actionContext, ext.attachedAccountsNode);
});
registerCommand('cosmosDB.attachEmulator', async (actionContext: IActionContext) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.attachEmulator', async (actionContext: IActionContext) => {
if (platform() !== 'win32') {
actionContext.errorHandling.suppressReportIssue = true;
throw new Error(localize('emulatorNotSupported', 'The Cosmos DB emulator is only supported on Windows.'));
Expand All @@ -90,15 +92,15 @@ export async function activateInternal(context: vscode.ExtensionContext, perfSta
await ext.attachedAccountsNode.attachEmulator(actionContext);
await ext.rgApi.workspaceResourceTree.refresh(actionContext, ext.attachedAccountsNode);
});
registerCommand('azureDatabases.refresh', async (actionContext: IActionContext, node?: AzExtTreeItem) => {
registerCommandWithTreeNodeUnwrapping('azureDatabases.refresh', async (actionContext: IActionContext, node?: AzExtTreeItem) => {
if (node) {
await node.refresh(actionContext);
} else {
await ext.rgApi.appResourceTree.refresh(actionContext, node);
}
});

registerCommand('azureDatabases.detachDatabaseAccount', async (actionContext: IActionContext & ITreeItemPickerContext, node?: AzExtTreeItem) => {
registerCommandWithTreeNodeUnwrapping('azureDatabases.detachDatabaseAccount', async (actionContext: IActionContext & ITreeItemPickerContext, node?: AzExtTreeItem) => {
const children = await ext.attachedAccountsNode.loadAllChildren(actionContext);
if (children[0].contextValue === "cosmosDBAttachDatabaseAccount") {
const message = localize('noAttachedAccounts', 'There are no Attached Accounts.');
Expand All @@ -117,15 +119,15 @@ export async function activateInternal(context: vscode.ExtensionContext, perfSta
await ext.rgApi.workspaceResourceTree.refresh(actionContext, ext.attachedAccountsNode);
}
});
registerCommand('cosmosDB.importDocument', async (actionContext: IActionContext, selectedNode: vscode.Uri | MongoCollectionTreeItem | DocDBCollectionTreeItem, uris: vscode.Uri[]) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.importDocument', async (actionContext: IActionContext, selectedNode: vscode.Uri | MongoCollectionTreeItem | DocDBCollectionTreeItem, uris: vscode.Uri[]) => {
if (selectedNode instanceof vscode.Uri) {
await importDocuments(actionContext, uris || [selectedNode], undefined);
} else {
await importDocuments(actionContext, undefined, selectedNode);
}
});
registerCommand('cosmosDB.copyConnectionString', cosmosDBCopyConnectionString);
registerCommand('cosmosDB.openDocument', async (actionContext: IActionContext, node?: MongoDocumentTreeItem | DocDBDocumentTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.copyConnectionString', cosmosDBCopyConnectionString);
registerCommandWithTreeNodeUnwrapping('cosmosDB.openDocument', async (actionContext: IActionContext, node?: MongoDocumentTreeItem | DocDBDocumentTreeItem) => {
if (!node) {
node = await ext.rgApi.pickAppResource<MongoDocumentTreeItem | DocDBDocumentTreeItem>(actionContext, {
filter: [
Expand All @@ -140,8 +142,8 @@ export async function activateInternal(context: vscode.ExtensionContext, perfSta
ext.fileSystem.fireChangedEvent(node);
await ext.fileSystem.showTextDocument(node);
}, doubleClickDebounceDelay);
registerCommand('azureDatabases.update', async (_actionContext: IActionContext, uri: vscode.Uri) => await ext.fileSystem.updateWithoutPrompt(uri));
registerCommand('azureDatabases.loadMore', async (actionContext: IActionContext, node: AzExtTreeItem) => await ext.rgApi.appResourceTree.loadMore(node, actionContext));
registerCommandWithTreeNodeUnwrapping('azureDatabases.update', async (_actionContext: IActionContext, uri: vscode.Uri) => await ext.fileSystem.updateWithoutPrompt(uri));
registerCommandWithTreeNodeUnwrapping('azureDatabases.loadMore', async (actionContext: IActionContext, node: AzExtTreeItem) => await ext.rgApi.appResourceTree.loadMore(node, actionContext));
registerEvent(
'cosmosDB.onDidChangeConfiguration',
vscode.workspace.onDidChangeConfiguration,
Expand Down
12 changes: 6 additions & 6 deletions src/graph/registerGraphCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzExtTreeItem, IActionContext, ITreeItemPickerContext, registerCommand } from "@microsoft/vscode-azext-utils";
import { AzExtTreeItem, IActionContext, ITreeItemPickerContext, registerCommandWithTreeNodeUnwrapping } from "@microsoft/vscode-azext-utils";
import { cosmosGremlinFilter, doubleClickDebounceDelay } from '../constants';
import { ext } from '../extensionVariables';
import { GraphAccountTreeItem } from "./tree/GraphAccountTreeItem";
Expand All @@ -12,25 +12,25 @@ import { GraphDatabaseTreeItem } from "./tree/GraphDatabaseTreeItem";
import { GraphTreeItem } from "./tree/GraphTreeItem";

export function registerGraphCommands(): void {
registerCommand('cosmosDB.createGraphDatabase', createGraphDatabase);
registerCommand('cosmosDB.createGraph', createGraph);
registerCommand('cosmosDB.deleteGraphDatabase', async (context: IActionContext, node?: GraphDatabaseTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.createGraphDatabase', createGraphDatabase);
registerCommandWithTreeNodeUnwrapping('cosmosDB.createGraph', createGraph);
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteGraphDatabase', async (context: IActionContext, node?: GraphDatabaseTreeItem) => {
const suppressCreateContext: ITreeItemPickerContext = context;
suppressCreateContext.suppressCreatePick = true;
if (!node) {
node = await pickGraph<GraphDatabaseTreeItem>(context, GraphDatabaseTreeItem.contextValue);
}
await node.deleteTreeItem(context);
});
registerCommand('cosmosDB.deleteGraph', async (context: IActionContext, node?: GraphCollectionTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.deleteGraph', async (context: IActionContext, node?: GraphCollectionTreeItem) => {
const suppressCreateContext: ITreeItemPickerContext = context;
suppressCreateContext.suppressCreatePick = true;
if (!node) {
node = await pickGraph<GraphCollectionTreeItem>(context, GraphCollectionTreeItem.contextValue);
}
await node.deleteTreeItem(context);
});
registerCommand('cosmosDB.openGraphExplorer', async (context: IActionContext, node: GraphTreeItem) => {
registerCommandWithTreeNodeUnwrapping('cosmosDB.openGraphExplorer', async (context: IActionContext, node: GraphTreeItem) => {
if (!node) {
node = await pickGraph<GraphTreeItem>(context, GraphTreeItem.contextValue);
}
Expand Down
Loading

0 comments on commit bff491d

Please sign in to comment.