Skip to content

Commit bbc41f0

Browse files
author
Kapil Borle
committed
Get a list of active PSSA rules
1 parent 6324789 commit bbc41f0

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

src/features/SelectPSSARules.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ interface LabelToCheckboxMap {
1616
[Label: string]: string;
1717
}
1818

19+
interface RuleInfo {
20+
Name: string;
21+
IsEnabled: boolean;
22+
}
23+
1924
export class SelectPSSARulesFeature implements IFeature {
2025

2126
private command: vscode.Disposable;
@@ -35,19 +40,21 @@ export class SelectPSSARulesFeature implements IFeature {
3540
var cwr = doc.getWordRangeAtPosition(selection.active)
3641
var text = doc.getText(cwr);
3742

38-
let rules: string[] = [];
43+
let rules: RuleInfo[] = [];
3944
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);
4451
});
4552
});
4653
}
4754

48-
private GetSelections(rules: string[], ruleSelectionMap: Map<string,boolean>): Map<string,boolean>
55+
private GetSelections(rules: RuleInfo[])
4956
{
50-
vscode.window.showQuickPick(this.GetQuickPickItems(rules, ruleSelectionMap))
57+
vscode.window.showQuickPick(this.GetQuickPickItems(rules))
5158
.then((selection) =>{
5259
if (!selection)
5360
{
@@ -56,24 +63,28 @@ export class SelectPSSARulesFeature implements IFeature {
5663

5764
if (selection.label == figures.tick)
5865
{
59-
vscode.window.showInformationMessage("yes!");
6066
return;
6167
}
6268

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);
6572
});
66-
return ruleSelectionMap;
73+
}
74+
75+
private GetRuleIndex(rules: RuleInfo[], ruleName: string) : number
76+
{
77+
return rules.findIndex(rule => rule.Name == ruleName);
6778
}
6879

6980
private GetCheckBoxOn() : string
7081
{
71-
return figures.checkboxOn;
82+
return "[ x ]"; // this looks better than figure.checkboxOn
7283
}
7384

7485
private GetCheckBoxOff() : string
7586
{
76-
return figures.checkboxOff;
87+
return "[ ]"; // this looks better than figure.checkboxOff
7788
}
7889

7990
private ConvertToState(checkBox: string) : boolean
@@ -103,9 +114,12 @@ export class SelectPSSARulesFeature implements IFeature {
103114
}
104115
}
105116

106-
private GetQuickPickItems(items: string[], itemsMap: Map<string,boolean>): QuickPickItem[] {
117+
private GetQuickPickItems(rules: RuleInfo[]): QuickPickItem[] {
107118
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+
}
109123
qItems.push({label: figures.tick, description: "confirm"});
110124
return qItems;
111125
}
@@ -117,6 +131,4 @@ export class SelectPSSARulesFeature implements IFeature {
117131
public dispose() {
118132
this.command.dispose();
119133
}
120-
121-
122134
}

0 commit comments

Comments
 (0)