Skip to content

Commit 9af6e08

Browse files
committed
Added ordering and analysis-status node.
1 parent e3061f9 commit 9af6e08

2 files changed

Lines changed: 49 additions & 15 deletions

File tree

src/deepcode/view/IssueProvider.ts

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,21 @@ interface ISeverityCounts {
99
}
1010

1111
export class IssueProvider extends NodeProvider {
12-
processProgress(progress: number) {
12+
compareNodes(n1: Node, n2: Node): number {
13+
if (n2.internal.severity - n1.internal.severity) return n2.internal.severity - n1.internal.severity;
14+
if (n2.internal.nIssues - n1.internal.nIssues) return n2.internal.nIssues - n1.internal.nIssues;
15+
if (n1.label && n2.label) {
16+
if (n1.label < n2.label) return -1;
17+
if (n1.label > n2.label) return 1;
18+
}
19+
if (n1.description && n2.description) {
20+
if (n1.description < n2.description) return -1;
21+
if (n1.description > n2.description) return 1;
22+
}
23+
return 0;
24+
}
25+
26+
processProgress(progress: number): string {
1327
return `${Math.round(100*progress)}%`;
1428
}
1529

@@ -21,25 +35,20 @@ export class IssueProvider extends NodeProvider {
2135
}[severity] || NODE_ICONS.info;
2236
}
2337

24-
getFileSeverityIcon(counts: ISeverityCounts): INodeIcon {
38+
getFileSeverity(counts: ISeverityCounts): number {
2539
for (const s of [
2640
DEEPCODE_SEVERITIES.error,
2741
DEEPCODE_SEVERITIES.warning,
2842
DEEPCODE_SEVERITIES.information,
2943
]) {
30-
if (counts[s]) return this.getSeverityIcon(s);
44+
if (counts[s]) return s;
3145
}
32-
return this.getSeverityIcon(DEEPCODE_SEVERITIES.information);
46+
return DEEPCODE_SEVERITIES.information;
3347
}
3448

3549
getRootChildren(): Node[] {
3650
const review: Node[] = [];
37-
if (this.extension.runningAnalysis) return [
38-
new Node({
39-
text: this.extension.analysisStatus,
40-
description: this.processProgress(this.extension.analysisProgress),
41-
})
42-
];
51+
let nIssues = 0;
4352
if (!this.extension.analyzer.deepcodeReview) return review;
4453
this.extension.analyzer.deepcodeReview.forEach(
4554
(uri: Uri, diagnostics: readonly Diagnostic[]): void => {
@@ -54,6 +63,7 @@ export class IssueProvider extends NodeProvider {
5463
const issues: Node[] = diagnostics.map((d) => {
5564
const severity = getDeepCodeSeverity(d.severity);
5665
++counts[severity];
66+
++nIssues;
5767
const params: {
5868
text: string, icon: INodeIcon, issue: { uri: Uri, range?: Range }, children?: Node[]
5969
} = {
@@ -77,16 +87,32 @@ export class IssueProvider extends NodeProvider {
7787
}
7888
return new Node(params);
7989
});
90+
const fileSeverity = this.getFileSeverity(counts);
8091
const file = new Node({
8192
text: filename,
82-
description: `${dir} - ${diagnostics.length} issue${diagnostics.length > 1 ? 's' : ''}`,
83-
icon: this.getFileSeverityIcon(counts),
93+
description: `${dir} - ${diagnostics.length} issue${diagnostics.length === 1 ? '' : 's'}`,
94+
icon: this.getSeverityIcon(fileSeverity),
8495
issue: { uri },
8596
children: issues,
97+
internal: {
98+
nIssues: diagnostics.length,
99+
severity: fileSeverity,
100+
}
86101
});
87102
review.push(file);
88103
}
89104
);
105+
review.sort(this.compareNodes);
106+
if (this.extension.runningAnalysis) {
107+
review.unshift(new Node({
108+
text: this.extension.analysisStatus,
109+
description: this.processProgress(this.extension.analysisProgress),
110+
}));
111+
} else {
112+
review.unshift(new Node({
113+
text: `DeepCode found ${nIssues} issue${nIssues === 1 ? '' : 's'}`,
114+
}));
115+
}
90116
return review;
91117
}
92118
}

src/deepcode/view/Node.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'path';
55
export interface INodeIcon {
66
['light']: string,
77
['dark']: string
8-
}
8+
};
99

1010
export const NODE_ICONS: {[key: string]: INodeIcon} = {
1111
critical: {
@@ -22,6 +22,8 @@ export const NODE_ICONS: {[key: string]: INodeIcon} = {
2222
},
2323
};
2424

25+
export type InternalType = {[key: string]: any};
26+
2527
export interface INodeOptions {
2628
text: string;
2729
description?: string;
@@ -36,10 +38,15 @@ export interface INodeOptions {
3638
collapsed?: TreeItemCollapsibleState;
3739
parent?: Node;
3840
children?: Node[];
39-
}
41+
internal?: InternalType,
42+
};
4043

44+
export type INode = TreeItem & {
45+
readonly internal: InternalType;
46+
};
4147

42-
export class Node extends TreeItem {
48+
export class Node extends TreeItem implements INode {
49+
readonly internal: {[key: string]: any};
4350
private parent: Node | undefined;
4451
private children: Node[] | undefined;
4552

@@ -72,6 +79,7 @@ export class Node extends TreeItem {
7279
// this.resourceUri = options.link ? Uri.parse(options.link) : (options.issue && options.issue.uri);
7380
this.parent = options.parent;
7481
this.children = options.children;
82+
this.internal = options.internal || {};
7583
}
7684

7785
getParent(): Node | undefined {

0 commit comments

Comments
 (0)