Skip to content

Commit 1ba4118

Browse files
author
Arvid Paeglit
committed
Merge branch 'master' into use-analysis-progress
2 parents ab640ab + 07ffc6b commit 1ba4118

14 files changed

Lines changed: 247 additions & 89 deletions

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@
168168
{
169169
"command": "deepcode.login",
170170
"when": "!deepcode:loggedIn"
171+
},
172+
{
173+
"command": "deepcode.dcignore",
174+
"when": "!deepcode:error && deepcode:loggedIn && deepcode:uploadApproved && deepcode:workspaceFound"
171175
}
172176
]
173177
},
@@ -184,7 +188,13 @@
184188
},
185189
{
186190
"command": "deepcode.login",
187-
"title": "DeepCode login"
191+
"title": "DeepCode login",
192+
"icon": "$(log-in)"
193+
},
194+
{
195+
"command": "deepcode.dcignore",
196+
"title": "DeepCode create dcignore file",
197+
"icon": "$(new-file)"
188198
}
189199
]
190200
},
@@ -215,6 +225,7 @@
215225
},
216226
"dependencies": {
217227
"@deepcode/tsc": "^1.3.0",
228+
"@deepcode/dcignore": "^1.0.2",
218229
"@types/lodash": "^4.14.159",
219230
"@types/mz": "^2.7.1",
220231
"ignore": "^5.1.8",

src/deepcode/DeepCodeExtension.ts

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import DeepCodeLib from "./lib/modules/DeepCodeLib";
77
import {
88
DEEPCODE_START_COMMAND,
99
DEEPCODE_SETTINGS_COMMAND,
10+
DEEPCODE_DCIGNORE_COMMAND,
1011
DEEPCODE_LOGIN,
1112
DEEPCODE_APPROVE,
1213
DEEPCODE_OPEN_BROWSER,
1314
DEEPCODE_OPEN_LOCAL,
1415
} from "./constants/commands";
15-
import { openDeepcodeSettingsCommand } from "./utils/vscodeCommandsUtils";
16+
import { openDeepcodeSettingsCommand, createDCIgnoreCommand } from "./utils/vscodeCommandsUtils";
17+
import { errorsLogs } from "./messages/errorsServerLogMessages";
1618

1719
import {
1820
DEEPCODE_VIEW_SUPPORT,
@@ -22,24 +24,42 @@ import { SupportProvider } from "./view/SupportProvider";
2224
import { IssueProvider } from "./view/IssueProvider";
2325

2426
class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterface {
27+
private async executeCommand(
28+
name: string,
29+
fn: (...args: any[]) => Promise<any>,
30+
...args: any[]
31+
): Promise<any> {
32+
try {
33+
await fn(...args);
34+
} catch (error) {
35+
this.processError(error, {
36+
message: errorsLogs.command(name),
37+
});
38+
}
39+
}
40+
2541
public activate(context: vscode.ExtensionContext): void {
2642
this.statusBarItem.show();
2743

2844
context.subscriptions.push(
2945
vscode.commands.registerCommand(
3046
DEEPCODE_OPEN_BROWSER,
31-
(url: string) => open(url)
47+
this.executeCommand.bind(
48+
this,
49+
DEEPCODE_OPEN_BROWSER,
50+
(url: string) => open(url)
51+
)
3252
)
3353
);
3454

3555
context.subscriptions.push(
3656
vscode.commands.registerCommand(
3757
DEEPCODE_OPEN_LOCAL,
3858
(path: vscode.Uri, range?: vscode.Range) => {
39-
console.log("DEEPCODE_OPEN_LOCAL",path.toString());
4059
vscode.window.showTextDocument(path, { selection: range }).then(
41-
(f) => console.log(f),
42-
(err) => console.error(err)
60+
() => {}, (err) => this.processError(err, {
61+
message: errorsLogs.command(DEEPCODE_OPEN_LOCAL),
62+
})
4363
);
4464
}
4565
)
@@ -48,28 +68,51 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
4868
context.subscriptions.push(
4969
vscode.commands.registerCommand(
5070
DEEPCODE_LOGIN,
51-
this.initiateLogin.bind(this)
71+
this.executeCommand.bind(
72+
this,
73+
DEEPCODE_LOGIN,
74+
this.initiateLogin.bind(this)
75+
)
5276
)
5377
);
5478

5579
context.subscriptions.push(
5680
vscode.commands.registerCommand(
5781
DEEPCODE_APPROVE,
58-
this.approveUpload.bind(this)
82+
this.executeCommand.bind(
83+
this,
84+
DEEPCODE_APPROVE,
85+
this.approveUpload.bind(this)
86+
)
5987
)
6088
);
6189

6290
context.subscriptions.push(
6391
vscode.commands.registerCommand(
6492
DEEPCODE_START_COMMAND,
65-
this.startExtension.bind(this)
93+
this.executeCommand.bind(
94+
this,
95+
DEEPCODE_START_COMMAND,
96+
this.startExtension.bind(this)
97+
)
6698
)
6799
);
68100

69101
context.subscriptions.push(
70102
vscode.commands.registerCommand(
71103
DEEPCODE_SETTINGS_COMMAND,
72-
openDeepcodeSettingsCommand
104+
this.executeCommand.bind(
105+
this,
106+
DEEPCODE_SETTINGS_COMMAND,
107+
openDeepcodeSettingsCommand
108+
)
109+
)
110+
);
111+
112+
context.subscriptions.push(
113+
vscode.commands.registerCommand(
114+
DEEPCODE_DCIGNORE_COMMAND,
115+
createDCIgnoreCommand
73116
)
74117
);
75118

@@ -84,7 +127,9 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
84127
);
85128

86129
this.activateAll();
87-
this.startExtension();
130+
this.startExtension().catch((err) => this.processError(err, {
131+
message: errorsLogs.failedExecution,
132+
}));
88133
}
89134

90135
}

src/deepcode/constants/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const DEEPCODE_LOGIN = "deepcode.login";
88
export const DEEPCODE_APPROVE = "deepcode.approve";
99
export const DEEPCODE_SETTINGS_COMMAND = "deepcode.settings";
1010
export const DEEPCODE_IGNORE_ISSUES_COMMAND = "deepcode.ignoreissues";
11+
export const DEEPCODE_DCIGNORE_COMMAND = "deepcode.dcignore";
1112
export const DEEPCODE_OPEN_BROWSER = "deepcode.open";
1213
export const DEEPCODE_OPEN_LOCAL = "deepcode.show";
1314

src/deepcode/lib/modules/BaseDeepCodeModule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
7474
}
7575

7676
get uploadApproved(): boolean {
77-
return this.staticUploadApproved || this.source !== IDE_NAME || !!(vscode.workspace.getConfiguration('deepcode').get('uploadApproved'));
77+
return this.staticUploadApproved || this.source !== IDE_NAME || !!(vscode.workspace.getConfiguration('deepcode').get<boolean>('uploadApproved'));
7878
}
7979

8080
async setUploadApproved(value = true): Promise<void> {
8181
await vscode.workspace.getConfiguration('deepcode').update('uploadApproved', value, true);
8282
}
8383

8484
get shouldReportErrors(): boolean {
85-
return !!vscode.workspace.getConfiguration('deepcode').get('yesCrashReport');
85+
return !!vscode.workspace.getConfiguration('deepcode').get<boolean>('yesCrashReport');
8686
}
8787

8888
get shouldReportEvents(): boolean {
89-
return !!vscode.workspace.getConfiguration('deepcode').get('yesTelemetry');
89+
return !!vscode.workspace.getConfiguration('deepcode').get<boolean>('yesTelemetry');
9090
}
9191

9292
// Avoid refreshing context/views too often:

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ abstract class BundlesModule extends LoginModule
102102

103103
onError(error: Error) {
104104
this.terminateAnalysis();
105-
this.processError(error);
105+
this.processError(error, {
106+
message: errorsLogs.failedServiceAI,
107+
});
106108
}
107109

108110
// processing workspaces
@@ -132,7 +134,13 @@ abstract class BundlesModule extends LoginModule
132134

133135
// procesing filter list of files, acceptable for server
134136
public async createFilesFilterList(): Promise<void> {
135-
this.serverFilesFilterList = await http.getFilters(this.baseURL, this.token);
137+
try {
138+
this.serverFilesFilterList = await http.getFilters(this.baseURL, this.token);
139+
} catch (err) {
140+
this.processError(err, {
141+
message: errorsLogs.filtersFiles
142+
})
143+
}
136144
}
137145

138146
private terminateAnalysis(): void {
@@ -193,7 +201,11 @@ abstract class BundlesModule extends LoginModule
193201
this.onError(error);
194202
});
195203

196-
http.analyse(this.baseURL, this.token, path, this.files, removedFiles).catch((error) => this.onError(error));
204+
http.analyse(this.baseURL, this.token, path, this.files, removedFiles).catch(
205+
(error) => this.processError(error, {
206+
message: errorsLogs.analyse
207+
})
208+
);
197209
}
198210

199211
private async startCollectingFiles(
@@ -274,25 +286,27 @@ abstract class BundlesModule extends LoginModule
274286
try {
275287
const workspaceFolders: readonly vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders;
276288
if (!workspaceFolders || !workspaceFolders.length) {
277-
setContext(DEEPCODE_CONTEXT.ANALYZING, false);
289+
await setContext(DEEPCODE_CONTEXT.ANALYZING, false);
278290
return;
279291
}
280292

281293
this.createWorkspacesList(workspaceFolders);
282294

283295
if (this.workspacesPaths.length) {
284-
setContext(DEEPCODE_CONTEXT.ANALYZING, true);
296+
await setContext(DEEPCODE_CONTEXT.ANALYZING, true);
285297
this.updateCurrentWorkspacePath(this.workspacesPaths[0]);
286298

287299
await this.updateHashesBundles();
288300
for await (const path of this.workspacesPaths) {
289301
await this.performBundlesActions(path);
290302
}
291303
} else {
292-
setContext(DEEPCODE_CONTEXT.ANALYZING, false);
304+
await setContext(DEEPCODE_CONTEXT.ANALYZING, false);
293305
}
294306
} catch(err) {
295-
await this.processError(err);
307+
await this.processError(err, {
308+
message: errorsLogs.failedAnalysis,
309+
});
296310
}
297311
}
298312
}

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import BundlesModule from "./BundlesModule";
44
import { setContext } from "../../utils/vscodeCommandsUtils";
55
import { DEEPCODE_CONTEXT } from "../../constants/views";
66
import { EXECUTION_DEBOUNCE_INTERVAL } from "../../constants/general";
7+
import { errorsLogs } from "../../messages/errorsServerLogMessages";
78

89
export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepCodeLibInterface {
9-
private executing = false;
10-
1110
activateAll(): void {
1211
// this.filesWatcher.activate(this);
1312
this.workspacesWatcher.activate(this);
@@ -18,7 +17,7 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
1817

1918
private async executeExtensionPipeline(): Promise<void> {
2019
console.log("DeepCode: starting execution pipeline");
21-
setContext(DEEPCODE_CONTEXT.ERROR, false);
20+
await setContext(DEEPCODE_CONTEXT.ERROR, false);
2221

2322
const loggedIn = await this.checkSession();
2423
if (!loggedIn) return;
@@ -36,7 +35,9 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
3635
try {
3736
await this.executeExtensionPipeline();
3837
} catch (err) {
39-
this.processError(err);
38+
this.processError(err, {
39+
message: errorsLogs.failedExecutionDebounce,
40+
});
4041
}
4142
},
4243
EXECUTION_DEBOUNCE_INTERVAL,

src/deepcode/lib/modules/LoginModule.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
1717

1818
this.pendingLogin = true;
1919
try {
20-
setContext(DEEPCODE_CONTEXT.LOGGEDIN, false);
20+
await setContext(DEEPCODE_CONTEXT.LOGGEDIN, false);
2121
const result = await http.login(this.baseURL, this.source);
2222
const { sessionToken, loginURL } = result;
2323
if (!sessionToken || !loginURL) {
@@ -27,7 +27,9 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
2727
await viewInBrowser(loginURL);
2828
await this.waitLoginConfirmation();
2929
} catch (err) {
30-
await this.processError(err, { message: errorsLogs.login });
30+
await this.processError(err, {
31+
message: errorsLogs.login
32+
});
3133
} finally {
3234
this.pendingLogin = false;
3335
}
@@ -36,9 +38,15 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
3638
async checkSession(): Promise<boolean> {
3739
let validSession = false;
3840
if (this.token) {
39-
validSession = !!(await http.checkSession(this.baseURL, this.token));
41+
try {
42+
validSession = !!(await http.checkSession(this.baseURL, this.token));
43+
} catch (err) {
44+
this.processError(err, {
45+
message: errorsLogs.loginStatus
46+
});
47+
}
4048
}
41-
setContext(DEEPCODE_CONTEXT.LOGGEDIN, validSession);
49+
await setContext(DEEPCODE_CONTEXT.LOGGEDIN, validSession);
4250
return validSession;
4351
}
4452

@@ -57,13 +65,13 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
5765

5866
async checkApproval(): Promise<boolean> {
5967
const approved = this.uploadApproved;
60-
setContext(DEEPCODE_CONTEXT.APPROVED, approved);
68+
await setContext(DEEPCODE_CONTEXT.APPROVED, approved);
6169
return approved;
6270
}
6371

6472
async approveUpload(): Promise<void> {
65-
this.setUploadApproved(true);
66-
this.checkApproval();
73+
await this.setUploadApproved(true);
74+
await this.checkApproval();
6775
}
6876

6977
}

0 commit comments

Comments
 (0)