Skip to content

Commit 6e6a20b

Browse files
author
Arvid Paeglit
committed
added error handling for 401 status code;
fixed showing results; fixed parsing of rules for interfile;
1 parent 9289562 commit 6e6a20b

10 files changed

Lines changed: 88 additions & 90 deletions

File tree

src/deepcode/constants/analysis.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,3 @@ export const ISSUES_MARKERS_DECORATION_TYPE: { [key: string]: string } = {
2323
borderColor: "green",
2424
borderStyle: "none none dashed none"
2525
};
26-
27-
export const ISSUE_ID_SPLITTER = "%2Fdc%2F";

src/deepcode/lib/analyzer/DeepCodeAnalyzer.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
createIssueRelatedInformation,
1313
createDeepCodeSeveritiesMap,
1414
getDeepCodeSeverity,
15-
extractSuggestionIdFromSuggestionsMap
16-
} from "../../utils/analysisUtils";
15+
findSuggestionByMessage,
16+
} from '../../utils/analysisUtils';
1717
import { DEEPCODE_NAME } from "../../constants/general";
1818
import { TELEMETRY_EVENTS } from "../../constants/telemetry";
1919
import { ISSUES_MARKERS_DECORATION_TYPE } from "../../constants/analysis";
@@ -38,7 +38,7 @@ class DeepCodeAnalyzer implements AnalyzerInterface {
3838
this.deepcodeReview = vscode.languages.createDiagnosticCollection(DEEPCODE_NAME);
3939

4040
new DisposableCodeActionsProvider(this.deepcodeReview, {
41-
findSuggestionId: this.findSuggestionId.bind(this),
41+
findSuggestion: this.findSuggestion.bind(this),
4242
trackIgnoreSuggestion: this.trackIgnoreSuggestion.bind(this),
4343
});
4444
new DisposableHoverProvider(this.deepcodeReview);
@@ -48,8 +48,8 @@ class DeepCodeAnalyzer implements AnalyzerInterface {
4848
this.extension = extension;
4949
}
5050

51-
public findSuggestionId(suggestionName: string): string {
52-
return extractSuggestionIdFromSuggestionsMap(this.analysisResults, suggestionName);
51+
public findSuggestion(suggestionName: string): ISuggestion | undefined {
52+
return findSuggestionByMessage(this.analysisResults, suggestionName);
5353
}
5454

5555
public trackIgnoreSuggestion(vscodeSeverity: number, options: { [key: string]: any }): void {
@@ -61,7 +61,11 @@ class DeepCodeAnalyzer implements AnalyzerInterface {
6161
this.extension.processEvent(TELEMETRY_EVENTS.ignoreSuggestion, options);
6262
}
6363

64-
private createIssueDiagnosticInfo({ issuePositions, suggestion, fileUri }: {
64+
private createIssueDiagnosticInfo({
65+
issuePositions,
66+
suggestion,
67+
fileUri,
68+
}: {
6569
issuePositions: IFileSuggestion;
6670
suggestion: ISuggestion;
6771
fileUri: vscode.Uri;
@@ -166,10 +170,7 @@ class DeepCodeAnalyzer implements AnalyzerInterface {
166170
) {
167171
return;
168172
}
169-
const fileIssuesList: IFilePath = await updateFileReviewResultsPositions(
170-
this.analysisResults,
171-
updatedFile,
172-
);
173+
const fileIssuesList: IFilePath = await updateFileReviewResultsPositions(this.analysisResults, updatedFile);
173174
// Opening a project directory instead of a workspace leads to empty updatedFile.workspace field
174175
const workspace = updatedFile.workspace;
175176
const filepath = updatedFile.filePathInWorkspace || updatedFile.fullPath.replace(workspace, '');

src/deepcode/lib/deepCodeProviders/codeActionsProvider/DeepCodeIssuesActionsProvider.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import * as vscode from "vscode";
2-
import {
3-
findIssueWithRange,
4-
ignoreIssueCommentText,
5-
extractIssueNameOutOfId
6-
} from "../../../utils/analysisUtils";
2+
import { findIssueWithRange, ignoreIssueCommentText } from '../../../utils/analysisUtils';
73
import {
84
IGNORE_ISSUE_ACTION_NAME,
95
FILE_IGNORE_ACTION_NAME,
@@ -18,13 +14,13 @@ export class DeepCodeIssuesActionProvider implements vscode.CodeActionProvider {
1814
public static readonly providedCodeActionKinds = [vscode.CodeActionKind.QuickFix];
1915

2016
private issuesList: vscode.DiagnosticCollection | undefined;
21-
private findSuggestionId: Function;
17+
private findSuggestion: Function;
2218
private trackIgnoreSuggestion: Function;
2319

2420
constructor(issuesList: vscode.DiagnosticCollection | undefined, callbacks: { [key: string]: Function }) {
2521
this.issuesList = issuesList;
2622
this.registerIgnoreIssuesCommand();
27-
this.findSuggestionId = callbacks.findSuggestionId;
23+
this.findSuggestion = callbacks.findSuggestion;
2824
this.trackIgnoreSuggestion = callbacks.trackIgnoreSuggestion;
2925
}
3026

@@ -111,8 +107,10 @@ export class DeepCodeIssuesActionProvider implements vscode.CodeActionProvider {
111107
DeepCodeIssuesActionProvider.providedCodeActionKinds[0],
112108
);
113109

114-
const issueFullId: string = this.findSuggestionId(matchedIssue.message);
115-
const issueNameForComment: string = extractIssueNameOutOfId(issueFullId);
110+
const suggestion = this.findSuggestion(matchedIssue.message);
111+
112+
const issueFullId: string = suggestion?.id;
113+
const issueNameForComment: string = suggestion?.rule;
116114
const issueText: string = ignoreIssueCommentText(issueNameForComment, isFileIgnore);
117115
ignoreIssueAction.command = {
118116
command: DEEPCODE_IGNORE_ISSUE_COMMAND,

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { BundlesModuleInterface } from "../../../interfaces/DeepCodeInterfaces";
66
import LoginModule from "../../lib/modules/LoginModule";
77
import { DEEPCODE_ANALYSIS_STATUS, DEEPCODE_CONTEXT } from "../../constants/views";
88
import { errorsLogs } from "../../messages/errorsServerLogMessages";
9+
import { statusCodes } from '../../constants/statusCodes';
910

10-
import { analyzeFolders } from '@deepcode/tsc';
11+
import { analyzeFolders, extendAnalysis } from '@deepcode/tsc';
1112

1213
abstract class BundlesModule extends LoginModule implements BundlesModuleInterface {
1314
runningAnalysis = false;
@@ -54,18 +55,26 @@ abstract class BundlesModule extends LoginModule implements BundlesModuleInterfa
5455
if (paths.length) {
5556
await this.setContext(DEEPCODE_CONTEXT.WORKSPACE_FOUND, true);
5657

57-
if (this.runningAnalysis) return;
58+
if (this.runningAnalysis) {
59+
return;
60+
}
5861
this.runningAnalysis = true;
5962

60-
const result = await analyzeFolders(this.baseURL, this.token, false, 1, paths);
63+
let result;
64+
if (this.changedFiles.size && this.remoteBundle) {
65+
const changedFiles = [...this.changedFiles];
66+
this.changedFiles.clear();
67+
result = await extendAnalysis(this.remoteBundle, changedFiles);
68+
} else {
69+
result = await analyzeFolders(this.baseURL, this.token, false, 1, paths);
70+
}
6171

6272
if (result) {
6373
this.remoteBundle = result;
6474

6575
this.analyzer.analysisResults = result.analysisResults;
6676
this.analyzer.createReviewResults();
6777

68-
this.runningAnalysis = false;
6978
this.refreshViews();
7079
}
7180
} else {
@@ -75,6 +84,8 @@ abstract class BundlesModule extends LoginModule implements BundlesModuleInterfa
7584
await this.processError(err, {
7685
message: errorsLogs.failedAnalysis,
7786
});
87+
} finally {
88+
this.runningAnalysis = false;
7889
}
7990
}
8091
}

src/deepcode/lib/modules/LoginModule.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ abstract class LoginModule extends ReportModule implements LoginModuleInterface
1616
private pendingLogin: boolean = false;
1717

1818
async initiateLogin(): Promise<void> {
19-
2019
await this.setContext(DEEPCODE_CONTEXT.LOGGEDIN, false);
2120

2221
if (this.pendingLogin) {
@@ -34,29 +33,31 @@ abstract class LoginModule extends ReportModule implements LoginModuleInterface
3433

3534
const { sessionToken, loginURL } = response.value;
3635

37-
await this.setToken(sessionToken);
3836
await viewInBrowser(loginURL);
39-
await this.waitLoginConfirmation();
37+
const confirmed = await this.waitLoginConfirmation(sessionToken);
38+
if (confirmed) {
39+
await this.setToken(sessionToken);
40+
}
4041
} catch (err) {
4142
await this.processError(err, {
42-
message: errorsLogs.login
43+
message: errorsLogs.login,
4344
});
4445
} finally {
4546
this.pendingLogin = false;
4647
}
4748
}
4849

49-
async checkSession(): Promise<boolean> {
50+
async checkSession(token = ''): Promise<boolean> {
5051
let validSession = false;
51-
if (this.token) {
52+
if (token || this.token) {
5253
try {
5354
validSession = !!(await checkSession({
5455
baseURL: this.baseURL,
55-
sessionToken: this.token,
56+
sessionToken: token || this.token,
5657
}));
5758
} catch (err) {
5859
await this.processError(err, {
59-
message: errorsLogs.loginStatus
60+
message: errorsLogs.loginStatus,
6061
});
6162
}
6263
}
@@ -65,17 +66,17 @@ abstract class LoginModule extends ReportModule implements LoginModuleInterface
6566
return validSession;
6667
}
6768

68-
private async waitLoginConfirmation(): Promise<void> {
69-
if (!this.token) return;
69+
private async waitLoginConfirmation(token: string): Promise<boolean> {
7070
// 20 attempts to wait for user's login & consent
7171
for (let i = 0; i < 20; i++) {
7272
await sleep(1000);
7373

74-
const confirmed = await this.checkSession();
74+
const confirmed = await this.checkSession(token);
7575
if (confirmed) {
76-
return;
76+
return true;
7777
}
7878
}
79+
return false;
7980
}
8081

8182
async checkApproval(): Promise<boolean> {
@@ -96,7 +97,7 @@ abstract class LoginModule extends ReportModule implements LoginModuleInterface
9697
this.processEvent(TELEMETRY_EVENTS.viewWelcomeNotification);
9798
let pressedButton = await vscode.window.showInformationMessage(
9899
deepCodeMessages.welcome.msg,
99-
deepCodeMessages.welcome.button
100+
deepCodeMessages.welcome.button,
100101
);
101102
if (pressedButton === deepCodeMessages.welcome.button) {
102103
await openDeepcodeViewContainer();

0 commit comments

Comments
 (0)