@@ -16,6 +16,11 @@ interface LabelToCheckboxMap {
16
16
[ Label : string ] : string ;
17
17
}
18
18
19
+ interface RuleInfo {
20
+ Name : string ;
21
+ IsEnabled : boolean ;
22
+ }
23
+
19
24
export class SelectPSSARulesFeature implements IFeature {
20
25
21
26
private command : vscode . Disposable ;
@@ -35,19 +40,21 @@ export class SelectPSSARulesFeature implements IFeature {
35
40
var cwr = doc . getWordRangeAtPosition ( selection . active )
36
41
var text = doc . getText ( cwr ) ;
37
42
38
- let rules : string [ ] = [ ] ;
43
+ let rules : RuleInfo [ ] = [ ] ;
39
44
this . languageClient . sendRequest ( GetPSSARulesRequest . type , null ) . then ( ( returnedRules ) => {
40
- returnedRules . forEach ( item => rules . push ( item ) )
41
- let ruleSelectionMap = new Map < string , boolean > ( ) ;
42
- rules . forEach ( rule => ruleSelectionMap [ rule ] = false ) ;
43
- ruleSelectionMap = this . GetSelections ( rules , ruleSelectionMap ) ;
45
+ for ( var index = 0 ; index < returnedRules . length ; index ++ ) {
46
+ var element = returnedRules [ index ] ;
47
+ rules . push ( { Name : element . name , IsEnabled : element . isEnabled } )
48
+ }
49
+
50
+ this . GetSelections ( rules ) ;
44
51
} ) ;
45
52
} ) ;
46
53
}
47
54
48
- private GetSelections ( rules : string [ ] , ruleSelectionMap : Map < string , boolean > ) : Map < string , boolean >
55
+ private GetSelections ( rules : RuleInfo [ ] )
49
56
{
50
- vscode . window . showQuickPick ( this . GetQuickPickItems ( rules , ruleSelectionMap ) )
57
+ vscode . window . showQuickPick ( this . GetQuickPickItems ( rules ) )
51
58
. then ( ( selection ) => {
52
59
if ( ! selection )
53
60
{
@@ -56,24 +63,28 @@ export class SelectPSSARulesFeature implements IFeature {
56
63
57
64
if ( selection . label == figures . tick )
58
65
{
59
- vscode . window . showInformationMessage ( "yes!" ) ;
60
66
return ;
61
67
}
62
68
63
- ruleSelectionMap [ selection . description ] = this . ToggleState ( ruleSelectionMap [ selection . description ] ) ;
64
- this . GetSelections ( rules , ruleSelectionMap ) ;
69
+ let index = this . GetRuleIndex ( rules , selection . description ) ;
70
+ rules [ index ] . IsEnabled = this . ToggleState ( rules [ index ] . IsEnabled ) ;
71
+ this . GetSelections ( rules ) ;
65
72
} ) ;
66
- return ruleSelectionMap ;
73
+ }
74
+
75
+ private GetRuleIndex ( rules : RuleInfo [ ] , ruleName : string ) : number
76
+ {
77
+ return rules . findIndex ( rule => rule . Name == ruleName ) ;
67
78
}
68
79
69
80
private GetCheckBoxOn ( ) : string
70
81
{
71
- return figures . checkboxOn ;
82
+ return "[ x ]" ; // this looks better than figure .checkboxOn
72
83
}
73
84
74
85
private GetCheckBoxOff ( ) : string
75
86
{
76
- return figures . checkboxOff ;
87
+ return "[ ]" ; // this looks better than figure .checkboxOff
77
88
}
78
89
79
90
private ConvertToState ( checkBox : string ) : boolean
@@ -103,9 +114,12 @@ export class SelectPSSARulesFeature implements IFeature {
103
114
}
104
115
}
105
116
106
- private GetQuickPickItems ( items : string [ ] , itemsMap : Map < string , boolean > ) : QuickPickItem [ ] {
117
+ private GetQuickPickItems ( rules : RuleInfo [ ] ) : QuickPickItem [ ] {
107
118
let qItems : QuickPickItem [ ] = [ ] ;
108
- items . forEach ( item => qItems . push ( { label : this . ConvertToCheckBox ( itemsMap [ item ] ) , description : item } ) ) ;
119
+ for ( var index = 0 ; index < rules . length ; index ++ ) {
120
+ var element = rules [ index ] ;
121
+ qItems . push ( { label : this . ConvertToCheckBox ( element . IsEnabled ) , description : element . Name } )
122
+ }
109
123
qItems . push ( { label : figures . tick , description : "confirm" } ) ;
110
124
return qItems ;
111
125
}
@@ -117,6 +131,4 @@ export class SelectPSSARulesFeature implements IFeature {
117
131
public dispose ( ) {
118
132
this . command . dispose ( ) ;
119
133
}
120
-
121
-
122
134
}
0 commit comments