Skip to content

Commit 561fd68

Browse files
author
Kapil Borle
committedDec 9, 2016
Notify if extension uses PSSA settings file
1 parent 5389d49 commit 561fd68

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed
 

‎src/checkboxQuickPick.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,58 @@
55
import vscode = require("vscode");
66
import QuickPickItem = vscode.QuickPickItem;
77

8-
export interface ICheckboxOption {
8+
export class CheckboxQuickPickItem {
99
name: string;
1010
isSelected: boolean;
1111
}
1212

1313
export class CheckboxQuickPick {
14-
private options: ICheckboxOption[];
14+
private options: CheckboxQuickPickItem[];
1515
private readonly confirm: string;
1616
private readonly checkboxOn: string;
1717
private readonly checkboxOff: string;
1818
private readonly confirmPlaceHolder: string;
1919

20-
constructor(options: ICheckboxOption[]) {
20+
constructor(options: CheckboxQuickPickItem[]) {
2121
this.options = options;
2222
this.confirm = "$(check)";
2323
this.checkboxOn = "[ x ]";
2424
this.checkboxOff = "[ ]";
25-
this.confirmPlaceHolder = "Select " + this.confirm + " to confirm";
25+
this.confirmPlaceHolder = "Select 'Confirm' to confirm";
2626
}
2727

28-
public show(callback: (options: ICheckboxOption[]) => void): void {
29-
let tempOptions: ICheckboxOption[] = this.options.slice();
28+
public show(callback: (options: CheckboxQuickPickItem[]) => void): void {
29+
let tempOptions: CheckboxQuickPickItem[] = this.options.slice();
3030
this.showInner(tempOptions, callback);
3131
}
3232

33-
private showInner(tempOptions: ICheckboxOption[], callback: (options: ICheckboxOption[]) => void): void {
34-
vscode.window.showQuickPick(
35-
this.getQuickPickItems(tempOptions),
36-
{ ignoreFocusOut: true, placeHolder: this.confirmPlaceHolder }).then((selection) => {
37-
if (!selection) {
38-
return;
39-
}
33+
private showInner(
34+
tempOptions: CheckboxQuickPickItem[],
35+
callback: (options: CheckboxQuickPickItem[]) => void): void {
36+
vscode.window.showQuickPick(
37+
this.getQuickPickItems(tempOptions),
38+
{ ignoreFocusOut: true, placeHolder: this.confirmPlaceHolder }).then((selection) => {
39+
if (!selection) {
40+
return;
41+
}
4042

41-
if (selection.label == this.confirm) {
42-
callback(tempOptions);
43-
this.options = tempOptions;
44-
return;
45-
}
43+
if (selection.label == this.confirm) {
44+
callback(tempOptions);
45+
this.options = tempOptions;
46+
return;
47+
}
4648

47-
let index: number = this.getRuleIndex(tempOptions, selection.description);
48-
this.toggleOption(tempOptions[index]);
49-
this.showInner(tempOptions, callback);
50-
});
49+
let index: number = this.getRuleIndex(tempOptions, selection.description);
50+
this.toggleOption(tempOptions[index]);
51+
this.showInner(tempOptions, callback);
52+
});
5153
}
5254

53-
private getRuleIndex(options: ICheckboxOption[], optionLabel: string): number {
55+
private getRuleIndex(options: CheckboxQuickPickItem[], optionLabel: string): number {
5456
return options.findIndex(opt => opt.name == optionLabel);
5557
}
5658

57-
private getQuickPickItems(tempOptions: ICheckboxOption[]): QuickPickItem[] {
59+
private getQuickPickItems(tempOptions: CheckboxQuickPickItem[]): QuickPickItem[] {
5860
let quickPickItems: QuickPickItem[] = [];
5961
tempOptions.forEach(option =>
6062
quickPickItems.push({
@@ -72,7 +74,7 @@ export class CheckboxQuickPick {
7274
return !state;
7375
}
7476

75-
private toggleOption(option: ICheckboxOption): void {
77+
private toggleOption(option: CheckboxQuickPickItem): void {
7678
option.isSelected = this.toggleState(option.isSelected);
7779
}
7880

‎src/features/SelectPSSARules.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import vscode = require("vscode");
66
import { IFeature } from "../feature";
77
import { LanguageClient, RequestType } from "vscode-languageclient";
8-
import { ICheckboxOption, CheckboxQuickPick } from "../checkboxQuickPick";
8+
import { CheckboxQuickPickItem, CheckboxQuickPick } from "../checkboxQuickPick";
99

1010
export namespace GetPSSARulesRequest {
1111
export const type: RequestType<any, any, void> = { get method(): string { return "powerShell/getPSSARules"; } };
@@ -33,13 +33,18 @@ export class SelectPSSARulesFeature implements IFeature {
3333
}
3434

3535
this.languageClient.sendRequest(GetPSSARulesRequest.type, null).then((returnedRules) => {
36-
let options: ICheckboxOption[] = returnedRules.map(function (rule: IRuleInfo): ICheckboxOption {
36+
if (returnedRules == null) {
37+
vscode.window.showWarningMessage(
38+
"PowerShell extension uses PSScriptAnalyzer settings file - Cannot update rules.");
39+
return;
40+
}
41+
let options: CheckboxQuickPickItem[] = returnedRules.map(function (rule: IRuleInfo): CheckboxQuickPickItem {
3742
return { name: rule.name, isSelected: rule.isEnabled };
3843
});
3944
(new CheckboxQuickPick(options)).show((updatedOptions) => {
4045
this.languageClient.sendRequest(
4146
SetPSSARulesRequest.type,
42-
updatedOptions.map(function (option: ICheckboxOption): IRuleInfo {
47+
updatedOptions.map(function (option: CheckboxQuickPickItem): IRuleInfo {
4348
return { name: option.name, isEnabled: option.isSelected };
4449
}));
4550
});

0 commit comments

Comments
 (0)