export function registerMongoCommands()

in src/mongo/registerMongoCommands.ts [26:95]


export function registerMongoCommands(): void {
    ext.mongoLanguageClient = new MongoDBLanguageClient();

    ext.mongoCodeLensProvider = new MongoCodeLensProvider();
    ext.context.subscriptions.push(vscode.languages.registerCodeLensProvider(mongoLanguageId, ext.mongoCodeLensProvider));

    diagnosticsCollection = vscode.languages.createDiagnosticCollection('cosmosDB.mongo');
    ext.context.subscriptions.push(diagnosticsCollection);

    setUpErrorReporting();

    const loadPersistedMongoDBTask: Promise<void> = loadPersistedMongoDB();

    registerCommand('cosmosDB.createMongoDatabase', createMongoDatabase);
    registerCommand('cosmosDB.createMongoCollection', createMongoCollection);
    registerCommand('cosmosDB.createMongoDocument', async (context: IActionContext, node?: MongoCollectionTreeItem) => {
        if (!node) {
            node = <MongoCollectionTreeItem>await ext.tree.showTreeItemPicker(MongoCollectionTreeItem.contextValue, context);
        }
        const documentNode = await node.createChild(context);
        await vscode.commands.executeCommand("cosmosDB.openDocument", documentNode);
    });
    registerCommand('cosmosDB.connectMongoDB', async (context: IActionContext, node?: MongoDatabaseTreeItem) => {
        if (!node) {
            // Include defaultExperience in the context to prevent https://github.com/microsoft/vscode-cosmosdb/issues/1517
            const experienceContext: ITreeItemPickerContext & { defaultExperience?: Experience } = { ...context, defaultExperience: MongoExperience };
            node = <MongoDatabaseTreeItem>await ext.tree.showTreeItemPicker(MongoDatabaseTreeItem.contextValue, experienceContext);
        }

        const oldNodeId: string | undefined = ext.connectedMongoDB && ext.connectedMongoDB.fullId;
        await ext.mongoLanguageClient.connect(node.connectionString, node.databaseName);
        void ext.context.globalState.update(connectedMongoKey, node.fullId);
        setConnectedNode(node);
        await node.refresh(context);

        if (oldNodeId) {
            // We have to use findTreeItem to get the instance of the old node that's being displayed in the ext.tree. Our specific instance might have been out-of-date
            const oldNode: AzExtTreeItem | undefined = await ext.tree.findTreeItem(oldNodeId, context);
            if (oldNode) {
                await oldNode.refresh(context);
            }
        }
    });
    registerCommand('cosmosDB.deleteMongoDB', deleteMongoDB);
    registerCommand('cosmosDB.deleteMongoCollection', deleteMongoCollection);
    registerCommand('cosmosDB.deleteMongoDocument', async (context: IActionContext, node?: MongoDocumentTreeItem) => {
        const suppressCreateContext: ITreeItemPickerContext = context;
        suppressCreateContext.suppressCreatePick = true;
        if (!node) {
            node = <MongoDocumentTreeItem>await ext.tree.showTreeItemPicker(MongoDocumentTreeItem.contextValue, context);
        }
        await node.deleteTreeItem(context);
    });
    registerCommand('cosmosDB.openCollection', async (context: IActionContext, node?: MongoCollectionTreeItem) => {
        if (!node) {
            node = <MongoCollectionTreeItem>await ext.tree.showTreeItemPicker(MongoCollectionTreeItem.contextValue, context);
        }
        await ext.fileSystem.showTextDocument(node);
    });
    registerCommand('cosmosDB.launchMongoShell', launchMongoShell);
    registerCommand('cosmosDB.newMongoScrapbook', async () => await vscodeUtil.showNewFile('', 'Scrapbook', '.mongo'));
    registerCommand('cosmosDB.executeMongoCommand', async (context: IActionContext, position?: vscode.Position) => {
        await loadPersistedMongoDBTask;
        await executeCommandFromActiveEditor(context, position);
    });
    registerCommand('cosmosDB.executeAllMongoCommands', async (context: IActionContext) => {
        await loadPersistedMongoDBTask;
        await executeAllCommandsFromActiveEditor(context);
    });
}