Skip to content

Commit 36285ba

Browse files
authored
Merge pull request #62 from DeepCodeAI/tracking
Tracking
2 parents 45a162e + f268f03 commit 36285ba

15 files changed

Lines changed: 200 additions & 68 deletions

File tree

src/deepcode/DeepCodeExtension.ts

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import {
99
DEEPCODE_SETMODE_COMMAND,
1010
DEEPCODE_SETTINGS_COMMAND,
1111
DEEPCODE_DCIGNORE_COMMAND,
12-
DEEPCODE_LOGIN,
13-
DEEPCODE_APPROVE,
14-
DEEPCODE_OPEN_BROWSER,
15-
DEEPCODE_OPEN_LOCAL,
12+
DEEPCODE_LOGIN_COMMAND,
13+
DEEPCODE_APPROVE_COMMAND,
14+
DEEPCODE_OPEN_BROWSER_COMMAND,
15+
DEEPCODE_OPEN_LOCAL_COMMAND,
16+
DEEPCODE_OPEN_ISSUE_COMMAND,
1617
} from "./constants/commands";
1718
import {
1819
openDeepcodeSettingsCommand,
1920
createDCIgnoreCommand,
2021
} from "./utils/vscodeCommandsUtils";
2122
import { errorsLogs } from "./messages/errorsServerLogMessages";
22-
2323
import {
2424
DEEPCODE_VIEW_SUPPORT,
2525
DEEPCODE_VIEW_ANALYSIS,
@@ -47,23 +47,23 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
4747

4848
context.subscriptions.push(
4949
vscode.commands.registerCommand(
50-
DEEPCODE_OPEN_BROWSER,
50+
DEEPCODE_OPEN_BROWSER_COMMAND,
5151
this.executeCommand.bind(
5252
this,
53-
DEEPCODE_OPEN_BROWSER,
53+
DEEPCODE_OPEN_BROWSER_COMMAND,
5454
(url: string) => open(url)
5555
)
5656
)
5757
);
5858

5959
context.subscriptions.push(
6060
vscode.commands.registerCommand(
61-
DEEPCODE_OPEN_LOCAL,
61+
DEEPCODE_OPEN_LOCAL_COMMAND,
6262
(path: vscode.Uri, range?: vscode.Range) => {
6363
vscode.window.showTextDocument(path, { selection: range }).then(
6464
// no need to wait for processError since then is called asynchronously as well
6565
() => {}, (err) => this.processError(err, {
66-
message: errorsLogs.command(DEEPCODE_OPEN_LOCAL),
66+
message: errorsLogs.command(DEEPCODE_OPEN_LOCAL_COMMAND),
6767
})
6868
);
6969
}
@@ -72,21 +72,21 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
7272

7373
context.subscriptions.push(
7474
vscode.commands.registerCommand(
75-
DEEPCODE_LOGIN,
75+
DEEPCODE_LOGIN_COMMAND,
7676
this.executeCommand.bind(
7777
this,
78-
DEEPCODE_LOGIN,
78+
DEEPCODE_LOGIN_COMMAND,
7979
this.initiateLogin.bind(this)
8080
)
8181
)
8282
);
8383

8484
context.subscriptions.push(
8585
vscode.commands.registerCommand(
86-
DEEPCODE_APPROVE,
86+
DEEPCODE_APPROVE_COMMAND,
8787
this.executeCommand.bind(
8888
this,
89-
DEEPCODE_APPROVE,
89+
DEEPCODE_APPROVE_COMMAND,
9090
this.approveUpload.bind(this)
9191
)
9292
)
@@ -125,6 +125,27 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
125125
)
126126
);
127127

128+
context.subscriptions.push(
129+
vscode.commands.registerCommand(
130+
DEEPCODE_OPEN_ISSUE_COMMAND,
131+
this.executeCommand.bind(
132+
this,
133+
DEEPCODE_OPEN_ISSUE_COMMAND,
134+
async (
135+
issueId: string,
136+
severity: number,
137+
uri: vscode.Uri,
138+
range: vscode.Range,
139+
) => {
140+
await vscode.commands.executeCommand(
141+
DEEPCODE_OPEN_LOCAL_COMMAND, uri, range
142+
);
143+
await this.trackViewSuggestion(issueId, severity);
144+
}
145+
)
146+
)
147+
);
148+
128149
context.subscriptions.push(
129150
vscode.commands.registerCommand(
130151
DEEPCODE_DCIGNORE_COMMAND,
@@ -153,6 +174,9 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
153174
this.checkWelcomeNotification().catch((err) => this.processError(err, {
154175
message: errorsLogs.welcomeNotification,
155176
}));
177+
this.checkAdvancedMode().catch((err) => this.processError(err, {
178+
message: errorsLogs.checkAdvancedMode,
179+
}));
156180
}
157181

158182
}

src/deepcode/constants/commands.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ export const VSCODE_ADD_COMMENT_COMMAND = "editor.action.addCommentLine";
55

66
// custom depcode commands
77
export const DEEPCODE_START_COMMAND = "deepcode.start";
8-
export const DEEPCODE_LOGIN = "deepcode.login";
9-
export const DEEPCODE_APPROVE = "deepcode.approve";
8+
export const DEEPCODE_LOGIN_COMMAND = "deepcode.login";
9+
export const DEEPCODE_APPROVE_COMMAND = "deepcode.approve";
1010
export const DEEPCODE_SETMODE_COMMAND = "deepcode.setmode";
1111
export const DEEPCODE_SETTINGS_COMMAND = "deepcode.settings";
12-
export const DEEPCODE_IGNORE_ISSUES_COMMAND = "deepcode.ignoreissues";
1312
export const DEEPCODE_DCIGNORE_COMMAND = "deepcode.dcignore";
14-
export const DEEPCODE_OPEN_BROWSER = "deepcode.open";
15-
export const DEEPCODE_OPEN_LOCAL = "deepcode.show";
13+
export const DEEPCODE_OPEN_BROWSER_COMMAND = "deepcode.open";
14+
export const DEEPCODE_OPEN_LOCAL_COMMAND = "deepcode.show";
15+
export const DEEPCODE_OPEN_ISSUE_COMMAND = "deepcode.showissue"
16+
export const DEEPCODE_IGNORE_ISSUE_COMMAND = "deepcode.ignoreissue";
1617

1718
// custom depcode constants used in commands
1819
export const DEEPCODE_CONTEXT_PREFIX = "deepcode:";
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
export const TELEMETRY_EVENTS = {
2-
ignoreSuggestion: 'ignoreSuggestion',
2+
viewWelcomeNotification: 'viewWelcomeNotification',
3+
viewLoginView: 'viewLogin',
4+
viewConsentView: 'viewConsent',
5+
viewSuggestionView: 'viewSuggestionView',
36
viewSuggestion: 'viewSuggestion',
7+
ignoreSuggestion: 'ignoreSuggestion',
8+
toggleAdvancedMode: 'toggleAdvancedMode',
9+
changeExecutionMode: 'changeExecutionMode',
410
};

src/deepcode/lib/analyzer/DeepCodeAnalyzer.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class DeepCodeAnalyzer implements DeepCode.AnalyzerInterface {
3838
this.ignoreActionsProvider = new DisposableCodeActionsProvider(
3939
this.deepcodeReview,
4040
{
41-
findSuggestionId: extractSuggestionIdFromSuggestionsMap(
42-
this.analysisResultsCollection
43-
),
41+
findSuggestionId: this.findSuggestionId.bind(this),
4442
trackIgnoreSuggestion: this.trackIgnoreSuggestion.bind(this)
4543
}
4644
);
@@ -51,13 +49,21 @@ class DeepCodeAnalyzer implements DeepCode.AnalyzerInterface {
5149
this.extension = extension;
5250
}
5351

52+
public findSuggestionId(suggestionName: string, fileSystemPath: string): string {
53+
return extractSuggestionIdFromSuggestionsMap(
54+
this.analysisResultsCollection,
55+
suggestionName,
56+
fileSystemPath
57+
);
58+
}
59+
5460
public trackIgnoreSuggestion(vscodeSeverity: number, options: {[key: string]: any}): void {
5561
if (!this.extension) return;
5662
options.data = {
5763
severity: getDeepCodeSeverity(vscodeSeverity),
5864
...options.data
5965
};
60-
this.extension.sendEvent(
66+
this.extension.processEvent(
6167
TELEMETRY_EVENTS.ignoreSuggestion,
6268
options
6369
);

src/deepcode/lib/deepCodeProviders/codeActionsProvider/DeepCodeIssuesActionsProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
IGNORE_ISSUE_BASE_COMMENT_TEXT
1111
} from "../../../constants/analysis";
1212
import {
13-
DEEPCODE_IGNORE_ISSUES_COMMAND,
13+
DEEPCODE_IGNORE_ISSUE_COMMAND,
1414
VSCODE_ADD_COMMENT_COMMAND
1515
} from "../../../constants/commands";
1616

@@ -35,7 +35,7 @@ export class DeepCodeIssuesActionProvider implements vscode.CodeActionProvider {
3535

3636
private registerIgnoreIssuesCommand() {
3737
vscode.commands.registerCommand(
38-
DEEPCODE_IGNORE_ISSUES_COMMAND,
38+
DEEPCODE_IGNORE_ISSUE_COMMAND,
3939
({
4040
currentEditor,
4141
issueText,
@@ -149,8 +149,8 @@ export class DeepCodeIssuesActionProvider implements vscode.CodeActionProvider {
149149
isFileIgnore
150150
);
151151
ignoreIssueAction.command = {
152-
command: DEEPCODE_IGNORE_ISSUES_COMMAND,
153-
title: DEEPCODE_IGNORE_ISSUES_COMMAND,
152+
command: DEEPCODE_IGNORE_ISSUE_COMMAND,
153+
title: DEEPCODE_IGNORE_ISSUE_COMMAND,
154154
arguments: [{ issueText, matchedIssue, issueId: issueFullId, isFileIgnore }]
155155
};
156156

src/deepcode/lib/modules/BaseDeepCodeModule.ts

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import DeepCodeSettingsWatcher from "../watchers/DeepCodeSettingsWatcher";
1010
import { PendingTask, PendingTaskInterface } from "../../utils/pendingTask";
1111
import { IDE_NAME, REFRESH_VIEW_DEBOUNCE_INTERVAL } from "../../constants/general";
1212
import { setContext } from "../../utils/vscodeCommandsUtils";
13-
import { DEEPCODE_VIEW_ANALYSIS } from "../../constants/views";
13+
import { DEEPCODE_CONTEXT, DEEPCODE_VIEW_ANALYSIS } from "../../constants/views";
14+
import { TELEMETRY_EVENTS } from "../../constants/telemetry";
1415
import { errorsLogs } from '../../messages/errorsServerLogMessages';
15-
import { pendingMocks } from 'nock/types';
1616

1717
export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleInterface {
1818
currentWorkspacePath: string;
@@ -33,6 +33,7 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
3333
analysisProgress = 0;
3434
private initializedView: PendingTaskInterface;
3535
private progressBadge: PendingTaskInterface | undefined;
36+
private shouldShowProgressBadge = false;
3637
private viewContext: {[key: string]: unknown};
3738

3839
// These attributes are used in tests
@@ -113,19 +114,73 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
113114

114115
async setContext(key: string, value: unknown): Promise<void> {
115116
console.log("DeepCode context", key, value);
117+
const oldValue = this.viewContext[key];
116118
this.viewContext[key] = value;
117119
await setContext(key, value);
118120
this.refreshViews();
121+
this.trackContextChange(key, value, oldValue);
122+
}
123+
124+
private trackContextChange(key: string, value: unknown, oldValue: unknown) {
125+
let event = "";
126+
let shouldWaitForView = true;
127+
let options: Record<string,any> | undefined;
128+
switch(key) {
129+
case DEEPCODE_CONTEXT.LOGGEDIN: {
130+
if (oldValue !== undefined) {
131+
if (!value && oldValue) event = TELEMETRY_EVENTS.viewLoginView;
132+
if (value && !oldValue) event = TELEMETRY_EVENTS.viewConsentView;
133+
} else {
134+
// If key was un-initialized (i.e. at start), we still report it if new value is false
135+
if (!value) event = TELEMETRY_EVENTS.viewLoginView;
136+
}
137+
break;
138+
}
139+
case DEEPCODE_CONTEXT.APPROVED: {
140+
if (oldValue !== undefined) {
141+
if (!value && oldValue) event = TELEMETRY_EVENTS.viewConsentView;
142+
if (value && !oldValue) event = TELEMETRY_EVENTS.viewSuggestionView;
143+
}
144+
break;
145+
}
146+
case DEEPCODE_CONTEXT.ADVANCED: {
147+
if (oldValue !== undefined) {
148+
event = TELEMETRY_EVENTS.toggleAdvancedMode;
149+
options = { data: { value } };
150+
shouldWaitForView = false;
151+
}
152+
break;
153+
}
154+
case DEEPCODE_CONTEXT.MODE: {
155+
event = TELEMETRY_EVENTS.changeExecutionMode;
156+
options = { data: { value } };
157+
shouldWaitForView = false;
158+
break;
159+
}
160+
}
161+
// We want to fire the event only when the user actually sees the View
162+
if (event) {
163+
if (shouldWaitForView) this.initializedView.waiter.then(
164+
() => this.processEvent(event, options)
165+
);
166+
else this.processEvent(event, options);
167+
}
119168
}
120169

121170
get shouldShowAnalysis(): boolean {
122-
return !this.viewContext['error'] &&
123-
['loggedIn', 'uploadApproved', 'workspaceFound'].every(
124-
(c) => !!this.viewContext[c]
125-
);
171+
return !this.viewContext[
172+
DEEPCODE_CONTEXT.ERROR
173+
] && [
174+
DEEPCODE_CONTEXT.LOGGEDIN,
175+
DEEPCODE_CONTEXT.APPROVED,
176+
DEEPCODE_CONTEXT.ANALYZING,
177+
].every(
178+
(c) => !!this.viewContext[c]
179+
);
126180
}
127181

128182
private getProgressBadgePromise(): Promise<void> {
183+
if (!this.shouldShowProgressBadge) return Promise.resolve();
129184
if (!this.progressBadge || this.progressBadge.isCompleted) {
130185
this.progressBadge = new PendingTask();
131186
}
@@ -134,6 +189,7 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
134189

135190
// Leave viewId undefined to remove the badge from all views
136191
async setLoadingBadge(value: boolean): Promise<void> {
192+
this.shouldShowProgressBadge = value;
137193
if (value) {
138194
// Using closure on this to allow partial binding in arbitrary positions
139195
const self = this;
@@ -172,5 +228,10 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
172228
options?: { [key: string]: any }
173229
): Promise<void>;
174230

231+
abstract processEvent(
232+
event: string,
233+
options?: { [key: string]: any }
234+
): Promise<void>;
235+
175236
abstract startExtension(): Promise<void>;
176237
}

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
4343
private async executeExtensionPipeline(): Promise<void> {
4444
console.log("DeepCode: starting execution pipeline");
4545
await this.setContext(DEEPCODE_CONTEXT.ERROR, false);
46+
this.resetTransientErrors();
4647
await this.setLoadingBadge(false);
4748

4849
const loggedIn = await this.checkSession();
49-
if (!loggedIn) return;
5050
const approved = await this.checkApproval();
51-
if (!approved) return;
51+
if (!loggedIn || !approved) return;
5252
await this.startAnalysis();
53-
54-
this.resetTransientErrors();
5553
}
5654

5755
// This function is called by commands, error handlers, etc.

src/deepcode/lib/modules/LoginModule.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DEEPCODE_CONTEXT } from "../../constants/views";
77
import { openDeepcodeViewContainer } from "../../utils/vscodeCommandsUtils";
88
import { errorsLogs } from "../../messages/errorsServerLogMessages";
99
import { deepCodeMessages } from "../../messages/deepCodeMessages";
10+
import { TELEMETRY_EVENTS } from "../../constants/telemetry";
1011

1112
const sleep = (duration: number) => new Promise(resolve => setTimeout(resolve, duration));
1213

@@ -83,6 +84,7 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
8384

8485
async checkWelcomeNotification(): Promise<void> {
8586
if (this.shouldShowWelcomeNotification) {
87+
this.processEvent(TELEMETRY_EVENTS.viewWelcomeNotification);
8688
let pressedButton = await vscode.window.showInformationMessage(
8789
deepCodeMessages.welcome.msg,
8890
deepCodeMessages.welcome.button

0 commit comments

Comments
 (0)