@@ -5,28 +5,17 @@ import {
5
5
ProblemsModel ,
6
6
MarkerSeverity ,
7
7
builtInStatusProblems ,
8
- builtInPanelProblems ,
9
8
} from 'mo/model/problems' ;
10
- import { IPanelItem } from 'mo/model/workbench/panel' ;
11
9
import { IStatusBarItem } from 'mo/model/workbench/statusBar' ;
12
- import {
13
- PanelService ,
14
- IPanelService ,
15
- StatusBarService ,
16
- IStatusBarService ,
17
- } from 'mo/services' ;
10
+ import { StatusBarService , IStatusBarService } from 'mo/services' ;
18
11
import { Component } from 'mo/react' ;
19
12
import { singleton , container } from 'tsyringe' ;
20
13
import { searchById } from './helper' ;
21
14
export interface IProblemsService extends Component < IProblems > {
22
- updateStatus < T > ( item : IStatusBarItem < T > ) : void ;
23
- updatePanel < T > ( item : IStatusBarItem < T > ) : void ;
24
- removeProblems ( id : number ) : void ;
15
+ removeProblems ( id : number | number [ ] ) : void ;
25
16
clearProblems ( ) : void ;
26
- addProblems ( item : IProblemsItem ) : void ;
27
- updateProblems < T > ( item : IProblemsItem < T > ) : void ;
28
- updateStatus ( item : IStatusBarItem ) : void ;
29
- updatePanel ( item : IPanelItem ) : void ;
17
+ addProblems ( item : IProblemsItem | IProblemsItem [ ] ) : void ;
18
+ updateProblems < T > ( item : IProblemsItem < T > | IProblemsItem < T > [ ] ) : void ;
30
19
showHideProblems ( ) : void ;
31
20
}
32
21
@@ -35,12 +24,10 @@ export class ProblemsService
35
24
extends Component < IProblems >
36
25
implements IProblemsService {
37
26
protected state : IProblems ;
38
- private readonly panelService : IPanelService ;
39
27
private readonly statusBarService : IStatusBarService ;
40
28
constructor ( ) {
41
29
super ( ) ;
42
30
this . state = container . resolve ( ProblemsModel ) ;
43
- this . panelService = container . resolve ( PanelService ) ;
44
31
this . statusBarService = container . resolve ( StatusBarService ) ;
45
32
}
46
33
@@ -50,85 +37,92 @@ export class ProblemsService
50
37
show : ! this . state . show ,
51
38
} ) ;
52
39
}
53
- public addProblems < T > ( item : IProblemsItem < T > ) : void {
40
+ public addProblems < T > ( item : IProblemsItem < T > | IProblemsItem < T > [ ] ) : void {
41
+ const problems = Array . isArray ( item ) ? item : [ item ] ;
54
42
const { data } = this . state ;
55
- const index = data . findIndex ( searchById ( item . id ) ) ;
56
- if ( index > - 1 ) {
57
- data . splice ( index , 1 , item ) ;
58
- } else {
59
- data . push ( item ) ;
60
- }
43
+
44
+ problems . forEach ( ( problem ) => {
45
+ const index = data . findIndex ( searchById ( problem . id ) ) ;
46
+ if ( index > - 1 ) {
47
+ data . splice ( index , 1 , problem ) ;
48
+ } else {
49
+ data . push ( problem ) ;
50
+ }
51
+ } ) ;
52
+
61
53
this . setState (
62
54
{
63
- ...this . state ,
64
55
data : [ ...data ] ,
65
56
} ,
66
57
( ) => {
67
- this . update ( ) ;
58
+ this . updateStatusBar ( ) ;
68
59
}
69
60
) ;
70
61
}
71
- public updateProblems < T > ( item : IProblemsItem < T > ) {
62
+ public updateProblems < T > ( item : IProblemsItem < T > | IProblemsItem < T > [ ] ) {
63
+ const problems = Array . isArray ( item ) ? item : [ item ] ;
72
64
const { data } = this . state ;
73
- const index = data . findIndex ( searchById ( item . id ) ) ;
74
- if ( index > - 1 ) {
75
- data . splice ( index , 1 , item ) ;
76
- this . setState (
77
- {
78
- ...this . state ,
79
- data : [ ...data ] ,
80
- } ,
81
- ( ) => {
82
- this . update ( ) ;
83
- }
84
- ) ;
85
- } else {
86
- this . addProblems ( item ) ;
87
- }
65
+
66
+ problems . forEach ( ( problem ) => {
67
+ const index = data . findIndex ( searchById ( problem . id ) ) ;
68
+ if ( index > - 1 ) {
69
+ data . splice ( index , 1 , problem ) ;
70
+ }
71
+ } ) ;
72
+
73
+ this . setState (
74
+ {
75
+ data : [ ...data ] ,
76
+ } ,
77
+ ( ) => {
78
+ this . updateStatusBar ( ) ;
79
+ }
80
+ ) ;
88
81
}
89
- public removeProblems ( id : number ) : void {
82
+ public removeProblems ( id : number | number [ ] ) : void {
83
+ const ids = Array . isArray ( id ) ? id : [ id ] ;
84
+
90
85
const { data = [ ] } = this . state ;
91
- if ( data . length > - 1 ) {
92
- const index = data . findIndex ( searchById ( id ) ) ;
86
+ ids . forEach ( ( problemId ) => {
87
+ const index = data . findIndex ( searchById ( problemId ) ) ;
93
88
if ( index > - 1 ) {
94
89
data . splice ( index , 1 ) ;
95
- this . setState (
96
- {
97
- ...this . state ,
98
- data : [ ...data ] ,
99
- } ,
100
- ( ) => {
101
- this . update ( ) ;
102
- }
103
- ) ;
104
90
}
105
- }
91
+ } ) ;
92
+
93
+ this . setState (
94
+ {
95
+ data : [ ...data ] ,
96
+ } ,
97
+ ( ) => {
98
+ this . updateStatusBar ( ) ;
99
+ }
100
+ ) ;
106
101
}
102
+
107
103
public clearProblems ( ) : void {
108
104
this . setState ( {
109
105
...this . state ,
110
106
data : [ ] ,
111
107
} ) ;
112
108
this . updateStatus ( builtInStatusProblems ( ) ) ;
113
- this . updatePanel ( builtInPanelProblems ( ) ) ;
114
109
}
115
- public update < T > ( ) : void {
110
+
111
+ private updateStatusBar < T > ( ) : void {
116
112
const { data = [ ] } = this . state ;
117
113
const markersData = this . getProblemsMarkers ( data ) ;
118
114
this . updateStatus (
119
115
Object . assign ( builtInStatusProblems ( ) , {
120
116
data : markersData ,
121
117
} )
122
118
) ;
123
- this . updatePanel ( Object . assign ( builtInPanelProblems ( ) , { data } ) ) ;
124
119
}
125
- public updateStatus < T > ( item : IStatusBarItem < T > ) : void {
120
+
121
+ private updateStatus < T > ( item : IStatusBarItem < T > ) : void {
126
122
this . statusBarService . updateItem ( item ) ;
127
123
}
128
- public updatePanel < T > ( item : IPanelItem < T > ) : void {
129
- this . panelService . update ( item ) ;
130
- }
131
- public getProblemsMarkers = (
124
+
125
+ private getProblemsMarkers = (
132
126
data : IProblemsItem [ ]
133
127
) : { warnings : number ; errors : number ; infos : number } => {
134
128
let warnings = 0 ;
0 commit comments