Skip to content

Commit d4196a2

Browse files
author
Arvid Paeglit
committed
refactoring of vscode: mostly removing trash
1 parent b3a0726 commit d4196a2

9 files changed

Lines changed: 69 additions & 106 deletions

File tree

src/deepcode/http/requests.ts

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

src/deepcode/lib/modules/BaseDeepCodeModule.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import { setContext } from "../../utils/vscodeCommandsUtils";
1313
import { DEEPCODE_VIEW_ANALYSIS } from "../../constants/views";
1414
import { errorsLogs } from '../../messages/errorsServerLogMessages';
1515
import { pendingMocks } from 'nock/types';
16+
import { IServiceAI, ServiceAI } from '@deepcode/tsc';
1617

1718
export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCodeModuleInterface {
19+
serviceAI: IServiceAI;
1820
currentWorkspacePath: string;
1921
workspacesPaths: Array<string>;
2022
hashesBundles: DeepCode.HashesBundlesInterface;
21-
serverFilesFilterList: DeepCode.AllowedServerFilterListInterface;
2223
remoteBundles: DeepCode.RemoteBundlesCollectionInterface;
2324
analyzer: DeepCode.AnalyzerInterface;
2425
statusBarItem: DeepCode.StatusBarItemInterface;
@@ -42,10 +43,10 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
4243
staticUploadApproved = false;
4344

4445
constructor() {
46+
this.serviceAI = new ServiceAI();
4547
this.currentWorkspacePath = "";
4648
this.workspacesPaths = [];
4749
this.hashesBundles = {};
48-
this.serverFilesFilterList = {};
4950
this.remoteBundles = {};
5051
this.analyzer = new DeepCodeAnalyzer();
5152
this.statusBarItem = new DeepCodeStatusBarItem();

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
22
import * as _ from "lodash";
3-
import http from "../../http/requests";
3+
44
import DeepCode from "../../../interfaces/DeepCodeInterfaces";
55
import { IQueueAnalysisCheckResult } from "@deepcode/tsc";
66
import { checkIfBundleIsEmpty } from "../../utils/bundlesUtils";
@@ -17,8 +17,7 @@ abstract class BundlesModule extends LoginModule
1717
runningAnalysis = false;
1818

1919
files: string[] = [];
20-
serviceAI = http.getServiceAI();
21-
20+
2221
constructor() {
2322
super();
2423

@@ -30,7 +29,30 @@ abstract class BundlesModule extends LoginModule
3029
this.onAnalyseFinish = this.onAnalyseFinish.bind(this);
3130
this.onError = this.onError.bind(this);
3231

33-
this.serviceAI.on(BUNDLE_EVENTS.error, this.onError);
32+
this.serviceAI.on(BUNDLE_EVENTS.buildBundleProgress, (processed: number, total: number) => {
33+
this.onBuildBundleProgress(processed, total);
34+
});
35+
this.serviceAI.on(BUNDLE_EVENTS.buildBundleFinish, () => {
36+
this.onBuildBundleFinish();
37+
});
38+
this.serviceAI.on(BUNDLE_EVENTS.uploadBundleProgress, (processed: number, total: number) => {
39+
this.onUploadBundleProgress(processed, total);
40+
});
41+
this.serviceAI.on(BUNDLE_EVENTS.uploadFilesFinish, () => {
42+
this.onUploadBundleFinish();
43+
});
44+
this.serviceAI.on(BUNDLE_EVENTS.analyseProgress, (analysisResults: IQueueAnalysisCheckResult) => {
45+
this.onAnalyseProgress(analysisResults);
46+
});
47+
this.serviceAI.on(
48+
BUNDLE_EVENTS.analyseFinish,
49+
(analysisResults: IQueueAnalysisCheckResult) => {
50+
this.onAnalyseFinish(analysisResults);
51+
}
52+
);
53+
this.serviceAI.on(BUNDLE_EVENTS.error, (error: Error) => {
54+
this.onError(error);
55+
});
3456
}
3557

3658
updateStatus(status: string, progress?: number) {
@@ -134,7 +156,10 @@ abstract class BundlesModule extends LoginModule
134156
// procesing filter list of files, acceptable for server
135157
public async createFilesFilterList(): Promise<void> {
136158
try {
137-
this.serverFilesFilterList = await http.getFilters(this.baseURL, this.token);
159+
this.serverFilesFilterList = await this.serviceAI.getFilters({
160+
baseURL: this.baseURL,
161+
sessionToken: this.token
162+
});
138163
} catch (err) {
139164
await this.processError(err, {
140165
message: errorsLogs.filtersFiles
@@ -165,53 +190,35 @@ abstract class BundlesModule extends LoginModule
165190
this.filesWatcher.activate(this);
166191
}
167192

168-
if (!this.token || !this.uploadApproved) {
193+
if (!this.token) {
169194
await this.checkSession();
195+
return;
196+
}
197+
198+
if (!this.uploadApproved) {
170199
await this.checkApproval();
171200
return;
172201
}
173202

174-
const bundle = await this.startCollectingFiles(path, this.serverFilesFilterList);
203+
const bundle = await this.startCollectingFiles(path);
175204
const removedFiles = (this.files || []).filter(f => !bundle.includes(f));
176205
this.files = bundle;
177206

178-
this.serviceAI.on(BUNDLE_EVENTS.buildBundleProgress, (processed: number, total: number) => {
179-
this.onBuildBundleProgress(processed, total);
180-
});
181-
this.serviceAI.on(BUNDLE_EVENTS.buildBundleFinish, () => {
182-
this.onBuildBundleFinish();
183-
});
184-
this.serviceAI.on(BUNDLE_EVENTS.uploadBundleProgress, (processed: number, total: number) => {
185-
this.onUploadBundleProgress(processed, total);
186-
});
187-
this.serviceAI.on(BUNDLE_EVENTS.uploadFilesFinish, () => {
188-
this.onUploadBundleFinish();
189-
});
190-
this.serviceAI.on(BUNDLE_EVENTS.analyseProgress, (analysisResults: IQueueAnalysisCheckResult) => {
191-
this.onAnalyseProgress(analysisResults);
192-
});
193-
this.serviceAI.on(
194-
BUNDLE_EVENTS.analyseFinish,
195-
(analysisResults: IQueueAnalysisCheckResult) => {
196-
this.onAnalyseFinish(analysisResults);
197-
}
198-
);
199-
this.serviceAI.on(BUNDLE_EVENTS.error, (error: Error) => {
200-
this.onError(error);
201-
});
202-
203-
http.analyse(this.baseURL, this.token, path, this.files, removedFiles).catch(
207+
this.serviceAI.analyse({
208+
baseURL: this.baseURL,
209+
sessionToken: this.token,
210+
baseDir: path,
211+
files: this.files,
212+
removedFiles: removedFiles
213+
}).catch(
204214
// no need to wait for processError since catch is called asynchronously as well
205215
(error) => this.processError(error, {
206216
message: errorsLogs.analyse
207217
})
208218
);
209219
}
210220

211-
private async startCollectingFiles(
212-
folderPath: string,
213-
serverFilesFilterList: DeepCode.AllowedServerFilterListInterface
214-
): Promise<string[]> {
221+
private async startCollectingFiles(folderPath: string): Promise<string[]> {
215222
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.COLLECTING, 0);
216223
console.log("COLLECTING");
217224
const bundle = await createListOfDirFiles({

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
4545
await this.setContext(DEEPCODE_CONTEXT.ERROR, false);
4646
await this.setLoadingBadge(false);
4747

48-
const loggedIn = await this.checkSession();
49-
if (!loggedIn) return;
48+
if (!this.token) return;
5049
const approved = await this.checkApproval();
5150
if (!approved) return;
5251
await this.startAnalysis();

src/deepcode/lib/modules/LoginModule.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from "vscode";
22
import ReportModule from "./ReportModule";
33
import DeepCode from "../../../interfaces/DeepCodeInterfaces";
4-
import http from "../../http/requests";
4+
55
import { viewInBrowser } from "../../utils/vscodeCommandsUtils";
66
import { DEEPCODE_CONTEXT } from "../../constants/views";
77
import { openDeepcodeViewContainer } from "../../utils/vscodeCommandsUtils";
@@ -22,7 +22,7 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
2222
try {
2323
const checkCurrentToken = await this.checkSession();
2424
if (checkCurrentToken) return;
25-
const result = await http.login(this.baseURL, this.source);
25+
const result = await this.serviceAI.startSession({ baseURL: this.baseURL, source: this.source });
2626
const { sessionToken, loginURL } = result;
2727
if (!sessionToken || !loginURL) {
2828
throw new Error(errorsLogs.login);
@@ -43,7 +43,10 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
4343
let validSession = false;
4444
if (this.token) {
4545
try {
46-
validSession = !!(await http.checkSession(this.baseURL, this.token));
46+
validSession = !!(await this.serviceAI.checkSession({
47+
baseURL: this.baseURL,
48+
sessionToken: this.token
49+
}));
4750
} catch (err) {
4851
await this.processError(err, {
4952
message: errorsLogs.loginStatus

src/deepcode/lib/modules/ReportModule.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import DeepCode from "../../../interfaces/DeepCodeInterfaces";
2-
import http from "../../http/requests";
32
import BaseDeepCodeModule from "./BaseDeepCodeModule";
43
import { statusCodes } from "../../constants/statusCodes";
54
import { errorsLogs } from "../../messages/errorsServerLogMessages";
@@ -24,7 +23,8 @@ abstract class ReportModule extends BaseDeepCodeModule implements DeepCode.Repor
2423
async sendError(options: {[key: string]: any}): Promise<void> {
2524
if (!this.shouldReport || !this.shouldReportErrors) return;
2625
try {
27-
await http.sendError(this.baseURL, {
26+
await this.serviceAI.reportError({
27+
baseURL: this.baseURL,
2828
source: this.source,
2929
...(this.token && { sessionToken: this.token }),
3030
...options
@@ -37,7 +37,8 @@ abstract class ReportModule extends BaseDeepCodeModule implements DeepCode.Repor
3737
async sendEvent(event: string, options: {[key: string]: any}): Promise<void> {
3838
if (!this.shouldReport || !this.shouldReportEvents) return;
3939
try {
40-
await http.sendEvent(this.baseURL, {
40+
await this.serviceAI.reportEvent({
41+
baseURL: this.baseURL,
4142
type: event,
4243
source: this.source,
4344
...(this.token && { sessionToken: this.token }),

src/deepcode/lib/watchers/DeepCodeFilesWatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class DeepCodeFilesWatcher implements DeepCode.DeepCodeWatcherInterface {
123123
type: string
124124
): Promise<void> {
125125
if (
126-
!acceptFileToBundle(filePath, extension.serverFilesFilterList) &&
126+
!acceptFileToBundle(filePath, extension.serviceAI.serverFilesFilterList) &&
127127
!isFileChangingBundle(filePath)
128128
) {
129129
return;

src/interfaces/DeepCodeInterfaces.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
} from "vscode";
99
import * as vscode from "vscode";
1010

11+
import { IServiceAI } from '@deepcode/tsc';
12+
1113
namespace DeepCode {
1214
export type userStateItemType = string | number | boolean | undefined;
1315

@@ -72,11 +74,6 @@ namespace DeepCode {
7274
[key: string]: RemoteBundleInterface;
7375
}
7476

75-
export interface AllowedServerFilterListInterface {
76-
extensions?: Array<string>;
77-
configFiles?: Array<string>;
78-
}
79-
8077
export interface SingleIssuePositionInterface {
8178
cols: Array<number>;
8279
rows: Array<number>;
@@ -164,10 +161,10 @@ namespace DeepCode {
164161
}
165162

166163
export interface BaseDeepCodeModuleInterface {
164+
serviceAI: IServiceAI;
167165
currentWorkspacePath: string;
168166
workspacesPaths: Array<string>;
169167
hashesBundles: HashesBundlesInterface;
170-
serverFilesFilterList: AllowedServerFilterListInterface;
171168
remoteBundles: RemoteBundlesCollectionInterface;
172169
refreshViewEmitter: vscode.EventEmitter<any>;
173170
refreshViews(content: any): void;

src/test/suite/extension.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import * as nock from "nock";
1010
import * as extension from "../../extension";
1111
import Deepcode from "../../interfaces/DeepCodeInterfaces";
1212

13-
import http from "../../deepcode/http/requests";
14-
1513
// mocked data for tests
1614
const testHost = "http://localhost:3000";
1715
const testHostPrefix = "/publicapi";
@@ -124,7 +122,13 @@ suite("Deepcode Extension Tests", () => {
124122

125123
test('Send files list to analyse', async () => {
126124
try {
127-
await http.analyse(testHost, testToken, mockedTestFilesDirPath, testFilesList);
125+
await testExtension.serviceAI.analyse({
126+
baseURL: testHost,
127+
sessionToken: testToken,
128+
baseDir: mockedTestFilesDirPath,
129+
files: testFilesList,
130+
removedFiles: []
131+
});
128132
assert.equal(true, true);
129133
} catch(error) {
130134
console.log(error);

0 commit comments

Comments
 (0)