Skip to content

Commit 1ac10a0

Browse files
committed
Mostly enable 'strictPropertyInitialization'
1 parent 1b50b3d commit 1ac10a0

16 files changed

+196
-197
lines changed

src/features/Console.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function onInputEntered(responseText: string | undefined): IShowInputPromptRespo
170170

171171
export class ConsoleFeature extends LanguageClientConsumer {
172172
private commands: vscode.Disposable[];
173-
private handlers: vscode.Disposable[];
173+
private handlers: vscode.Disposable[] = [];
174174

175175
constructor(private log: Logger) {
176176
super();
@@ -203,7 +203,7 @@ export class ConsoleFeature extends LanguageClientConsumer {
203203
selectionRange = editor.document.lineAt(editor.selection.start.line).range;
204204
}
205205

206-
await this.languageClient.sendRequest(EvaluateRequestType, {
206+
await this.languageClient?.sendRequest(EvaluateRequestType, {
207207
expression: editor.document.getText(selectionRange),
208208
});
209209

src/features/CustomViews.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class HtmlContentView extends CustomView {
158158
styleSheetPaths: [],
159159
};
160160

161-
private webviewPanel: vscode.WebviewPanel;
161+
private webviewPanel: vscode.WebviewPanel | undefined;
162162

163163
constructor(
164164
id: string,
@@ -196,9 +196,7 @@ class HtmlContentView extends CustomView {
196196
}
197197

198198
public showContent(viewColumn: vscode.ViewColumn): void {
199-
if (this.webviewPanel) {
200-
this.webviewPanel.dispose();
201-
}
199+
this.webviewPanel?.dispose();
202200

203201
let localResourceRoots: vscode.Uri[] = [];
204202
if (this.htmlContent.javaScriptPaths) {

src/features/DebugSession.ts

+33-12
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export class DebugSessionFeature extends LanguageClientConsumer
3333
implements DebugConfigurationProvider, vscode.DebugAdapterDescriptorFactory {
3434

3535
private sessionCount: number = 1;
36-
private tempDebugProcess: PowerShellProcess;
37-
private tempSessionDetails: IEditorServicesSessionDetails;
38-
private handlers: vscode.Disposable[];
36+
private tempDebugProcess: PowerShellProcess | undefined;
37+
private tempSessionDetails: IEditorServicesSessionDetails | undefined;
38+
private handlers: vscode.Disposable[] = [];
3939
private configs: Record<DebugConfig, DebugConfiguration> = {
4040
[DebugConfig.LaunchCurrentFile]: {
4141
name: "PowerShell: Launch Current File",
@@ -68,7 +68,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
6868
super();
6969
// Register a debug configuration provider
7070
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("PowerShell", this));
71-
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory("PowerShell", this))
71+
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory("PowerShell", this));
7272
}
7373

7474
createDebugAdapterDescriptor(
@@ -79,6 +79,11 @@ export class DebugSessionFeature extends LanguageClientConsumer
7979
? this.tempSessionDetails
8080
: this.sessionManager.getSessionDetails();
8181

82+
if (sessionDetails === undefined) {
83+
this.logger.writeAndShowError(`No session details available for ${session.name}`);
84+
return;
85+
}
86+
8287
this.logger.writeVerbose(`Connecting to pipe: ${sessionDetails.debugServicePipeName}`);
8388
this.logger.writeVerbose(`Debug configuration: ${JSON.stringify(session.configuration)}`);
8489

@@ -234,6 +239,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
234239
return undefined;
235240
}
236241
}
242+
237243
// Check the temporary console setting for untitled documents only, and
238244
// check the document extension for everything else.
239245
if (config.untitled_document) {
@@ -248,17 +254,24 @@ export class DebugSessionFeature extends LanguageClientConsumer
248254
return undefined;
249255
}
250256
}
257+
251258
return config;
252259
}
253260

254261
private async resolveAttachDebugConfiguration(config: DebugConfiguration): Promise<DebugConfiguration | undefined | null> {
255262
const platformDetails = getPlatformDetails();
256263
const versionDetails = this.sessionManager.getPowerShellVersionDetails();
264+
if (versionDetails === undefined) {
265+
vscode.window.showErrorMessage(`Session version details were not found for ${config.name}`)
266+
return null;
267+
}
268+
257269
// Cross-platform attach to process was added in 6.2.0-preview.4.
258270
if (versionDetails.version < "7.0.0" && platformDetails.operatingSystem !== OperatingSystem.Windows) {
259271
vscode.window.showErrorMessage(`Attaching to a PowerShell Host Process on ${OperatingSystem[platformDetails.operatingSystem]} requires PowerShell 7.0 or higher.`);
260272
return undefined;
261273
}
274+
262275
// If nothing is set, prompt for the processId.
263276
if (!config.customPipeName && !config.processId) {
264277
config.processId = await vscode.commands.executeCommand("PowerShell.PickPSHostProcess");
@@ -267,13 +280,15 @@ export class DebugSessionFeature extends LanguageClientConsumer
267280
return null;
268281
}
269282
}
283+
270284
if (!config.runspaceId && !config.runspaceName) {
271285
config.runspaceId = await vscode.commands.executeCommand("PowerShell.PickRunspace", config.processId);
272286
// No runspace selected. Cancel attach.
273287
if (!config.runspaceId) {
274288
return null;
275289
}
276290
}
291+
277292
return config;
278293
}
279294
}
@@ -341,7 +356,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
341356

342357
private command: vscode.Disposable;
343358
private waitingForClientToken?: vscode.CancellationTokenSource;
344-
private getLanguageClientResolve: (value: LanguageClient) => void;
359+
private getLanguageClientResolve?: (value: LanguageClient) => void;
345360

346361
constructor() {
347362
super();
@@ -356,7 +371,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
356371
public setLanguageClient(languageClient: LanguageClient) {
357372
this.languageClient = languageClient;
358373

359-
if (this.waitingForClientToken) {
374+
if (this.waitingForClientToken && this.getLanguageClientResolve) {
360375
this.getLanguageClientResolve(this.languageClient);
361376
this.clearWaitingToken();
362377
}
@@ -367,7 +382,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
367382
}
368383

369384
private getLanguageClient(): Promise<LanguageClient> {
370-
if (this.languageClient) {
385+
if (this.languageClient !== undefined) {
371386
return Promise.resolve(this.languageClient);
372387
} else {
373388
// If PowerShell isn't finished loading yet, show a loading message
@@ -406,13 +421,14 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
406421
}
407422

408423
private async pickPSHostProcess(): Promise<string | undefined> {
409-
const hostProcesses = await this.languageClient.sendRequest(GetPSHostProcessesRequestType, {});
410424
// Start with the current PowerShell process in the list.
411425
const items: IProcessItem[] = [{
412426
label: "Current",
413427
description: "The current PowerShell Extension process.",
414428
pid: "current",
415429
}];
430+
431+
const hostProcesses = await this.languageClient?.sendRequest(GetPSHostProcessesRequestType, {});
416432
for (const p in hostProcesses) {
417433
if (hostProcesses.hasOwnProperty(p)) {
418434
let windowTitle = "";
@@ -427,15 +443,18 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
427443
});
428444
}
429445
}
446+
430447
if (items.length === 0) {
431448
return Promise.reject("There are no PowerShell host processes to attach to.");
432449
}
450+
433451
const options: vscode.QuickPickOptions = {
434452
placeHolder: "Select a PowerShell host process to attach to",
435453
matchOnDescription: true,
436454
matchOnDetail: true,
437455
};
438456
const item = await vscode.window.showQuickPick(items, options);
457+
439458
return item ? `${item.pid}` : undefined;
440459
}
441460

@@ -462,7 +481,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
462481

463482
private command: vscode.Disposable;
464483
private waitingForClientToken?: vscode.CancellationTokenSource;
465-
private getLanguageClientResolve: (value: LanguageClient) => void;
484+
private getLanguageClientResolve?: (value: LanguageClient) => void;
466485

467486
constructor() {
468487
super();
@@ -476,7 +495,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
476495
public setLanguageClient(languageClient: LanguageClient) {
477496
this.languageClient = languageClient;
478497

479-
if (this.waitingForClientToken) {
498+
if (this.waitingForClientToken && this.getLanguageClientResolve) {
480499
this.getLanguageClientResolve(this.languageClient);
481500
this.clearWaitingToken();
482501
}
@@ -526,9 +545,9 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
526545
}
527546

528547
private async pickRunspace(processId: string): Promise<string | undefined> {
529-
const response = await this.languageClient.sendRequest(GetRunspaceRequestType, { processId });
548+
const response = await this.languageClient?.sendRequest(GetRunspaceRequestType, { processId });
530549
const items: IRunspaceItem[] = [];
531-
for (const runspace of response) {
550+
for (const runspace of response ?? []) {
532551
// Skip default runspace
533552
if ((runspace.id === 1 || runspace.name === "PSAttachRunspace")
534553
&& processId === "current") {
@@ -541,12 +560,14 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
541560
id: runspace.id.toString(),
542561
});
543562
}
563+
544564
const options: vscode.QuickPickOptions = {
545565
placeHolder: "Select PowerShell runspace to debug",
546566
matchOnDescription: true,
547567
matchOnDetail: true,
548568
};
549569
const item = await vscode.window.showQuickPick(items, options);
570+
550571
return item ? `${item.id}` : undefined;
551572
}
552573

src/features/ExpandAlias.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export class ExpandAliasFeature extends LanguageClientConsumer {
2424
const sls = selection.start;
2525
const sle = selection.end;
2626

27-
let text;
28-
let range;
27+
let text: string | any[];
28+
let range: vscode.Range | vscode.Position;
2929

3030
if ((sls.character === sle.character) && (sls.line === sle.line)) {
3131
text = document.getText();
@@ -35,7 +35,7 @@ export class ExpandAliasFeature extends LanguageClientConsumer {
3535
range = new vscode.Range(sls.line, sls.character, sle.line, sle.character);
3636
}
3737

38-
this.languageClient.sendRequest(ExpandAliasRequestType, { text }).then((result) => {
38+
this.languageClient?.sendRequest(ExpandAliasRequestType, { text }).then((result) => {
3939
editor.edit((editBuilder) => {
4040
editBuilder.replace(range, result.text);
4141
});

src/features/ExtensionCommands.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,16 @@ interface IInvokeRegisteredEditorCommandParameter {
172172

173173
export class ExtensionCommandsFeature extends LanguageClientConsumer {
174174
private commands: vscode.Disposable[];
175-
private handlers: vscode.Disposable[];
175+
private handlers: vscode.Disposable[] = [];
176176
private extensionCommands: IExtensionCommand[] = [];
177177

178178
constructor(private log: Logger) {
179179
super();
180180
this.commands = [
181181
vscode.commands.registerCommand("PowerShell.ShowAdditionalCommands", async () => {
182-
await this.showExtensionCommands(this.languageClient);
182+
if (this.languageClient !== undefined) {
183+
await this.showExtensionCommands(this.languageClient);
184+
}
183185
}),
184186

185187
vscode.commands.registerCommand("PowerShell.InvokeRegisteredEditorCommand",
@@ -191,7 +193,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
191193
const commandToExecute = this.extensionCommands.find((x) => x.name === param.commandName);
192194

193195
if (commandToExecute) {
194-
await this.languageClient.sendRequest(
196+
await this.languageClient?.sendRequest(
195197
InvokeExtensionCommandRequestType,
196198
{
197199
name: commandToExecute.name,
@@ -340,10 +342,10 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
340342

341343
private onCommandSelected(
342344
chosenItem: IExtensionCommandQuickPickItem | undefined,
343-
client: LanguageClient) {
345+
client: LanguageClient | undefined) {
344346

345347
if (chosenItem !== undefined) {
346-
client.sendRequest(
348+
client?.sendRequest(
347349
InvokeExtensionCommandRequestType,
348350
{
349351
name: chosenItem.command.name,

src/features/ExternalApi.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ export class ExternalApiFeature extends LanguageClientConsumer implements IPower
141141
const versionDetails = this.sessionManager.getPowerShellVersionDetails();
142142

143143
return {
144-
exePath: this.sessionManager.PowerShellExeDetails.exePath,
145-
version: versionDetails.version,
146-
displayName: this.sessionManager.PowerShellExeDetails.displayName, // comes from the Session Menu
147-
architecture: versionDetails.architecture
144+
exePath: this.sessionManager.PowerShellExeDetails?.exePath ?? "unknown",
145+
version: versionDetails?.version ?? "unknown",
146+
displayName: this.sessionManager.PowerShellExeDetails?.displayName ?? "unknown", // comes from the Session Menu
147+
architecture: versionDetails?.architecture ?? "unknown"
148148
};
149149
}
150150
/*

src/features/FindModule.ts

+23-23
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ export class FindModuleFeature extends LanguageClientConsumer {
4444

4545
this.pickPowerShellModule().then((moduleName) => {
4646
if (moduleName) {
47-
// vscode.window.setStatusBarMessage("Installing PowerShell Module " + moduleName, 1500);
48-
this.languageClient.sendRequest(InstallModuleRequestType, moduleName);
47+
this.languageClient?.sendRequest(InstallModuleRequestType, moduleName);
4948
}
5049
});
5150
});
@@ -55,37 +54,38 @@ export class FindModuleFeature extends LanguageClientConsumer {
5554
this.command.dispose();
5655
}
5756

58-
private pickPowerShellModule(): Thenable<string> {
59-
return this.languageClient.sendRequest(FindModuleRequestType, undefined).then((modules) => {
60-
const items: QuickPickItem[] = [];
57+
private async pickPowerShellModule(): Promise<string | undefined> {
58+
const modules = await this.languageClient?.sendRequest(FindModuleRequestType, undefined);
59+
const items: QuickPickItem[] = [];
6160

62-
// We've got the modules info, let's cancel the timeout unless it's already been cancelled
63-
if (this.cancelFindToken) {
64-
this.clearCancelFindToken();
65-
} else {
66-
// Already timed out, would be weird to display modules after we said it timed out.
67-
return Promise.resolve("");
68-
}
61+
// We've got the modules info, let's cancel the timeout unless it's already been cancelled
62+
if (this.cancelFindToken) {
63+
this.clearCancelFindToken();
64+
} else {
65+
// Already timed out, would be weird to display modules after we said it timed out.
66+
return Promise.resolve("");
67+
}
6968

69+
if (modules !== undefined) {
7070
for (const item in modules) {
7171
if (modules.hasOwnProperty(item)) {
7272
items.push({ label: modules[item].name, description: modules[item].description });
7373
}
7474
}
75+
}
7576

76-
if (items.length === 0) {
77-
return Promise.reject("No PowerShell modules were found.");
78-
}
77+
if (items.length === 0) {
78+
return Promise.reject("No PowerShell modules were found.");
79+
}
7980

80-
const options: vscode.QuickPickOptions = {
81-
placeHolder: "Select a PowerShell module to install",
82-
matchOnDescription: true,
83-
matchOnDetail: true,
84-
};
81+
const options: vscode.QuickPickOptions = {
82+
placeHolder: "Select a PowerShell module to install",
83+
matchOnDescription: true,
84+
matchOnDetail: true,
85+
};
8586

86-
return vscode.window.showQuickPick(items, options).then((item) => {
87-
return item ? item.label : "";
88-
});
87+
return vscode.window.showQuickPick(items, options).then((item) => {
88+
return item ? item.label : "";
8989
});
9090
}
9191

src/features/GenerateBugReport.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ${this.generateExtensionTable(extensions)}
7979
this.command.dispose();
8080
}
8181

82-
private generateExtensionTable(installedExtensions): string {
82+
private generateExtensionTable(installedExtensions: vscode.Extension<any>[]): string {
8383
if (!installedExtensions.length) {
8484
return "none";
8585
}
@@ -105,8 +105,7 @@ ${tableHeader}\n${table};
105105
}
106106

107107
private getRuntimeInfo() {
108-
109-
const powerShellExePath = this.sessionManager.PowerShellExeDetails.exePath;
108+
const powerShellExePath = this.sessionManager.PowerShellExeDetails?.exePath;
110109
const powerShellArgs = [
111110
"-NoProfile",
112111
"-Command",

0 commit comments

Comments
 (0)