Skip to content

Commit 07cca8d

Browse files
committed
Merge branch 'master' into suggestion-view-merge
# Conflicts: # src/deepcode/DeepCodeExtension.ts
2 parents 1734619 + ccaa7e2 commit 07cca8d

6 files changed

Lines changed: 46 additions & 11 deletions

File tree

src/deepcode/DeepCodeExtension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import * as vscode from 'vscode';
22
import * as _ from "lodash";
33
import open from 'open';
44

5+
import { emitter, ISupportedFiles } from '@deepcode/tsc';
56
import { ExtensionInterface } from '../interfaces/DeepCodeInterfaces';
67
import DeepCodeLib from './lib/modules/DeepCodeLib';
78
import createFileWatcher from './lib/watchers/FilesWatcher';
89
import { COMMAND_DEBOUNCE_INTERVAL } from "./constants/general";
9-
import { emitter, ISupportedFiles } from '@deepcode/tsc';
1010
import {
1111
DEEPCODE_START_COMMAND,
1212
DEEPCODE_SETMODE_COMMAND,
@@ -170,7 +170,7 @@ class DeepCodeExtension extends DeepCodeLib implements ExtensionInterface {
170170
}
171171

172172
onSupportedFilesLoaded(data: ISupportedFiles | null) {
173-
const msg = !!data ? 'Ignore rules loading' : 'Loading';
173+
const msg = data ? 'Ignore rules loading' : 'Loading';
174174

175175
this.updateStatus(DEEPCODE_ANALYSIS_STATUS.FILTERS, msg);
176176

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import { analyzeFolders, extendAnalysis } from '@deepcode/tsc';
1111
abstract class BundlesModule extends LoginModule implements BundlesModuleInterface {
1212
runningAnalysis = false;
1313

14+
private lastAnalysisStartingTimestamp = Date.now();
15+
lastAnalysisDuration = 0;
16+
lastAnalysisTimestamp = Date.now();
17+
1418
files: string[] = [];
1519

1620
updateStatus(status: string, progress: string) {
@@ -57,6 +61,7 @@ abstract class BundlesModule extends LoginModule implements BundlesModuleInterfa
5761
return;
5862
}
5963
this.runningAnalysis = true;
64+
this.lastAnalysisStartingTimestamp = Date.now();
6065

6166
let result;
6267
if (this.changedFiles.size && this.remoteBundle) {
@@ -85,6 +90,8 @@ abstract class BundlesModule extends LoginModule implements BundlesModuleInterfa
8590
});
8691
} finally {
8792
this.runningAnalysis = false;
93+
this.lastAnalysisTimestamp = Date.now();
94+
this.lastAnalysisDuration = this.lastAnalysisTimestamp - this.lastAnalysisStartingTimestamp;
8895
}
8996
}
9097
}

src/deepcode/lib/modules/LoginModule.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const sleep = (duration: number) => new Promise(resolve => setTimeout(resolve, d
1414

1515
abstract class LoginModule extends ReportModule implements LoginModuleInterface {
1616
private pendingLogin: boolean = false;
17+
private pendingToken = '';
1718

1819
async initiateLogin(): Promise<void> {
1920
await this.setContext(DEEPCODE_CONTEXT.LOGGEDIN, false);
@@ -26,8 +27,22 @@ abstract class LoginModule extends ReportModule implements LoginModuleInterface
2627
try {
2728
const checkCurrentToken = await this.checkSession();
2829
if (checkCurrentToken) return;
30+
31+
// In case we already created a draft token earlier, check if it's confirmed already
32+
if (this.pendingToken) {
33+
try {
34+
const confirmedPendingToken = await this.checkSession(this.pendingToken);
35+
if (confirmedPendingToken) {
36+
await this.setToken(this.pendingToken);
37+
return;
38+
}
39+
} finally {
40+
this.pendingToken = '';
41+
}
42+
}
43+
2944
const response = await startSession({ baseURL: this.baseURL, source: this.source });
30-
if (response.type == 'error') {
45+
if (response.type === 'error') {
3146
throw new Error(errorsLogs.login);
3247
}
3348

@@ -37,6 +52,8 @@ abstract class LoginModule extends ReportModule implements LoginModuleInterface
3752
const confirmed = await this.waitLoginConfirmation(sessionToken);
3853
if (confirmed) {
3954
await this.setToken(sessionToken);
55+
} else {
56+
this.pendingToken = sessionToken;
4057
}
4158
} catch (err) {
4259
await this.processError(err, {
@@ -51,10 +68,15 @@ abstract class LoginModule extends ReportModule implements LoginModuleInterface
5168
let validSession = false;
5269
if (token || this.token) {
5370
try {
54-
validSession = !!(await checkSession({
71+
const sessionResponse = await checkSession({
5572
baseURL: this.baseURL,
5673
sessionToken: token || this.token,
57-
}));
74+
});
75+
if (sessionResponse.type === 'error') {
76+
validSession = false;
77+
} else {
78+
validSession = sessionResponse.value;
79+
}
5880
} catch (err) {
5981
await this.processError(err, {
6082
message: errorsLogs.loginStatus,

src/deepcode/view/IssueProvider.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,16 @@ export class IssueProvider extends NodeProvider {
128128
}),
129129
);
130130
} else {
131-
review.unshift(
132-
new Node({
133-
text: `DeepCode found ${!nIssues ? 'no issue! ✅' : `${nIssues} issue${nIssues === 1 ? '' : 's'}`}`,
134-
}),
135-
);
131+
review.unshift(new Node({
132+
text: `DeepCode found ${!nIssues ? 'no issues! ✅' : `${nIssues} issue${nIssues === 1 ? '' : 's'}`}`,
133+
}));
134+
const sDuration = Math.round((this.extension.lastAnalysisDuration / 1000 + Number.EPSILON) * 100) / 100;
135+
const ts = new Date(this.extension.lastAnalysisTimestamp);
136+
const time = ts.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
137+
const day = ts.toLocaleDateString([], { year: "2-digit", month: "2-digit", day: "2-digit" });
138+
review.unshift(new Node({
139+
text: `Analysis took ${sDuration}s, finished at ${time}, ${day}`,
140+
}));
136141
}
137142
return review;
138143
}

src/interfaces/DeepCodeInterfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export interface LoginModuleInterface {
5656

5757
export interface BundlesModuleInterface {
5858
readonly runningAnalysis: boolean;
59+
readonly lastAnalysisDuration: number;
60+
readonly lastAnalysisTimestamp: number;
5961
startAnalysis(): Promise<void>;
6062
}
6163

src/test/runTest.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { runTests } from 'vscode-test';
44

55
async function main() {
66
try {
7-
87
console.log('STARTING TESTS');
98

109
// The folder containing the Extension Manifest package.json

0 commit comments

Comments
 (0)