Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: suggest use and db commands VSCODE-380 #491

Merged
merged 2 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/connectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default class ConnectionController {
} catch (error) {
// Here we're lenient when loading connections in case their
// connections have become corrupted.
log.error(`Connection migration failed: ${formatError(error).message}`);
log.error('Migrating previously saved connections failed', error);
return;
}
}
Expand All @@ -164,7 +164,7 @@ export default class ConnectionController {
// Return saved connection as it is.
if (!ext.keytarModule) {
log.error(
'Load saved connections failed: VSCode extension keytar module is undefined.'
'Getting connection info with secrets failed because VSCode extension keytar module is undefined'
);
return savedConnectionInfo as StoreConnectionInfoWithConnectionOptions;
}
Expand Down Expand Up @@ -197,9 +197,7 @@ export default class ConnectionController {
} catch (error) {
// Here we're lenient when loading connections in case their
// connections have become corrupted.
log.error(
`Merging connection with secrets failed: ${formatError(error).message}`
);
log.error('Getting connection info with secrets failed', error);
return;
}
}
Expand Down Expand Up @@ -301,7 +299,7 @@ export default class ConnectionController {
async addNewConnectionStringAndConnect(
connectionString: string
): Promise<boolean> {
log.info('Trying to connect to a new connection configuration');
log.info('Trying to connect to a new connection configuration...');

const connectionStringData = new ConnectionString(connectionString);

Expand All @@ -313,7 +311,7 @@ export default class ConnectionController {
);

try {
const connectResult = await this.saveNewConnectionAndConnect(
const connectResult = await this.saveNewConnectionFromFormAndConnect(
{
id: uuidv4(),
connectionOptions: {
Expand All @@ -326,11 +324,10 @@ export default class ConnectionController {
return connectResult.successfullyConnected;
} catch (error) {
const printableError = formatError(error);
log.error('Failed to connect', printableError);
log.error('Failed to connect with a connection string', error);
void vscode.window.showErrorMessage(
`Unable to connect: ${printableError.message}`
);

return false;
}
}
Expand Down Expand Up @@ -391,7 +388,7 @@ export default class ConnectionController {
return savedConnectionInfo;
}

async saveNewConnectionAndConnect(
async saveNewConnectionFromFormAndConnect(
originalConnectionInfo: ConnectionInfo,
connectionType: ConnectionTypes
): Promise<ConnectionAttemptResult> {
Expand All @@ -412,9 +409,7 @@ export default class ConnectionController {
connectionOptions: originalConnectionInfo.connectionOptions, // The connection options with secrets.
};

log.info(
`Connect called to connect to instance: ${savedConnectionInfo.name}`
);
log.info('Connect called to connect to instance', savedConnectionInfo.name);

return this._connect(savedConnectionInfo.id, connectionType);
}
Expand Down Expand Up @@ -539,19 +534,18 @@ export default class ConnectionController {

return true;
} catch (error) {
log.error('Failed to connect by a connection id', error);
const printableError = formatError(error);
log.error('Failed to connect', printableError);
void vscode.window.showErrorMessage(
`Unable to connect: ${printableError.message}`
);

return false;
}
}

async disconnect(): Promise<boolean> {
log.info(
'Disconnect called, currently connected to:',
'Disconnect called, currently connected to',
this._currentConnectionId
);

Expand Down
8 changes: 2 additions & 6 deletions src/editors/editorsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ export default class EditorsController {
codeActionProvider: PlaygroundSelectedCodeActionProvider,
editDocumentCodeLensProvider: EditDocumentCodeLensProvider
) {
log.info('activating...');

this._connectionController = connectionController;
this._playgroundController = playgroundController;
this._context = context;
Expand Down Expand Up @@ -152,8 +150,6 @@ export default class EditorsController {

this._documentIdStore.removeByDocumentIdReference(documentIdReference);
});

log.info('activated.');
}

async openMongoDBDocument(data: EditDocumentInfo): Promise<boolean> {
Expand Down Expand Up @@ -262,7 +258,7 @@ export default class EditorsController {
}

async onViewCollectionDocuments(namespace: string): Promise<boolean> {
log.info('view collection documents', namespace);
log.info('View collection documents', namespace);

const operationId =
this._collectionDocumentsOperationsStore.createNewOperation();
Expand Down Expand Up @@ -294,7 +290,7 @@ export default class EditorsController {
connectionId: string,
namespace: string
): Promise<boolean> {
log.info('view more collection documents', namespace);
log.info('View more collection documents', namespace);

// A user might click to fetch more documents multiple times,
// this ensures it only performs one fetch at a time.
Expand Down
4 changes: 2 additions & 2 deletions src/editors/mongoDBDocumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class MongoDBDocumentService {
newDocument: EJSON.SerializableTypes;
source: DocumentSource;
}): Promise<void> {
log.info('replace document in MongoDB', data);
log.info('Replace document in MongoDB', data);

const { documentId, namespace, connectionId, newDocument, source } = data;
const activeConnectionId =
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class MongoDBDocumentService {
async fetchDocument(
data: EditDocumentInfo
): Promise<EJSON.SerializableTypes | void> {
log.info('fetch document from MongoDB', data);
log.info('Fetch document from MongoDB', data);

const { documentId, namespace, connectionId } = data;
const activeConnectionId =
Expand Down
11 changes: 7 additions & 4 deletions src/editors/playgroundController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export default class PlaygroundController {

return progressResult;
} catch (error) {
log.error('Evaluate playground with cancel modal error', error);
log.error('Evaluating playground with cancel modal failed', error);

return {
outputLines: undefined,
Expand Down Expand Up @@ -752,7 +752,7 @@ export default class PlaygroundController {
const { selectedText, importStatements, driverSyntax, builders, language } =
this._exportToLanguageCodeLensProvider._exportToLanguageAddons;

log.info(`Start export to ${language} language`);
log.info(`Exporting to the '${language}' language...`);

try {
const transpiledContent = await this.getTranspiledContent();
Expand Down Expand Up @@ -782,7 +782,10 @@ export default class PlaygroundController {
language,
};

log.info(`Export to ${language} language result`, this._playgroundResult);
log.info(
`Exported to the '${language}' language`,
this._playgroundResult
);

/* eslint-disable camelcase */
if (
Expand Down Expand Up @@ -817,8 +820,8 @@ export default class PlaygroundController {

await this._openPlaygroundResult();
} catch (error) {
log.error(`Export to the '${language}' language failed`, error);
const printableError = formatError(error);
log.error(`Export to ${language} language error`, printableError);
void vscode.window.showErrorMessage(
`Unable to export to ${language} language: ${printableError.message}`
);
Expand Down
6 changes: 4 additions & 2 deletions src/explorer/documentListTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TreeItemParent from './treeItemParentInterface';
import type { DataService } from 'mongodb-data-service';

const path = require('path');
const log = createLogger('tree view document list');
const log = createLogger('documents tree item');

// We fetch 1 more than this in order to see if there are more to fetch.
// Each time `show more` is clicked, the collection item increases the amount
Expand Down Expand Up @@ -244,7 +244,9 @@ export default class DocumentListTreeItem
}

onShowMoreClicked(): void {
log.info('show more clicked');
log.info(
`Show more documents clicked for the '${this.namespace}' namespace`
);

this._maxDocumentsToShow += MAX_DOCUMENTS_VISIBLE;
this.cacheIsUpToDate = false;
Expand Down
4 changes: 2 additions & 2 deletions src/explorer/explorerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export default class ExplorerController {
private _treeView?: vscode.TreeView<vscode.TreeItem>;

constructor(connectionController: ConnectionController) {
log.info('activate explorer controller');

this._connectionController = connectionController;
this._treeController = new ExplorerTreeController(connectionController);
}
Expand All @@ -40,12 +38,14 @@ export default class ExplorerController {
};

activateConnectionsTreeView(): void {
log.info('Activating explorer controller...');
// Listen for a change in connections to occur before we create the tree
// so that we show the `viewsWelcome` before any connections are added.
this._connectionController.addEventListener(
DataServiceEventTypes.CONNECTIONS_DID_CHANGE,
this.createTreeView
);
log.info('Explorer controller activated');
}

deactivate(): void {
Expand Down
6 changes: 3 additions & 3 deletions src/explorer/explorerTreeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DOCUMENT_LIST_ITEM, CollectionTypes } from './documentListTreeItem';
import EXTENSION_COMMANDS from '../commands';
import { sortTreeItemsByLabel } from './treeItemUtils';

const log = createLogger('explorer controller');
const log = createLogger('explorer tree controller');

export default class ExplorerTreeController
implements vscode.TreeDataProvider<vscode.TreeItem>
Expand Down Expand Up @@ -48,7 +48,7 @@ export default class ExplorerTreeController
treeView: vscode.TreeView<vscode.TreeItem>
): void => {
treeView.onDidCollapseElement((event: any) => {
log.info('Tree item was collapsed:', event.element.label);
log.info('Tree item was collapsed', event.element.label);

if (event.element.onDidCollapse) {
event.element.onDidCollapse();
Expand All @@ -64,7 +64,7 @@ export default class ExplorerTreeController
});

treeView.onDidExpandElement(async (event: any): Promise<void> => {
log.info('Tree item was expanded:', event.element.label);
log.info('Tree item was expanded', event.element.label);

if (!event.element.onDidExpand) {
return;
Expand Down
5 changes: 3 additions & 2 deletions src/explorer/helpExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ import HelpTree from './helpTree';
import { createLogger } from '../logging';
import { TelemetryService } from '../telemetry';

const log = createLogger('help and info explorer controller');
const log = createLogger('help and info explorer');

export default class HelpExplorer {
_treeController: HelpTree;
_treeView?: vscode.TreeView<vscode.TreeItem>;

constructor() {
log.info('activate help explorer');
this._treeController = new HelpTree();
}

activateHelpTreeView(telemetryService: TelemetryService): void {
if (!this._treeView) {
log.info('Activating help explorer...');
this._treeView = vscode.window.createTreeView('mongoDBHelpExplorer', {
treeDataProvider: this._treeController,
});
this._treeController.activateTreeViewEventHandlers(
this._treeView,
telemetryService
);
log.info('Help explorer activated');
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/explorer/playgroundsExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import * as vscode from 'vscode';
import PlaygroundsTree from './playgroundsTree';
import { createLogger } from '../logging';

const log = createLogger('explorer controller');
const log = createLogger('playgrounds explorer');

export default class PlaygroundsExplorer {
private _treeController: PlaygroundsTree;
private _treeView?: vscode.TreeView<vscode.TreeItem>;

constructor() {
log.info('activate playgrounds explorer');
this._treeController = new PlaygroundsTree();
}

Expand All @@ -26,7 +25,9 @@ export default class PlaygroundsExplorer {
};

public activatePlaygroundsTreeView(): void {
log.info('Activating playgrounds explorer...');
this.createPlaygroundsTreeView();
log.info('Playgrounds explorer activated');
}

public deactivate(): void {
Expand Down
6 changes: 3 additions & 3 deletions src/explorer/playgroundsTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PlaygroundsTreeItem from './playgroundsTreeItem';
import EXTENSION_COMMANDS from '../commands';
import { getPlaygrounds } from '../utils/playground';

const log = createLogger('playgrounds tree controller');
const log = createLogger('playgrounds tree');

export default class PlaygroundsTree
implements vscode.TreeDataProvider<vscode.TreeItem>
Expand Down Expand Up @@ -34,7 +34,7 @@ export default class PlaygroundsTree
treeView: vscode.TreeView<vscode.TreeItem>
): void => {
treeView.onDidCollapseElement((event: any) => {
log.info('Tree item was collapsed:', event.element.label);
log.info('Tree item was collapsed', event.element.label);

if (event.element.onDidCollapse) {
event.element.onDidCollapse();
Expand All @@ -50,7 +50,7 @@ export default class PlaygroundsTree
});

treeView.onDidExpandElement(async (event: any): Promise<void> => {
log.info('Tree item was expanded:', event.element.label);
log.info('Tree item was expanded', event.element.label);

if (!event.element.onDidExpand) {
return;
Expand Down
7 changes: 3 additions & 4 deletions src/explorer/schemaTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TreeItemParent from './treeItemParentInterface';
import { MAX_DOCUMENTS_VISIBLE } from './documentListTreeItem';
import { DataService } from 'mongodb-data-service';

const log = createLogger('tree view document list');
const log = createLogger('schema tree item');

const ITEM_LABEL = 'Schema';

Expand Down Expand Up @@ -114,7 +114,7 @@ export default class SchemaTreeItem
return;
}

log.info(`parsing schema for namespace ${namespace}`);
log.info(`Parsing schema for the '${namespace}' namespace...`);
if (!documents || documents.length === 0) {
return;
}
Expand Down Expand Up @@ -224,9 +224,8 @@ export default class SchemaTreeItem

onShowMoreClicked(): void {
log.info(
`show more schema fields clicked for namespace ${this.databaseName}.${this.collectionName}`
`Show more schema fields clicked for the ${this.databaseName}.${this.collectionName} namespace`
);

this.cacheIsUpToDate = false;
this.hasClickedShowMoreFields = true;
}
Expand Down
Loading