Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 043e491

Browse files
Allow unawaited promises explicitly with void
And refactor a bit of logging!
1 parent fac6e1a commit 043e491

14 files changed

+121
-118
lines changed

‎.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
"error",
3737
"always"
3838
],
39+
"@typescript-eslint/no-floating-promises": [
40+
"error",
41+
{
42+
"ignoreVoid": true
43+
}
44+
],
3945
"@typescript-eslint/no-non-null-assertion": [
4046
"off"
4147
],

‎src/features/CustomViews.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ class PowerShellContentProvider implements vscode.TextDocumentContentProvider {
101101

102102
vscode.workspace.textDocuments.some((doc) => {
103103
if (doc.uri.toString() === uriString) {
104-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
105-
vscode.window.showTextDocument(doc);
106-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
107-
vscode.commands.executeCommand("workbench.action.closeActiveEditor");
104+
void vscode.window.showTextDocument(doc);
105+
void vscode.commands.executeCommand("workbench.action.closeActiveEditor");
108106
return true;
109107
}
110108

‎src/features/DebugSession.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
8181
: this.sessionManager.getSessionDetails();
8282

8383
if (sessionDetails === undefined) {
84-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
85-
this.logger.writeAndShowError(`No session details available for ${session.name}`);
84+
void this.logger.writeAndShowError(`PowerShell session details not available for ${session.name}`);
8685
return;
8786
}
8887

@@ -103,17 +102,15 @@ export class DebugSessionFeature extends LanguageClientConsumer
103102
languageClient.onNotification(
104103
StartDebuggerNotificationType,
105104
// TODO: Use a named debug configuration.
106-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
107-
() => vscode.debug.startDebugging(undefined, {
105+
() => void vscode.debug.startDebugging(undefined, {
108106
request: "launch",
109107
type: "PowerShell",
110108
name: "PowerShell: Interactive Session"
111109
})),
112110

113111
languageClient.onNotification(
114112
StopDebuggerNotificationType,
115-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
116-
() => vscode.debug.stopDebugging(undefined))
113+
() => void vscode.debug.stopDebugging(undefined))
117114
];
118115
}
119116

@@ -192,7 +189,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
192189

193190
if (config.script === "${file}" || config.script === "${relativeFile}") {
194191
if (vscode.window.activeTextEditor === undefined) {
195-
awaitvscode.window.showErrorMessage("To debug the 'Current File', you must first open a PowerShell script file in the editor.");
192+
voidthis.logger.writeAndShowError("To debug the 'Current File', you must first open a PowerShell script file in the editor.");
196193
return undefined;
197194
}
198195
config.current_document = true;
@@ -218,7 +215,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
218215
} else if (config.request === "launch") {
219216
resolvedConfig = await this.resolveLaunchDebugConfiguration(config);
220217
} else {
221-
awaitvscode.window.showErrorMessage(`The request type was invalid: '${config.request}'`);
218+
voidthis.logger.writeAndShowError(`PowerShell debug configuration's request type was invalid: '${config.request}'.`);
222219
return null;
223220
}
224221

@@ -267,13 +264,13 @@ export class DebugSessionFeature extends LanguageClientConsumer
267264
const platformDetails = getPlatformDetails();
268265
const versionDetails = this.sessionManager.getPowerShellVersionDetails();
269266
if (versionDetails === undefined) {
270-
awaitvscode.window.showErrorMessage(`Session version details were not found for ${config.name}`);
267+
voidthis.logger.writeAndShowError(`PowerShell session version details were not found for '${config.name}'.`);
271268
return null;
272269
}
273270

274271
// Cross-platform attach to process was added in 6.2.0-preview.4.
275272
if (versionDetails.version < "7.0.0" && platformDetails.operatingSystem !== OperatingSystem.Windows) {
276-
awaitvscode.window.showErrorMessage(`Attaching to a PowerShell Host Process on ${OperatingSystem[platformDetails.operatingSystem]} requires PowerShell 7.0 or higher.`);
273+
voidthis.logger.writeAndShowError(`Attaching to a PowerShell Host Process on ${OperatingSystem[platformDetails.operatingSystem]} requires PowerShell 7.0 or higher.`);
277274
return undefined;
278275
}
279276

@@ -306,10 +303,9 @@ export class SpecifyScriptArgsFeature implements vscode.Disposable {
306303
constructor(context: vscode.ExtensionContext) {
307304
this.context = context;
308305

309-
this.command =
310-
vscode.commands.registerCommand("PowerShell.SpecifyScriptArgs", () => {
311-
return this.specifyScriptArguments();
312-
});
306+
this.command = vscode.commands.registerCommand("PowerShell.SpecifyScriptArgs", () => {
307+
return this.specifyScriptArguments();
308+
});
313309
}
314310

315311
public dispose() {
@@ -363,7 +359,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
363359
private waitingForClientToken?: vscode.CancellationTokenSource;
364360
private getLanguageClientResolve?: (value: LanguageClient) => void;
365361

366-
constructor() {
362+
constructor(privatelogger: Logger) {
367363
super();
368364

369365
this.command =
@@ -398,7 +394,6 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
398394
(resolve, reject) => {
399395
this.getLanguageClientResolve = resolve;
400396

401-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
402397
vscode.window
403398
.showQuickPick(
404399
["Cancel"],
@@ -409,17 +404,15 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
409404
this.clearWaitingToken();
410405
reject();
411406
}
412-
});
407+
},undefined);
413408

414409
// Cancel the loading prompt after 60 seconds
415410
setTimeout(() => {
416411
if (this.waitingForClientToken) {
417412
this.clearWaitingToken();
418413
reject();
419414

420-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
421-
vscode.window.showErrorMessage(
422-
"Attach to PowerShell host process: PowerShell session took too long to start.");
415+
void this.logger.writeAndShowError("Attach to PowerShell host process: PowerShell session took too long to start.");
423416
}
424417
}, 60000);
425418
},
@@ -492,7 +485,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
492485
private waitingForClientToken?: vscode.CancellationTokenSource;
493486
private getLanguageClientResolve?: (value: LanguageClient) => void;
494487

495-
constructor() {
488+
constructor(privatelogger: Logger) {
496489
super();
497490
this.command =
498491
vscode.commands.registerCommand("PowerShell.PickRunspace", (processId) => {
@@ -526,7 +519,6 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
526519
(resolve, reject) => {
527520
this.getLanguageClientResolve = resolve;
528521

529-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
530522
vscode.window
531523
.showQuickPick(
532524
["Cancel"],
@@ -537,17 +529,15 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
537529
this.clearWaitingToken();
538530
reject();
539531
}
540-
});
532+
},undefined);
541533

542534
// Cancel the loading prompt after 60 seconds
543535
setTimeout(() => {
544536
if (this.waitingForClientToken) {
545537
this.clearWaitingToken();
546538
reject();
547539

548-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
549-
vscode.window.showErrorMessage(
550-
"Attach to PowerShell host process: PowerShell session took too long to start.");
540+
void this.logger.writeAndShowError("Attach to PowerShell host process: PowerShell session took too long to start.");
551541
}
552542
}, 60000);
553543
},

‎src/features/ExtensionCommands.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
149149
private handlers: vscode.Disposable[] = [];
150150
private extensionCommands: IExtensionCommand[] = [];
151151

152-
constructor(private log: Logger) {
152+
constructor(private logger: Logger) {
153153
super();
154154
this.commands = [
155155
vscode.commands.registerCommand("PowerShell.ShowAdditionalCommands", async () => {
@@ -216,7 +216,6 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
216216

217217
this.languageClient.onRequest(
218218
InsertTextRequestType,
219-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
220219
(details) => this.insertText(details)),
221220

222221
this.languageClient.onRequest(
@@ -262,8 +261,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
262261
// We check to see if they have TrueClear on. If not, no-op because the
263262
// overriden Clear-Host already calls [System.Console]::Clear()
264263
if (Settings.load().integratedConsole.forceClearScrollbackBuffer) {
265-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
266-
vscode.commands.executeCommand("workbench.action.terminal.clear");
264+
void vscode.commands.executeCommand("workbench.action.terminal.clear");
267265
}
268266
})
269267
];
@@ -292,7 +290,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
292290
private async showExtensionCommands(client: LanguageClient): Promise<void> {
293291
// If no extension commands are available, show a message
294292
if (this.extensionCommands.length === 0) {
295-
awaitvscode.window.showInformationMessage("No extension commands have been loaded into the current session.");
293+
voidthis.logger.writeAndShowInformation("No extension commands have been loaded into the current session.");
296294
return;
297295
}
298296

@@ -364,10 +362,10 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
364362
};
365363
}
366364

367-
private newFile(): Thenable<EditorOperationResponse> {
368-
returnvscode.workspace.openTextDocument({ content: "" })
369-
.then((doc)=>vscode.window.showTextDocument(doc))
370-
.then((_)=>EditorOperationResponse.Completed);
365+
private asyncnewFile(): Promise<EditorOperationResponse> {
366+
constdoc=awaitvscode.workspace.openTextDocument({ content: "" });
367+
awaitvscode.window.showTextDocument(doc);
368+
returnEditorOperationResponse.Completed;
371369
}
372370

373371
private openFile(openFileDetails: IOpenFileDetails): Thenable<EditorOperationResponse> {
@@ -416,7 +414,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
416414
case "file": {
417415
// If the file to save can't be found, just complete the request
418416
if (!this.findTextDocument(this.normalizeFilePath(currentFileUri.fsPath))) {
419-
await this.log.writeAndShowError(`File to save not found: ${currentFileUri.fsPath}.`);
417+
void this.logger.writeAndShowError(`File to save not found: ${currentFileUri.fsPath}.`);
420418
return EditorOperationResponse.Completed;
421419
}
422420

@@ -443,8 +441,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
443441
if (!saveFileDetails.newPath) {
444442
// TODO: Create a class handle vscode warnings and errors so we can warn easily
445443
// without logging
446-
await this.log.writeAndShowWarning(
447-
"Cannot save untitled file. Try SaveAs(\"path/to/file.ps1\") instead.");
444+
void this.logger.writeAndShowWarning("Cannot save untitled file. Try SaveAs(\"path/to/file.ps1\") instead.");
448445
return EditorOperationResponse.Completed;
449446
}
450447

@@ -454,7 +451,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
454451
} else {
455452
// In fresh contexts, workspaceFolders is not defined...
456453
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length === 0) {
457-
await this.log.writeAndShowWarning("Cannot save file to relative path: no workspaces are open. " +
454+
void this.logger.writeAndShowWarning("Cannot save file to relative path: no workspaces are open. " +
458455
"Try saving to an absolute path, or open a workspace.");
459456
return EditorOperationResponse.Completed;
460457
}
@@ -463,7 +460,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
463460
const workspaceRootUri = vscode.workspace.workspaceFolders[0].uri;
464461
// We don't support saving to a non-file URI-schemed workspace
465462
if (workspaceRootUri.scheme !== "file") {
466-
await this.log.writeAndShowWarning(
463+
void this.logger.writeAndShowWarning(
467464
"Cannot save untitled file to a relative path in an untitled workspace. " +
468465
"Try saving to an absolute path or opening a workspace folder.");
469466
return EditorOperationResponse.Completed;
@@ -475,7 +472,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
475472
default: {
476473
// Other URI schemes are not supported
477474
const msg = JSON.stringify(saveFileDetails);
478-
this.log.writeVerbose(
475+
this.logger.writeVerbose(
479476
`<${ExtensionCommandsFeature.name}>: Saving a document with scheme '${currentFileUri.scheme}' ` +
480477
`is currently unsupported. Message: '${msg}'`);
481478
return EditorOperationResponse.Completed; }
@@ -503,7 +500,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
503500
vscode.Uri.file(destinationAbsolutePath),
504501
Buffer.from(oldDocument.getText()));
505502
} catch (e) {
506-
await this.log.writeAndShowWarning(`<${ExtensionCommandsFeature.name}>: ` +
503+
void this.logger.writeAndShowWarning(`<${ExtensionCommandsFeature.name}>: ` +
507504
`Unable to save file to path '${destinationAbsolutePath}': ${e}`);
508505
return;
509506
}
@@ -572,18 +569,18 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
572569
return EditorOperationResponse.Completed;
573570
}
574571

575-
private asyncshowInformationMessage(message: string): Promise<EditorOperationResponse> {
576-
awaitvscode.window.showInformationMessage(message);
572+
private showInformationMessage(message: string): EditorOperationResponse {
573+
voidthis.logger.writeAndShowInformation(message);
577574
return EditorOperationResponse.Completed;
578575
}
579576

580-
private asyncshowErrorMessage(message: string): Promise<EditorOperationResponse> {
581-
awaitvscode.window.showErrorMessage(message);
577+
private showErrorMessage(message: string): EditorOperationResponse {
578+
voidthis.logger.writeAndShowError(message);
582579
return EditorOperationResponse.Completed;
583580
}
584581

585-
private asyncshowWarningMessage(message: string): Promise<EditorOperationResponse> {
586-
awaitvscode.window.showWarningMessage(message);
582+
private showWarningMessage(message: string): EditorOperationResponse {
583+
voidthis.logger.writeAndShowWarning(message);
587584
return EditorOperationResponse.Completed;
588585
}
589586

‎src/features/GetCommands.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ export class GetCommandsFeature extends LanguageClientConsumer {
5858
public override setLanguageClient(languageclient: LanguageClient) {
5959
this.languageClient = languageclient;
6060
if (this.commandsExplorerTreeView.visible) {
61-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
62-
vscode.commands.executeCommand("PowerShell.RefreshCommandsExplorer");
61+
void vscode.commands.executeCommand("PowerShell.RefreshCommandsExplorer");
6362
}
6463
}
6564

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /