@@ -9,7 +9,21 @@ interface ISeverityCounts {
99}
1010
1111export 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}
0 commit comments