Skip to content

Commit cbd0d81

Browse files
committed
Added reactive dashboard.
1 parent f387352 commit cbd0d81

15 files changed

Lines changed: 377 additions & 8 deletions

images/icon-sidebar.svg

Lines changed: 18 additions & 0 deletions
Loading

package.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,60 @@
8181
}
8282
}
8383
],
84+
"viewsContainers": {
85+
"activitybar": [
86+
{
87+
"id": "deepcode",
88+
"title": "DeepCode",
89+
"icon": "images/icon-sidebar.svg"
90+
}
91+
]
92+
},
93+
"views": {
94+
"deepcode": [
95+
{
96+
"id": "deepcode.views.welcome",
97+
"name": "DeepCode Extension",
98+
"when": "!deepcode:loggedIn"
99+
},
100+
{
101+
"id": "deepcode.views.progress",
102+
"name": "DeepCode Analysis",
103+
"when": "deepcode:loggedIn && deepcode:analyzing"
104+
},
105+
{
106+
"id": "deepcode.views.analysis",
107+
"name": "DeepCode Analysis",
108+
"when": "deepcode:loggedIn && deepcode:completed"
109+
},
110+
{
111+
"id": "deepcode.views.support",
112+
"name": "Help & feedback"
113+
}
114+
]
115+
},
116+
"viewsWelcome": [
117+
{
118+
"view": "deepcode.views.welcome",
119+
"contents": "Welcome to DeepCode for Visual Studio Code. 👋\nLet's start by connecting VS Code with DeepCode:\n[Connect VS Code with DeepCode](command:deepcode.login 'Connect with DeepCode')\n🚀 DeepCode's mission is to find bugs in your Javascript, TypeScript, Python, Java and C/C++ code, fast!\n💬 A VS Code user (Lucas) recently said:\"I'm really crazy about this super simple service that feels like it's from 5 years in the future\".\n👉 Connect with DeepCode and start your first analysis!"
120+
},
121+
{
122+
"view": "deepcode.views.progress",
123+
"contents": "IN PROGRESS"
124+
},
125+
{
126+
"view": "deepcode.views.analysis",
127+
"contents": "ANALYZED"
128+
}
129+
],
130+
"menus": {
131+
"commandPalette": [
132+
{
133+
"command": "deepcode.start",
134+
"when": "deepcode:loggedIn"
135+
}
136+
]
137+
},
84138
"commands": [
85139
{
86140
"command": "deepcode.start",
@@ -89,6 +143,10 @@
89143
{
90144
"command": "deepcode.settings",
91145
"title": "DeepCode settings"
146+
},
147+
{
148+
"command": "deepcode.login",
149+
"title": "DeepCode login"
92150
}
93151
]
94152
},

src/deepcode/DeepCodeExtension.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,59 @@
11
import * as vscode from "vscode";
2+
import * as open from "open";
23

34
import DeepCode from "../interfaces/DeepCodeInterfaces";
45
import DeepCodeLib from "./lib/modules/DeepCodeLib";
56

6-
import { DEEPCODE_START_COMMAND, DEEPCODE_SETTINGS_COMMAND } from "./constants/commands";
7+
import {
8+
DEEPCODE_START_COMMAND,
9+
DEEPCODE_SETTINGS_COMMAND,
10+
DEEPCODE_LOGIN,
11+
DEEPCODE_OPEN_BROWSER,
12+
DEEPCODE_OPEN_LOCAL,
13+
} from "./constants/commands";
714
import { openDeepcodeSettingsCommand } from "./utils/vscodeCommandsUtils";
815

16+
import {
17+
DEEPCODE_VIEW_SUPPORT,
18+
DEEPCODE_VIEW_PROGRESS,
19+
DEEPCODE_VIEW_ANALYSIS,
20+
} from "./constants/views";
21+
import { SupportProvider } from "./view/SupportProvider";
22+
import { ProgressProvider } from "./view/ProgressProvider";
23+
import { IssueProvider } from "./view/IssueProvider";
24+
925
class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterface {
1026
public activate(context: vscode.ExtensionContext): void {
1127
this.store.createStore(context);
1228
this.statusBarItem.show();
1329

30+
context.subscriptions.push(
31+
vscode.commands.registerCommand(
32+
DEEPCODE_OPEN_BROWSER,
33+
(url: string) => open(url)
34+
)
35+
);
36+
37+
context.subscriptions.push(
38+
vscode.commands.registerCommand(
39+
DEEPCODE_OPEN_LOCAL,
40+
(path: vscode.Uri, range?: vscode.Range) => {
41+
console.log("DEEPCODE_OPEN_LOCAL",path.toString());
42+
vscode.window.showTextDocument(path, { selection: range }).then(
43+
(f) => console.log(f),
44+
(err) => console.error(err)
45+
);
46+
}
47+
)
48+
);
49+
50+
context.subscriptions.push(
51+
vscode.commands.registerCommand(
52+
DEEPCODE_LOGIN,
53+
this.activateExtensionAnalyzeActions.bind(this)
54+
)
55+
);
56+
1457
context.subscriptions.push(
1558
vscode.commands.registerCommand(
1659
DEEPCODE_START_COMMAND,
@@ -25,6 +68,21 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
2568
)
2669
);
2770

71+
vscode.window.registerTreeDataProvider(
72+
DEEPCODE_VIEW_SUPPORT,
73+
new SupportProvider(this)
74+
);
75+
76+
vscode.window.registerTreeDataProvider(
77+
DEEPCODE_VIEW_PROGRESS,
78+
new ProgressProvider(this)
79+
);
80+
81+
vscode.window.registerTreeDataProvider(
82+
DEEPCODE_VIEW_ANALYSIS,
83+
new IssueProvider(this)
84+
);
85+
2886
context.subscriptions.push(
2987
{ dispose: this.startExtension() },
3088
);

src/deepcode/constants/commands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ export const VSCODE_ADD_COMMENT_COMMAND = "editor.action.addCommentLine";
44

55
// custom depcode commands
66
export const DEEPCODE_START_COMMAND = "deepcode.start";
7+
export const DEEPCODE_LOGIN = "deepcode.login";
78
export const DEEPCODE_SETTINGS_COMMAND = "deepcode.settings";
89
export const DEEPCODE_IGNORE_ISSUES_COMMAND = "deepcode.ignoreissues";
10+
export const DEEPCODE_OPEN_BROWSER = "deepcode.open";
11+
export const DEEPCODE_OPEN_LOCAL = "deepcode.show";
12+
13+
// custom depcode constants used in commands
14+
export const DEEPCODE_CONTEXT_PREFIX = "deepcode:";

src/deepcode/constants/views.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const DEEPCODE_VIEW_SUPPORT = "deepcode.views.support";
2+
export const DEEPCODE_VIEW_PROGRESS = "deepcode.views.progress";
3+
export const DEEPCODE_VIEW_ANALYSIS = "deepcode.views.analysis";
4+
5+
export const DEEPCODE_CONTEXT = {
6+
LOGGEDIN: "loggedIn",
7+
ANALYZING: "analyzing",
8+
COMPLETED: "completed",
9+
};
10+
11+
export const DEEPCODE_ANALYSIS_STATUS = {
12+
HASHING: "Hashing files",
13+
UPLOADING: "Uploading files",
14+
ANALYZING: "Analyzing files",
15+
};

src/deepcode/lib/modules/BaseDeepCodeModule.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleIn
2525
public settingsWatcher: DeepCode.DeepCodeWatcherInterface;
2626
public errorHandler: DeepCode.ErrorHandlerInterface;
2727

28+
// Views and analysis progress
29+
public refreshViewEmitter: vscode.EventEmitter<any>;
30+
public analysisStatus: string = '';
31+
public analysisProgress: number = 0;
32+
2833
// These attributes are used in tests
2934
public staticToken = '';
3035
public staticBaseURL = '';
@@ -45,6 +50,9 @@ export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleIn
4550
this.editorsWatcher = new DeepCodeEditorsWatcher();
4651
this.settingsWatcher = new DeepCodeSettingsWatcher();
4752
this.errorHandler = new DeepCodeErrorhandler();
53+
this.refreshViewEmitter = new vscode.EventEmitter<any>();
54+
this.analysisStatus = '';
55+
this.analysisProgress = 0;
4856
}
4957

5058
public get baseURL(): string {
@@ -85,4 +93,8 @@ export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleIn
8593
public get shouldReportEvents(): boolean {
8694
return !!vscode.workspace.getConfiguration('deepcode').get('yesTelemetry');
8795
}
96+
97+
public refreshViews(content?: any): void {
98+
this.refreshViewEmitter.fire(content || undefined);
99+
}
88100
}

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { startFilesUpload } from "../../utils/packageUtils";
99
import { BUNDLE_EVENTS } from "../../constants/events";
1010
import { errorsLogs } from "../../messages/errorsServerLogMessages";
1111
import LoginModule from "../../lib/modules/LoginModule";
12+
import { setContext } from "../../utils/vscodeCommandsUtils";
13+
import { DEEPCODE_ANALYSIS_STATUS, DEEPCODE_CONTEXT } from "../../constants/views";
1214

1315
class BundlesModule extends LoginModule
1416
implements DeepCode.BundlesModuleInterface {
@@ -28,29 +30,44 @@ class BundlesModule extends LoginModule
2830
this.onAnalyseFinish = this.onAnalyseFinish.bind(this);
2931
this.onError = this.onError.bind(this);
3032

31-
this.serviceAI.on(BUNDLE_EVENTS.error, this.onError); }
33+
this.serviceAI.on(BUNDLE_EVENTS.error, this.onError);
34+
}
35+
36+
updateStatus(status: string, progress?: number) {
37+
this.analysisStatus = status;
38+
if (progress) this.analysisProgress = progress;
39+
this.refreshViews();
40+
}
3241

3342
onBuildBundleProgress(processed: number, total: number) {
3443
console.log(`BUILD BUNDLE PROGRESS - ${processed}/${total}`);
44+
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.HASHING, processed/total);
3545
}
3646

3747
onBuildBundleFinish() {
3848
console.log("BUILD BUNDLE FINISH");
49+
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.HASHING, 1);
3950
}
4051

4152
onUploadBundleProgress(processed: number, total: number) {
4253
console.log(`UPLOAD BUNDLE PROGRESS - ${processed}/${total}`);
54+
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.UPLOADING, processed/total);
4355
}
4456

4557
onUploadBundleFinish() {
4658
console.log("UPLOAD BUNDLE FINISH");
59+
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.UPLOADING, 1);
4760
}
4861

4962
onAnalyseProgress(analysisResults: IQueueAnalysisCheckResult) {
5063
console.log("on Analyse Progress");
64+
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.ANALYZING, 0.5);
5165
}
5266

5367
onAnalyseFinish(analysisResults: IQueueAnalysisCheckResult) {
68+
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.ANALYZING, 1);
69+
setContext(DEEPCODE_CONTEXT.ANALYZING, false);
70+
setContext(DEEPCODE_CONTEXT.COMPLETED, true);
5471
type ResultFiles = {
5572
[filePath: string]: DeepCode.AnalysisResultsFileResultsInterface;
5673
};
@@ -80,6 +97,8 @@ class BundlesModule extends LoginModule
8097
}
8198

8299
onError(error: Error) {
100+
setContext(DEEPCODE_CONTEXT.ANALYZING, false);
101+
setContext(DEEPCODE_CONTEXT.COMPLETED, false);
83102
this.errorHandler.processError(this, error);
84103
throw error;
85104
}
@@ -125,6 +144,8 @@ class BundlesModule extends LoginModule
125144
}
126145

127146
public async performBundlesActions(path: string): Promise<void> {
147+
setContext(DEEPCODE_CONTEXT.ANALYZING, true);
148+
setContext(DEEPCODE_CONTEXT.COMPLETED, false);
128149
if (!Object.keys(this.serverFilesFilterList).length) {
129150
await this.createFilesFilterList();
130151
this.filesWatcher.activate(this);
@@ -152,6 +173,8 @@ class BundlesModule extends LoginModule
152173
return currentProgress;
153174
};
154175

176+
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.HASHING, 0);
177+
155178
window.withProgress(progressOptions, async progress => {
156179
this.serviceAI.on(BUNDLE_EVENTS.buildBundleProgress, (processed: number, total: number) => {
157180
this.onBuildBundleProgress(processed, total);

src/deepcode/lib/modules/LoginModule.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as vscode from "vscode";
2-
import * as open from "open";
32

43
import DeepCode from "../../../interfaces/DeepCodeInterfaces";
54
import http from "../../http/requests";
65
import { deepCodeMessages } from "../../messages/deepCodeMessages";
6+
import { setContext, viewInBrowser } from "../../utils/vscodeCommandsUtils";
77
import ReportModule from "./ReportModule";
8+
import { DEEPCODE_CONTEXT } from "../../constants/views";
9+
810

911
const sleep = (duration: number) => new Promise(resolve => setTimeout(resolve, duration));
1012

@@ -18,6 +20,7 @@ class LoginModule extends ReportModule implements DeepCode.LoginModuleInterface
1820
this.pendingLogin = true;
1921

2022
try {
23+
setContext(DEEPCODE_CONTEXT.LOGGEDIN, false);
2124
const { login } = deepCodeMessages;
2225
let pressedButton: string | undefined;
2326

@@ -29,18 +32,21 @@ class LoginModule extends ReportModule implements DeepCode.LoginModuleInterface
2932
if (!sessionToken || !loginURL) {
3033
throw new Error();
3134
}
32-
await open(loginURL);
35+
await viewInBrowser(loginURL);
3336
await this.setToken(sessionToken);
3437
await this.waitLoginConfirmation();
38+
setContext(DEEPCODE_CONTEXT.LOGGEDIN, true);
3539
}
3640
} finally {
3741
this.pendingLogin = false;
3842
}
3943
}
4044

41-
public checkSession(): Promise<boolean> {
42-
if (!this.token) return Promise.resolve(false);
43-
return http.checkSession(this.baseURL, this.token);
45+
public async checkSession(): Promise<boolean> {
46+
if (!this.token) return false;
47+
const validSession = await http.checkSession(this.baseURL, this.token);
48+
setContext(DEEPCODE_CONTEXT.LOGGEDIN, !!validSession);
49+
return validSession;
4450
}
4551

4652
private async waitLoginConfirmation(): Promise<void> {

src/deepcode/utils/vscodeCommandsUtils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import * as vscode from "vscode";
22
import { DEEPCODE_NAME } from "../constants/general";
33
import {
44
DEEPCODE_START_COMMAND,
5-
VSCODE_GO_TO_SETTINGS_COMMAND
5+
VSCODE_GO_TO_SETTINGS_COMMAND,
6+
DEEPCODE_CONTEXT_PREFIX,
7+
DEEPCODE_OPEN_BROWSER,
68
} from "../constants/commands";
79

810
export const getDeepcodeExtensionId = (): string => {
@@ -20,3 +22,11 @@ export const openDeepcodeSettingsCommand = (): void => {
2022
export const startDeepCodeCommand = (): void => {
2123
vscode.commands.executeCommand(DEEPCODE_START_COMMAND);
2224
};
25+
26+
export function setContext(key: string, value: unknown) {
27+
vscode.commands.executeCommand('setContext', `${DEEPCODE_CONTEXT_PREFIX}${key}`, value);
28+
};
29+
30+
export function viewInBrowser(url: string) {
31+
vscode.commands.executeCommand(DEEPCODE_OPEN_BROWSER, url);
32+
};

0 commit comments

Comments
 (0)