Skip to content

Commit ab88425

Browse files
author
Arvid Paeglit
committed
huge refactoring. dealing with code to be in tsc and with interfaces
1 parent ed36a12 commit ab88425

15 files changed

Lines changed: 2312 additions & 1469 deletions

package-lock.json

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

package.json

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,31 +227,27 @@
227227
"test": "node ./out/test/runTest.js"
228228
},
229229
"devDependencies": {
230-
"@types/glob": "^7.1.2",
231-
"@types/mocha": "^7.0.2",
232-
"@types/node": "^14.0.14",
233-
"@types/vscode": "^1.46.0",
230+
"@types/glob": "^7.1.3",
231+
"@types/mocha": "^8.0.3",
232+
"@types/node": "^14.6.2",
233+
"@types/vscode": "^1.48.0",
234234
"@types/nock": "^11.1.0",
235+
"@types/lodash": "^4.14.161",
235236
"glob": "^7.1.6",
236-
"mocha": "^8.1.1",
237-
"typescript": "^3.9.5",
238-
"eslint": "^7.3.1",
239-
"eslint-plugin-import": "^2.21.2",
237+
"mocha": "^8.1.3",
238+
"typescript": "^4.0.2",
239+
"eslint": "^7.8.0",
240+
"eslint-plugin-import": "^2.22.0",
240241
"eslint-plugin-node": "^11.1.0",
241242
"eslint-plugin-prettier": "^3.1.4",
242243
"eslint-plugin-promise": "^4.2.1",
243244
"eslint-plugin-standard": "^4.0.1",
244245
"vscode-test": "^1.4.0",
245-
"nock": "^12.0.3"
246+
"nock": "^13.0.4"
246247
},
247248
"dependencies": {
248249
"@deepcode/tsc": "^1.3.1",
249-
"@deepcode/dcignore": "^1.0.2",
250-
"@types/lodash": "^4.14.159",
251-
"@types/mz": "^2.7.1",
252-
"ignore": "^5.1.8",
253250
"lodash": "^4.17.19",
254-
"mz": "^2.7.0",
255-
"open": "^7.0.4"
251+
"open": "^7.2.1"
256252
}
257253
}

src/deepcode/DeepCodeExtension.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
openDeepcodeSettingsCommand,
2020
createDCIgnoreCommand,
2121
} from "./utils/vscodeCommandsUtils";
22-
import { errorsLogs } from "./messages/errorsServerLogMessages";
22+
import { errorsLogs } from './messages/errorsServerLogMessages';
2323
import {
2424
DEEPCODE_VIEW_SUPPORT,
2525
DEEPCODE_VIEW_ANALYSIS,
@@ -41,7 +41,7 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
4141
});
4242
}
4343
}
44-
44+
4545
public activate(context: vscode.ExtensionContext): void {
4646
this.statusBarItem.show();
4747

@@ -69,7 +69,7 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
6969
}
7070
)
7171
);
72-
72+
7373
context.subscriptions.push(
7474
vscode.commands.registerCommand(
7575
DEEPCODE_LOGIN_COMMAND,
@@ -80,7 +80,7 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
8080
)
8181
)
8282
);
83-
83+
8484
context.subscriptions.push(
8585
vscode.commands.registerCommand(
8686
DEEPCODE_APPROVE_COMMAND,
@@ -91,7 +91,7 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
9191
)
9292
)
9393
);
94-
94+
9595
context.subscriptions.push(
9696
vscode.commands.registerCommand(
9797
DEEPCODE_START_COMMAND,
@@ -102,7 +102,7 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
102102
)
103103
)
104104
);
105-
105+
106106
context.subscriptions.push(
107107
vscode.commands.registerCommand(
108108
DEEPCODE_SETMODE_COMMAND,
@@ -113,7 +113,7 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
113113
)
114114
)
115115
);
116-
116+
117117
context.subscriptions.push(
118118
vscode.commands.registerCommand(
119119
DEEPCODE_SETTINGS_COMMAND,
@@ -158,12 +158,12 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
158158
);
159159

160160
vscode.window.registerTreeDataProvider(
161-
DEEPCODE_VIEW_SUPPORT,
161+
DEEPCODE_VIEW_SUPPORT,
162162
new SupportProvider(this)
163163
);
164164

165165
vscode.window.registerTreeDataProvider(
166-
DEEPCODE_VIEW_ANALYSIS,
166+
DEEPCODE_VIEW_ANALYSIS,
167167
new IssueProvider(this)
168168
);
169169

src/deepcode/constants/filesConstants.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/deepcode/lib/analyzer/DeepCodeAnalyzer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DeepCodeAnalyzer implements DeepCode.AnalyzerInterface {
2929
| undefined;
3030
public deepcodeReview: vscode.DiagnosticCollection | undefined;
3131
public analysisResultsCollection: DeepCode.AnalysisResultsCollectionInterface;
32-
32+
3333
public constructor() {
3434
this.SEVERITIES = createDeepCodeSeveritiesMap();
3535
this.deepcodeReview = vscode.languages.createDiagnosticCollection(DEEPCODE_NAME);

src/deepcode/lib/modules/BaseDeepCodeModule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import { setContext } from "../../utils/vscodeCommandsUtils";
1313
import { DEEPCODE_CONTEXT, DEEPCODE_VIEW_ANALYSIS } from "../../constants/views";
1414
import { TELEMETRY_EVENTS } from "../../constants/telemetry";
1515
import { errorsLogs } from '../../messages/errorsServerLogMessages';
16-
import { IServiceAI, ServiceAI } from '@deepcode/tsc';
16+
import { IServiceAI, ServiceAI, IHashesBundles, IRemoteBundlesCollection } from '@deepcode/tsc';
1717

1818
export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleInterface {
1919
serviceAI: IServiceAI;
2020
currentWorkspacePath: string;
2121
workspacesPaths: Array<string>;
22-
hashesBundles: DeepCode.HashesBundlesInterface;
23-
remoteBundles: DeepCode.RemoteBundlesCollectionInterface;
22+
hashesBundles: IHashesBundles;
23+
remoteBundles: IRemoteBundlesCollection;
2424
analyzer: DeepCode.AnalyzerInterface;
2525
statusBarItem: DeepCode.StatusBarItemInterface;
2626
filesWatcher: DeepCode.DeepCodeWatcherInterface;

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ import * as vscode from "vscode";
22
import * as _ from "lodash";
33

44
import DeepCode from "../../../interfaces/DeepCodeInterfaces";
5-
import { IQueueAnalysisCheckResult } from "@deepcode/tsc";
6-
import { checkIfBundleIsEmpty } from "../../utils/bundlesUtils";
7-
import { createListOfDirFiles } from "@deepcode/tsc/src/utils/packageUtils";
5+
import {
6+
IQueueAnalysisCheckResult,
7+
IBundles,
8+
IRemoteBundle,
9+
10+
checkIfBundleIsEmpty,
11+
createListOfDirFiles,
12+
} from '@deepcode/tsc';
13+
814
import { BUNDLE_EVENTS } from "../../constants/events";
915
import LoginModule from "../../lib/modules/LoginModule";
1016
import { DEEPCODE_ANALYSIS_STATUS, DEEPCODE_CONTEXT } from "../../constants/views";
@@ -17,7 +23,7 @@ abstract class BundlesModule extends LoginModule
1723
runningAnalysis = false;
1824

1925
files: string[] = [];
20-
26+
2127
constructor() {
2228
super();
2329

@@ -61,7 +67,7 @@ abstract class BundlesModule extends LoginModule
6167
this.refreshViews();
6268
}
6369

64-
70+
6571
onCollectBundleProgress(value: number) {
6672
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.COLLECTING, value);
6773
}
@@ -153,20 +159,6 @@ abstract class BundlesModule extends LoginModule
153159
this.workspacesPaths.push(workspacePath);
154160
}
155161

156-
// procesing filter list of files, acceptable for server
157-
public async createFilesFilterList(): Promise<void> {
158-
try {
159-
this.serverFilesFilterList = await this.serviceAI.getFilters({
160-
baseURL: this.baseURL,
161-
sessionToken: this.token
162-
});
163-
} catch (err) {
164-
await this.processError(err, {
165-
message: errorsLogs.filtersFiles
166-
})
167-
}
168-
}
169-
170162
private terminateAnalysis(): void {
171163
this.serviceAI.removeListeners();
172164
this.runningAnalysis = false;
@@ -176,25 +168,13 @@ abstract class BundlesModule extends LoginModule
176168
if (this.runningAnalysis) return;
177169
this.runningAnalysis = true;
178170

179-
if (!Object.keys(this.serverFilesFilterList).length) {
180-
await this.createFilesFilterList();
181-
if (!Object.keys(this.serverFilesFilterList).length) {
182-
await this.processError(new Error(errorsLogs.filtersFiles), {
183-
message: errorsLogs.filtersFiles,
184-
data: {
185-
filters: this.serverFilesFilterList
186-
}
187-
});
188-
return;
189-
}
190-
this.filesWatcher.activate(this);
191-
}
171+
// this.filesWatcher.activate(this);
192172

193173
if (!this.token) {
194174
await this.checkSession();
195175
return;
196176
}
197-
177+
198178
if (!this.uploadApproved) {
199179
await this.checkApproval();
200180
return;
@@ -203,12 +183,12 @@ abstract class BundlesModule extends LoginModule
203183
const bundle = await this.startCollectingFiles(path);
204184
const removedFiles = (this.files || []).filter(f => !bundle.includes(f));
205185
this.files = bundle;
206-
186+
207187
this.serviceAI.analyse({
208-
baseURL: this.baseURL,
209-
sessionToken: this.token,
210-
baseDir: path,
211-
files: this.files,
188+
baseURL: this.baseURL,
189+
sessionToken: this.token,
190+
baseDir: path,
191+
files: this.files,
212192
removedFiles: removedFiles
213193
}).catch(
214194
// no need to wait for processError since catch is called asynchronously as well
@@ -222,7 +202,6 @@ abstract class BundlesModule extends LoginModule
222202
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.COLLECTING, 0);
223203
console.log("COLLECTING");
224204
const bundle = await createListOfDirFiles({
225-
serverFilesFilterList,
226205
path: folderPath,
227206
progress: {
228207
onProgress: this.onCollectBundleProgress.bind(this),
@@ -235,7 +214,7 @@ abstract class BundlesModule extends LoginModule
235214

236215
private async createSingleHashBundle(
237216
path: string
238-
): Promise<DeepCode.BundlesInterface> {
217+
): Promise<IBundles> {
239218
this.rootPath = path;
240219

241220
// convert string[] to BundleInterface
@@ -280,7 +259,7 @@ abstract class BundlesModule extends LoginModule
280259
// processing remote server bundles
281260
public async updateExtensionRemoteBundles(
282261
workspacePath: string,
283-
bundle: DeepCode.RemoteBundleInterface | null = null
262+
bundle: IRemoteBundle | null = null
284263
): Promise<void> {
285264
if (bundle) {
286265
this.remoteBundles[workspacePath] = { ...bundle };

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import DeepCode from "../../../interfaces/DeepCodeInterfaces";
33
import BundlesModule from "./BundlesModule";
44
import { DEEPCODE_CONTEXT, DEEPCODE_MODE_CODES } from "../../constants/views";
55
import { errorsLogs } from "../../messages/errorsServerLogMessages";
6-
import {
6+
import {
77
EXECUTION_DEBOUNCE_INTERVAL,
88
EXECUTION_THROTTLING_INTERVAL,
9-
EXECUTION_PAUSE_INTERVAL,
9+
EXECUTION_PAUSE_INTERVAL,
1010
} from "../../constants/general";
1111

1212
export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepCodeLibInterface {
@@ -19,19 +19,19 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
1919
if (this._mode !== DEEPCODE_MODE_CODES.THROTTLED) return false;
2020
const now = Date.now();
2121
if (
22-
this._lastThrottledExecution === undefined ||
22+
this._lastThrottledExecution === undefined ||
2323
(now - this._lastThrottledExecution) >= EXECUTION_THROTTLING_INTERVAL
2424
) {
2525
this._lastThrottledExecution = now;
2626
return false;
2727
}
2828
return true;
2929
}
30-
30+
3131
private unpause(): void {
3232
if (this._mode === DEEPCODE_MODE_CODES.PAUSED) this.setMode(DEEPCODE_MODE_CODES.AUTO);
3333
}
34-
34+
3535
activateAll(): void {
3636
// this.filesWatcher.activate(this);
3737
this.workspacesWatcher.activate(this);
@@ -45,38 +45,41 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
4545
await this.setContext(DEEPCODE_CONTEXT.ERROR, false);
4646
this.resetTransientErrors();
4747
await this.setLoadingBadge(false);
48-
48+
4949
if (!this.token) return;
5050
const approved = await this.checkApproval();
5151
if (!approved) return;
52-
52+
5353
await this.startAnalysis();
5454
}
5555

56-
// This function is called by commands, error handlers, etc.
57-
// We should avoid having duplicate parallel executions.
58-
startExtension = _.debounce(
59-
async (manual = false): Promise<void> => {
60-
// If the execution is suspended, we only allow user-triggered analyses.
61-
if (!manual) {
62-
if ([
63-
DEEPCODE_MODE_CODES.MANUAL,
64-
DEEPCODE_MODE_CODES.PAUSED
65-
].includes(this._mode) ||
66-
this.shouldBeThrottled()
67-
) return;
68-
}
69-
try {
70-
await this.executeExtensionPipeline();
71-
} catch (err) {
72-
await this.processError(err, {
73-
message: errorsLogs.failedExecutionDebounce,
74-
});
75-
}
76-
},
77-
EXECUTION_DEBOUNCE_INTERVAL,
78-
{ 'leading': true }
79-
);
56+
public async startExtension(manual: Boolean = false): Promise<void> {
57+
// If the execution is suspended, we only allow user-triggered analyses.
58+
if (!manual) {
59+
if ([
60+
DEEPCODE_MODE_CODES.MANUAL,
61+
DEEPCODE_MODE_CODES.PAUSED
62+
].includes(this._mode) ||
63+
this.shouldBeThrottled()
64+
) return;
65+
}
66+
67+
// This function is called by commands, error handlers, etc.
68+
// We should avoid having duplicate parallel executions.
69+
_.debounce(
70+
async () => {
71+
try {
72+
await this.executeExtensionPipeline();
73+
} catch (err) {
74+
await this.processError(err, {
75+
message: errorsLogs.failedExecutionDebounce,
76+
});
77+
}
78+
},
79+
EXECUTION_DEBOUNCE_INTERVAL,
80+
{ 'leading': true }
81+
);
82+
};
8083

8184
async setMode(mode: string): Promise<void> {
8285
if (!Object.values(DEEPCODE_MODE_CODES).includes(mode)) return;

0 commit comments

Comments
 (0)