Skip to content

Commit cc47c1a

Browse files
committed
Enable 'strictNullChecks' (with some necessary refactoring)
1 parent e10b657 commit cc47c1a

27 files changed

+344
-349
lines changed

src/controls/checkboxQuickPick.ts

+33-44
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,17 @@ export interface ICheckboxQuickPickOptions {
1818
confirmPlaceHolder: string;
1919
}
2020

21-
const defaultOptions: ICheckboxQuickPickOptions = { confirmPlaceHolder: defaultPlaceHolder};
21+
const defaultOptions: ICheckboxQuickPickOptions = { confirmPlaceHolder: defaultPlaceHolder };
2222

23-
export function showCheckboxQuickPick(
23+
export async function showCheckboxQuickPick(
2424
items: ICheckboxQuickPickItem[],
25-
options: ICheckboxQuickPickOptions = defaultOptions): Thenable<ICheckboxQuickPickItem[]> {
26-
27-
return showInner(items, options).then(
28-
(selectedItem) => {
29-
// We're mutating the original item list so just return it for now.
30-
// If 'selectedItem' is undefined it means the user cancelled the
31-
// inner showQuickPick UI so pass the undefined along.
32-
return selectedItem !== undefined ? items : undefined;
33-
});
25+
options: ICheckboxQuickPickOptions = defaultOptions): Promise<ICheckboxQuickPickItem[] | undefined> {
26+
27+
const selectedItem = await showInner(items, options);
28+
return selectedItem !== undefined ? items : undefined;
3429
}
3530

3631
function getQuickPickItems(items: ICheckboxQuickPickItem[]): vscode.QuickPickItem[] {
37-
3832
const quickPickItems: vscode.QuickPickItem[] = [];
3933
quickPickItems.push({ label: confirmItemLabel, description: "" });
4034

@@ -48,40 +42,35 @@ function getQuickPickItems(items: ICheckboxQuickPickItem[]): vscode.QuickPickIte
4842
return quickPickItems;
4943
}
5044

51-
function showInner(
45+
async function showInner(
5246
items: ICheckboxQuickPickItem[],
53-
options: ICheckboxQuickPickOptions): Thenable<vscode.QuickPickItem> {
54-
55-
const quickPickThenable: Thenable<vscode.QuickPickItem> =
56-
vscode.window.showQuickPick(
57-
getQuickPickItems(items),
58-
{
59-
ignoreFocusOut: true,
60-
matchOnDescription: true,
61-
placeHolder: options.confirmPlaceHolder,
62-
});
63-
64-
return quickPickThenable.then(
65-
(selection) => {
66-
if (!selection) {
67-
return Promise.resolve<vscode.QuickPickItem>(undefined);
68-
}
69-
70-
if (selection.label === confirmItemLabel) {
71-
return selection;
72-
}
73-
74-
const index: number = getItemIndex(items, selection.label);
75-
76-
if (index >= 0) {
77-
toggleSelection(items[index]);
78-
} else {
79-
// tslint:disable-next-line:no-console
80-
console.log(`Couldn't find CheckboxQuickPickItem for label '${selection.label}'`);
81-
}
82-
83-
return showInner(items, options);
47+
options: ICheckboxQuickPickOptions): Promise<vscode.QuickPickItem | undefined> {
48+
49+
const selection = await vscode.window.showQuickPick(
50+
getQuickPickItems(items),
51+
{
52+
ignoreFocusOut: true,
53+
matchOnDescription: true,
54+
placeHolder: options.confirmPlaceHolder,
8455
});
56+
57+
if (selection === undefined) {
58+
return undefined;
59+
}
60+
61+
if (selection.label === confirmItemLabel) {
62+
return selection;
63+
}
64+
65+
const index: number = getItemIndex(items, selection.label);
66+
if (index >= 0) {
67+
toggleSelection(items[index]);
68+
} else {
69+
// tslint:disable-next-line:no-console
70+
console.log(`Couldn't find CheckboxQuickPickItem for label '${selection.label}'`);
71+
}
72+
73+
return showInner(items, options);
8574
}
8675

8776
function getItemIndex(items: ICheckboxQuickPickItem[], itemLabel: string): number {

src/features/CodeActions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class CodeActionsFeature implements vscode.Disposable {
1111

1212
constructor(private log: ILogger) {
1313
this.applyEditsCommand = vscode.commands.registerCommand("PowerShell.ApplyCodeActionEdits", (edit: any) => {
14-
Window.activeTextEditor.edit((editBuilder) => {
14+
Window.activeTextEditor?.edit((editBuilder) => {
1515
editBuilder.replace(
1616
new vscode.Range(
1717
edit.StartLineNumber - 1,

src/features/Console.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ interface IShowChoicePromptRequestArgs {
5050
}
5151

5252
interface IShowChoicePromptResponseBody {
53-
responseText: string;
53+
responseText: string | undefined;
5454
promptCancelled: boolean;
5555
}
5656

5757
interface IShowInputPromptResponseBody {
58-
responseText: string;
58+
responseText: string | undefined;
5959
promptCancelled: boolean;
6060
}
6161

@@ -119,11 +119,12 @@ function showChoicePrompt(promptDetails: IShowChoicePromptRequestArgs): Thenable
119119
return resultThenable;
120120
}
121121

122-
function showInputPrompt(promptDetails: IShowInputPromptRequestArgs): Thenable<IShowInputPromptResponseBody> {
123-
return vscode.window.showInputBox({ placeHolder: promptDetails.name + ": " }).then(onInputEntered);
122+
async function showInputPrompt(promptDetails: IShowInputPromptRequestArgs): Promise<IShowInputPromptResponseBody> {
123+
const responseText = await vscode.window.showInputBox({ placeHolder: promptDetails.name + ": " });
124+
return onInputEntered(responseText);
124125
}
125126

126-
function onItemsSelected(chosenItems: ICheckboxQuickPickItem[]): IShowChoicePromptResponseBody {
127+
function onItemsSelected(chosenItems: ICheckboxQuickPickItem[] | undefined): IShowChoicePromptResponseBody {
127128
if (chosenItems !== undefined) {
128129
return {
129130
promptCancelled: false,
@@ -138,7 +139,7 @@ function onItemsSelected(chosenItems: ICheckboxQuickPickItem[]): IShowChoiceProm
138139
}
139140
}
140141

141-
function onItemSelected(chosenItem: vscode.QuickPickItem): IShowChoicePromptResponseBody {
142+
function onItemSelected(chosenItem: vscode.QuickPickItem | undefined): IShowChoicePromptResponseBody {
142143
if (chosenItem !== undefined) {
143144
return {
144145
promptCancelled: false,
@@ -153,7 +154,7 @@ function onItemSelected(chosenItem: vscode.QuickPickItem): IShowChoicePromptResp
153154
}
154155
}
155156

156-
function onInputEntered(responseText: string): IShowInputPromptResponseBody {
157+
function onInputEntered(responseText: string | undefined): IShowInputPromptResponseBody {
157158
if (responseText !== undefined) {
158159
return {
159160
promptCancelled: false,
@@ -190,6 +191,10 @@ export class ConsoleFeature extends LanguageClientConsumer {
190191
}
191192

192193
const editor = vscode.window.activeTextEditor;
194+
if (editor === undefined) {
195+
return;
196+
}
197+
193198
let selectionRange: vscode.Range;
194199

195200
if (!editor.selection.isEmpty) {

0 commit comments

Comments
 (0)