Skip to content

Commit

Permalink
chore: sync with main 26 08 (#791)
Browse files Browse the repository at this point in the history
* chore(testing): use source map support, improve test cleanup error handling VSCODE-593 (#784)

* feat: show survey VSCODE-562 (#780)


---------

Co-authored-by: Rhys <[email protected]>
Co-authored-by: Rhys Howell <[email protected]>

* fix: add telemetry events for survey VSCODE-595 (#787)

* fix(editors): don't show connect code lens on regular js files VSCODE-538 (#789)

---------

Co-authored-by: Rhys <[email protected]>
Co-authored-by: Paula Stachova <[email protected]>
Co-authored-by: Rhys Howell <[email protected]>
  • Loading branch information
4 people authored Aug 26, 2024
1 parent 934e830 commit 16277cb
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 79 deletions.
4 changes: 4 additions & 0 deletions src/connectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ export default class ConnectionController {
this.eventEmitter.removeListener(eventType, listener);
}

deactivate() {
this.eventEmitter.removeAllListeners();
}

closeConnectionStringInput() {
this._connectionStringInputCancellationToken?.cancel();
}
Expand Down
36 changes: 19 additions & 17 deletions src/editors/activeConnectionCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
import * as vscode from 'vscode';
import type { TextEditor } from 'vscode';

import EXTENSION_COMMANDS from '../commands';
import type ConnectionController from '../connectionController';
import { isPlayground } from '../utils/playground';
import { getDBFromConnectionString } from '../utils/connection-string-db';
import { DataServiceEventTypes } from '../connectionController';

export default class ActiveConnectionCodeLensProvider
implements vscode.CodeLensProvider
{
_connectionController: ConnectionController;
_onDidChangeCodeLenses: vscode.EventEmitter<void> =
new vscode.EventEmitter<void>();
activeTextEditor?: TextEditor;
_activeConnectionChangedHandler: () => void;

readonly onDidChangeCodeLenses: vscode.Event<void> =
this._onDidChangeCodeLenses.event;

constructor(connectionController: ConnectionController) {
this._connectionController = connectionController;
this.activeTextEditor = vscode.window.activeTextEditor;

vscode.workspace.onDidChangeConfiguration(() => {
this._onDidChangeCodeLenses.fire();
});
}

setActiveTextEditor(activeTextEditor?: TextEditor) {
this.activeTextEditor = activeTextEditor;
this._onDidChangeCodeLenses.fire();
}

refresh(): void {
this._onDidChangeCodeLenses.fire();
}

isPlayground(): boolean {
return isPlayground(this.activeTextEditor?.document.uri);
this._activeConnectionChangedHandler = () => {
this._onDidChangeCodeLenses.fire();
};
this._connectionController.addEventListener(
DataServiceEventTypes.ACTIVE_CONNECTION_CHANGED,
this._activeConnectionChangedHandler
);
}

provideCodeLenses(): vscode.CodeLens[] {
if (!this.isPlayground()) {
provideCodeLenses(document: vscode.TextDocument): vscode.CodeLens[] {
if (!isPlayground(document.uri)) {
return [];
}

Expand Down Expand Up @@ -69,4 +64,11 @@ export default class ActiveConnectionCodeLensProvider

return [codeLens];
}

deactivate() {
this._connectionController.removeEventListener(
DataServiceEventTypes.ACTIVE_CONNECTION_CHANGED,
this._activeConnectionChangedHandler
);
}
}
22 changes: 6 additions & 16 deletions src/editors/playgroundController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import vm from 'vm';
import os from 'os';
import transpiler from 'bson-transpilers';

import type ActiveConnectionCodeLensProvider from './activeConnectionCodeLensProvider';
import type PlaygroundSelectedCodeActionProvider from './playgroundSelectedCodeActionProvider';
import type ConnectionController from '../connectionController';
import { DataServiceEventTypes } from '../connectionController';
Expand Down Expand Up @@ -129,12 +128,12 @@ export default class PlaygroundController {

_isPartialRun = false;

private _activeConnectionCodeLensProvider: ActiveConnectionCodeLensProvider;
private _playgroundResultViewColumn?: vscode.ViewColumn;
private _playgroundResultTextDocument?: vscode.TextDocument;
private _statusView: StatusView;
private _playgroundResultViewProvider: PlaygroundResultProvider;
private _participantController: ParticipantController;
private _activeConnectionChangedHandler: () => void;

private _codeToEvaluate = '';

Expand All @@ -144,7 +143,6 @@ export default class PlaygroundController {
telemetryService,
statusView,
playgroundResultViewProvider,
activeConnectionCodeLensProvider,
exportToLanguageCodeLensProvider,
playgroundSelectedCodeActionProvider,
participantController,
Expand All @@ -154,7 +152,6 @@ export default class PlaygroundController {
telemetryService: TelemetryService;
statusView: StatusView;
playgroundResultViewProvider: PlaygroundResultProvider;
activeConnectionCodeLensProvider: ActiveConnectionCodeLensProvider;
exportToLanguageCodeLensProvider: ExportToLanguageCodeLensProvider;
playgroundSelectedCodeActionProvider: PlaygroundSelectedCodeActionProvider;
participantController: ParticipantController;
Expand All @@ -165,17 +162,17 @@ export default class PlaygroundController {
this._telemetryService = telemetryService;
this._statusView = statusView;
this._playgroundResultViewProvider = playgroundResultViewProvider;
this._activeConnectionCodeLensProvider = activeConnectionCodeLensProvider;
this._exportToLanguageCodeLensProvider = exportToLanguageCodeLensProvider;
this._playgroundSelectedCodeActionProvider =
playgroundSelectedCodeActionProvider;
this._participantController = participantController;

this._activeConnectionChangedHandler = () => {
void this._activeConnectionChanged();
};
this._connectionController.addEventListener(
DataServiceEventTypes.ACTIVE_CONNECTION_CHANGED,
() => {
void this._activeConnectionChanged();
}
this._activeConnectionChangedHandler
);

const onDidChangeActiveTextEditor = (
Expand All @@ -195,9 +192,6 @@ export default class PlaygroundController {

if (isPlaygroundEditor) {
this._activeTextEditor = editor;
this._activeConnectionCodeLensProvider.setActiveTextEditor(
this._activeTextEditor
);
this._playgroundSelectedCodeActionProvider.setActiveTextEditor(
this._activeTextEditor
);
Expand Down Expand Up @@ -276,8 +270,6 @@ export default class PlaygroundController {
const connectionId = this._connectionController.getActiveConnectionId();
let mongoClientOption;

this._activeConnectionCodeLensProvider.refresh();

if (dataService && connectionId) {
mongoClientOption =
this._connectionController.getMongoClientConnectionOptions();
Expand Down Expand Up @@ -919,9 +911,7 @@ export default class PlaygroundController {
deactivate(): void {
this._connectionController.removeEventListener(
DataServiceEventTypes.ACTIVE_CONNECTION_CHANGED,
() => {
// No action is required after removing the listener.
}
this._activeConnectionChangedHandler
);
}
}
53 changes: 51 additions & 2 deletions src/mdbExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import launchMongoShell from './commands/launchMongoShell';
import type SchemaTreeItem from './explorer/schemaTreeItem';
import { StatusView } from './views';
import { StorageController, StorageVariables } from './storage';
import TelemetryService from './telemetry/telemetryService';
import TelemetryService, {
TelemetryEventTypes,
} from './telemetry/telemetryService';
import type PlaygroundsTreeItem from './explorer/playgroundsTreeItem';
import PlaygroundResultProvider from './editors/playgroundResultProvider';
import WebviewController from './views/webviewController';
Expand Down Expand Up @@ -117,7 +119,6 @@ export default class MDBExtensionController implements vscode.Disposable {
telemetryService: this._telemetryService,
statusView: this._statusView,
playgroundResultViewProvider: this._playgroundResultViewProvider,
activeConnectionCodeLensProvider: this._activeConnectionCodeLensProvider,
exportToLanguageCodeLensProvider: this._exportToLanguageCodeLensProvider,
playgroundSelectedCodeActionProvider:
this._playgroundSelectedCodeActionProvider,
Expand Down Expand Up @@ -157,6 +158,7 @@ export default class MDBExtensionController implements vscode.Disposable {

this.registerCommands();
this.showOverviewPageIfRecentlyInstalled();
void this.showSurveyForEstablishedUsers();
}

registerCommands = (): void => {
Expand Down Expand Up @@ -887,6 +889,51 @@ export default class MDBExtensionController implements vscode.Disposable {
}
}

async showSurveyForEstablishedUsers(): Promise<void> {
const surveyId = '9viN9wcbsC3zvHyg7';

const hasBeenShownSurveyAlready =
this._storageController.get(StorageVariables.GLOBAL_SURVEY_SHOWN) ===
surveyId;

// Show the survey when it hasn't been show to the
// user yet, and they have saved connections
// -> they haven't just started using this extension
if (
hasBeenShownSurveyAlready ||
!this._connectionStorage.hasSavedConnections()
) {
return;
}

const action = 'Share your thoughts';
const text = 'How can we make the MongoDB extension better for you?';
const link = 'https://forms.gle/9viN9wcbsC3zvHyg7';
const result = await vscode.window.showInformationMessage(
text,
{},
{
title: action,
}
);
if (result?.title === action) {
void vscode.env.openExternal(vscode.Uri.parse(link));
this._telemetryService.track(TelemetryEventTypes.SURVEY_CLICKED, {
survey_id: surveyId,
});
} else {
this._telemetryService.track(TelemetryEventTypes.SURVEY_DISMISSED, {
survey_id: surveyId,
});
}

// whether action was taken or the prompt dismissed, we won't show this again
void this._storageController.update(
StorageVariables.GLOBAL_SURVEY_SHOWN,
surveyId
);
}

async dispose(): Promise<void> {
await this.deactivate();
}
Expand All @@ -902,5 +949,7 @@ export default class MDBExtensionController implements vscode.Disposable {
this._telemetryService.deactivate();
this._editorsController.deactivate();
this._webviewController.deactivate();
this._activeConnectionCodeLensProvider.deactivate();
this._connectionController.deactivate();
}
}
2 changes: 2 additions & 0 deletions src/storage/storageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { StoreConnectionInfo } from './connectionStorage';
export enum StorageVariables {
// Only exists on globalState.
GLOBAL_HAS_BEEN_SHOWN_INITIAL_VIEW = 'GLOBAL_HAS_BEEN_SHOWN_INITIAL_VIEW',
GLOBAL_SURVEY_SHOWN = 'GLOBAL_SURVEY_SHOWN',
GLOBAL_SAVED_CONNECTIONS = 'GLOBAL_SAVED_CONNECTIONS',
// Analytics user identify.
GLOBAL_USER_ID = 'GLOBAL_USER_ID',
Expand Down Expand Up @@ -51,6 +52,7 @@ interface StorageVariableContents {
[StorageVariables.GLOBAL_USER_ID]: string;
[StorageVariables.GLOBAL_ANONYMOUS_ID]: string;
[StorageVariables.GLOBAL_HAS_BEEN_SHOWN_INITIAL_VIEW]: boolean;
[StorageVariables.GLOBAL_SURVEY_SHOWN]: string;
[StorageVariables.GLOBAL_SAVED_CONNECTIONS]: ConnectionsFromStorage;
[StorageVariables.WORKSPACE_SAVED_CONNECTIONS]: ConnectionsFromStorage;
[StorageVariables.COPILOT_HAS_BEEN_SHOWN_WELCOME_MESSAGE]: boolean;
Expand Down
9 changes: 8 additions & 1 deletion src/telemetry/telemetryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ type ConnectionEditedTelemetryEventProperties = {
success: boolean;
};

type SurveyActionProperties = {
survey_id: string;
};

type SavedConnectionsLoadedProperties = {
// Total number of connections saved on disk
saved_connections: number;
Expand All @@ -102,7 +106,8 @@ export type TelemetryEventProperties =
| PlaygroundSavedTelemetryEventProperties
| PlaygroundLoadedTelemetryEventProperties
| KeytarSecretsMigrationFailedProperties
| SavedConnectionsLoadedProperties;
| SavedConnectionsLoadedProperties
| SurveyActionProperties;

export enum TelemetryEventTypes {
PLAYGROUND_CODE_EXECUTED = 'Playground Code Executed',
Expand All @@ -120,6 +125,8 @@ export enum TelemetryEventTypes {
PLAYGROUND_CREATED = 'Playground Created',
KEYTAR_SECRETS_MIGRATION_FAILED = 'Keytar Secrets Migration Failed',
SAVED_CONNECTIONS_LOADED = 'Saved Connections Loaded',
SURVEY_CLICKED = 'Survey link clicked',
SURVEY_DISMISSED = 'Survey prompt dismissed',
}

/**
Expand Down
Loading

0 comments on commit 16277cb

Please sign in to comment.