Skip to content

Commit a5df51d

Browse files
author
Arvid Paeglit
committed
cleanup and debugging it with James. no logic changes
1 parent 81c150d commit a5df51d

10 files changed

Lines changed: 38 additions & 71 deletions

File tree

.extensionStatus

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/deepcode/constants/general.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
// Changing this requires changing display name in package.json.
22
export const DEEPCODE_NAME = "DeepCode";
33
export const ALLOWED_PAYLOAD_SIZE = 1024 * 1024 * 4; // max payload size of 4MB in bytes
4-
export const INSTALL_STATUS = {
5-
justInstalled: "JUST_INSTALLED",
6-
installed: "INSTALLED"
7-
};
8-
export const STATUSFILE_NAME = ".extensionStatus";
94
export const IDE_NAME = "vscode";

src/deepcode/constants/statusCodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const statusCodes: { [key: string]: number } = {
55
unauthorizedUser: 401,
66
unauthorizedBundleAccess: 403,
77
notFound: 404,
8+
analysisTimeout: 408,
89
bigPayload: 413,
910
serverError: 500,
1011
badGateway: 502,

src/deepcode/lib/errorHandler/DeepCodeErrorHandler.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ class DeepCodeErrorHandler implements DeepCode.ErrorHandlerInterface {
9191
}
9292

9393
private async unauthorizedAccess(extension: DeepCode.ExtensionInterface): Promise<void> {
94-
do {
95-
await extension.initiateLogin();
96-
} while (!extension.token)
97-
98-
await sleep(2000);
94+
await sleep(1000);
9995
await extension.activateExtensionAnalyzeActions();
10096
}
10197

src/deepcode/lib/modules/BaseDeepCodeModule.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import DeepCodeWorkspaceFoldersWatcher from "../watchers/WorkspaceFoldersWatcher
88
import DeepCodeEditorsWatcher from "../watchers/EditorsWatcher";
99
import DeepCodeSettingsWatcher from "../watchers/DeepCodeSettingsWatcher";
1010
import DeepCodeErrorhandler from "../errorHandler/DeepCodeErrorHandler";
11+
import { IDE_NAME } from "../../constants/general";
1112

1213
export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleInterface {
1314
public store: DeepCode.ExtensionStoreInterface;
@@ -28,7 +29,7 @@ export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleIn
2829
public staticToken = '';
2930
public staticBaseURL = '';
3031
public defaultBaseURL = 'https://www.deepcode.ai';
31-
public staticuUploadApproved = false;
32+
public staticUploadApproved = false;
3233

3334
constructor() {
3435
this.store = new DeepCodeStore();
@@ -60,13 +61,17 @@ export default class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleIn
6061
return this.staticToken || vscode.workspace.getConfiguration('deepcode').get('token');
6162
}
6263

63-
public set token(value) {
64+
public async setToken(token: string): Promise<void> {
6465
this.staticToken = '';
65-
vscode.workspace.getConfiguration('deepcode').update('token', value, true);
66+
await vscode.workspace.getConfiguration('deepcode').update('token', token, true);
67+
}
68+
69+
public get source(): string {
70+
return process.env['GITPOD_WORKSPACE_ID'] ? 'gitpod' : IDE_NAME;
6671
}
6772

6873
public get uploadApproved(): boolean {
69-
return this.staticuUploadApproved || !!(vscode.workspace.getConfiguration('deepcode').get('uploadApproved'));
74+
return this.staticUploadApproved || this.source !== IDE_NAME || !!(vscode.workspace.getConfiguration('deepcode').get('uploadApproved'));
7075
}
7176

7277
public async approveUpload(isGlobal: boolean = false): Promise<void> {

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import * as vscode from "vscode";
2-
// import * as path from "path";
3-
// import * as nodeFs from "fs";
42

53
import DeepCode from "../../../interfaces/DeepCodeInterfaces";
6-
import http from "../../http/requests";
74
import BundlesModule from "./BundlesModule";
85

9-
// import { INSTALL_STATUS, STATUSFILE_NAME, DEEPCODE_NAME } from "../../constants/general";
10-
116
export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepCodeLibInterface {
127

138
public activateWatchers(): void {
@@ -17,31 +12,27 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
1712
this.settingsWatcher.activate(this);
1813
}
1914

20-
// public async preActivateActions(): Promise<void> {
21-
// // let status = INSTALL_STATUS.installed;
22-
// // if (process.env.NODE_ENV === "production") {
23-
// // status = this.manageExtensionStatus();
24-
// // }
25-
// await this.activateActions();
26-
// }
27-
28-
// public manageExtensionStatus(): string {
29-
// const extension = vscode.extensions.all.find(
30-
// el => el.packageJSON.displayName === DEEPCODE_NAME
31-
// );
32-
// if (extension) {
33-
// const statusFilePath = path.join(extension.extensionPath, `/${STATUSFILE_NAME}`);
34-
// const extensionStatus = nodeFs.readFileSync(statusFilePath, "utf8");
35-
// if (extensionStatus === INSTALL_STATUS.justInstalled) {
36-
// this.store.cleanStore();
37-
// nodeFs.writeFileSync(statusFilePath, INSTALL_STATUS.installed);
38-
// return INSTALL_STATUS.justInstalled;
39-
// }
40-
// }
41-
// return INSTALL_STATUS.installed;
42-
// }
4315

4416
public async activateExtensionAnalyzeActions(): Promise<void> {
17+
18+
// First, check logged in or not
19+
let loggedIn = await this.checkSession();
20+
if (!loggedIn) {
21+
await this.initiateLogin();
22+
loggedIn = await this.checkSession();
23+
if (!loggedIn) {
24+
return;
25+
}
26+
}
27+
28+
// Second, check user consent on sending files to server
29+
if (!this.uploadApproved) {
30+
await this.askUploadApproval();
31+
if (!this.uploadApproved) {
32+
return;
33+
}
34+
}
35+
4536
const workspaceFolders: readonly vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders;
4637

4738
if (!workspaceFolders || !workspaceFolders.length) {
@@ -55,24 +46,6 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
5546

5647
await this.updateHashesBundles();
5748

58-
// First, check logged in or not
59-
let loggedIn = await this.checkSession();
60-
if (!loggedIn) {
61-
await this.initiateLogin();
62-
loggedIn = await this.checkSession();
63-
if (!loggedIn) {
64-
return;
65-
}
66-
}
67-
68-
// Second, check user consent on sending files to server
69-
if (!this.uploadApproved) {
70-
await this.askUploadApproval();
71-
if (!this.uploadApproved) {
72-
return;
73-
}
74-
}
75-
7649
// Third, initiate analysis
7750
try {
7851
// Main entry point to

src/deepcode/lib/modules/LoginModule.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ import DeepCode from "../../../interfaces/DeepCodeInterfaces";
55
import http from "../../http/requests";
66
import { deepCodeMessages } from "../../messages/deepCodeMessages";
77
import BaseDeepCodeModule from "./BaseDeepCodeModule";
8-
import { statusCodes } from "../../constants/statusCodes";
9-
import { IDE_NAME } from "../../constants/general";
108

119
const sleep = (duration: number) => new Promise(resolve => setTimeout(resolve, duration));
1210

1311
class LoginModule extends BaseDeepCodeModule implements DeepCode.LoginModuleInterface {
1412
private pendingLogin: boolean = false;
1513

1614
public async initiateLogin(): Promise<void> {
17-
1815
if (this.pendingLogin) {
1916
return
2017
}
@@ -26,15 +23,14 @@ class LoginModule extends BaseDeepCodeModule implements DeepCode.LoginModuleInte
2623

2724
pressedButton = await vscode.window.showInformationMessage(login.msg, login.button);
2825
if (pressedButton === login.button) {
29-
const source = process.env['GITPOD_WORKSPACE_ID'] ? 'gitpod' : IDE_NAME;
30-
const result = await http.login(this.baseURL, source);
26+
const result = await http.login(this.baseURL, this.source);
3127

3228
let { sessionToken, loginURL } = result;
3329
if (!sessionToken || !loginURL) {
3430
throw new Error();
3531
}
3632
await open(loginURL);
37-
this.token = sessionToken;
33+
await this.setToken(sessionToken);
3834
await this.waitLoginConfirmation();
3935
}
4036
} finally {

src/interfaces/DeepCodeInterfaces.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,16 @@ namespace DeepCode {
184184
hashesBundles: HashesBundlesInterface;
185185
serverFilesFilterList: AllowedServerFilterListInterface;
186186
remoteBundles: RemoteBundlesCollectionInterface;
187+
source: string;
187188
staticToken: string;
188189
defaultBaseURL: string;
189190
staticBaseURL: string;
190191
baseURL: string;
191192
termsConditionsUrl: string;
192193
token: string;
194+
setToken(token: string): Promise<void>;
193195
uploadApproved: boolean;
194-
approveUpload(): Promise<void>;
196+
approveUpload(isGlobal: boolean): Promise<void>;
195197
analyzer: DeepCode.AnalyzerInterface;
196198
statusBarItem: StatusBarItemInterface;
197199
filesWatcher: DeepCodeWatcherInterface;
@@ -225,11 +227,8 @@ namespace DeepCode {
225227
}
226228

227229
export interface DeepCodeLibInterface {
228-
// preActivateActions(): Promise<void>;
229-
// activateActions(): Promise<void>;
230230
activateWatchers(): void;
231231
activateExtensionAnalyzeActions(): Promise<void>;
232-
// manageExtensionStatus(): string;
233232
}
234233

235234
export interface ExtensionInterface

src/test/mocked_data/sample_repository/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ var browserVer;
1616

1717
if (agt.indexOf("opera") != -1) {
1818
browserType = "Opera";
19+
// deepcode ignore UseStrictEquality: <please specify a reason of ignoring this>
20+
// deepcode ignore UseStrictEquality: <please specify a reason of ignoring this>
1921

2022
if (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1) {
2123
browserVer = "Opera7";

src/test/suite/extension.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const preTestConfigureExtension = () => {
6868
const testExtension = extension.getExtension();
6969

7070
// set test token and backend host
71+
testExtension.staticUploadApproved = true;
7172
testExtension.staticToken = testToken;
7273
testExtension.staticBaseURL = testHost;
7374

0 commit comments

Comments
 (0)