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 d585443

Browse files
Merge pull request #4231 from PowerShell/andschwa/fix-debug-config
Check script extension for current file only, allow unawaited promises explicitly with void, and refactor a bit of logging!
2 parents 3924151 + ec7b8f1 commit d585443

16 files changed

+157
-157
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/Console.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ export class ConsoleFeature extends LanguageClientConsumer {
170170
private commands: vscode.Disposable[];
171171
private handlers: vscode.Disposable[] = [];
172172

173-
constructor(private log: Logger) {
173+
constructor(private logger: Logger) {
174174
super();
175175
this.commands = [
176176
vscode.commands.registerCommand("PowerShell.RunSelection", async () => {
177177
if (vscode.window.activeTerminal &&
178178
vscode.window.activeTerminal.name !== "PowerShell Extension") {
179-
this.log.write("PowerShell Extension Terminal is not active! Running in current terminal using 'runSelectedText'");
179+
this.logger.write("PowerShell Extension Terminal is not active! Running in current terminal using 'runSelectedText'");
180180
await vscode.commands.executeCommand("workbench.action.terminal.runSelectedText");
181181

182182
// We need to honor the focusConsoleOnExecute setting here too. However, the boolean that `show`

‎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: 27 additions & 40 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

@@ -235,48 +232,45 @@ export class DebugSessionFeature extends LanguageClientConsumer
235232
}
236233

237234
private async resolveLaunchDebugConfiguration(config: DebugConfiguration): Promise<DebugConfiguration | undefined> {
238-
// Check the languageId only for current documents (which includes untitled documents).
235+
// Check the languageId and file extension only for current documents
236+
// (which includes untitled documents). This prevents accidentally
237+
// running the debugger for an open non-PowerShell file.
239238
if (config.current_document) {
240239
const currentDocument = vscode.window.activeTextEditor?.document;
241240
if (currentDocument?.languageId !== "powershell") {
242-
awaitvscode.window.showErrorMessage("Please change the current document's language mode to PowerShell.");
241+
voidthis.logger.writeAndShowError(`PowerShell does not support debugging this language mode: '${currentDocument?.languageId}'.`);
243242
return undefined;
244243
}
245-
}
246244

247-
// Check the temporary console setting for untitled documents only, and
248-
// check the document extension for if the script is an extant file (it
249-
// could be inline).
250-
if (config.untitled_document) {
251-
if (config.createTemporaryIntegratedConsole) {
252-
await vscode.window.showErrorMessage("Debugging untitled files in a temporary console is not supported.");
253-
return undefined;
254-
}
255-
} else if (config.script) {
256-
// TODO: Why even bother with this complexity?
257245
if (await utils.checkIfFileExists(config.script)) {
258246
const ext = path.extname(config.script).toLowerCase();
259247
if (!(ext === ".ps1" || ext === ".psm1")) {
260-
awaitvscode.window.showErrorMessage(`PowerShell does not support debugging this file type: '${path.basename(config.script)}'`);
248+
voidthis.logger.writeAndShowError(`PowerShell does not support debugging this file type: '${path.basename(config.script)}'.`);
261249
return undefined;
262250
}
263251
}
264252
}
265253

254+
// Check the temporary console setting for untitled documents only.
255+
if (config.untitled_document && config.createTemporaryIntegratedConsole) {
256+
void this.logger.writeAndShowError("PowerShell does not support debugging untitled files in a temporary console.");
257+
return undefined;
258+
}
259+
266260
return config;
267261
}
268262

269263
private async resolveAttachDebugConfiguration(config: DebugConfiguration): Promise<DebugConfiguration | undefined | null> {
270264
const platformDetails = getPlatformDetails();
271265
const versionDetails = this.sessionManager.getPowerShellVersionDetails();
272266
if (versionDetails === undefined) {
273-
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}'.`);
274268
return null;
275269
}
276270

277271
// Cross-platform attach to process was added in 6.2.0-preview.4.
278272
if (versionDetails.version < "7.0.0" && platformDetails.operatingSystem !== OperatingSystem.Windows) {
279-
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.`);
280274
return undefined;
281275
}
282276

@@ -309,10 +303,9 @@ export class SpecifyScriptArgsFeature implements vscode.Disposable {
309303
constructor(context: vscode.ExtensionContext) {
310304
this.context = context;
311305

312-
this.command =
313-
vscode.commands.registerCommand("PowerShell.SpecifyScriptArgs", () => {
314-
return this.specifyScriptArguments();
315-
});
306+
this.command = vscode.commands.registerCommand("PowerShell.SpecifyScriptArgs", () => {
307+
return this.specifyScriptArguments();
308+
});
316309
}
317310

318311
public dispose() {
@@ -366,7 +359,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
366359
private waitingForClientToken?: vscode.CancellationTokenSource;
367360
private getLanguageClientResolve?: (value: LanguageClient) => void;
368361

369-
constructor() {
362+
constructor(privatelogger: Logger) {
370363
super();
371364

372365
this.command =
@@ -401,7 +394,6 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
401394
(resolve, reject) => {
402395
this.getLanguageClientResolve = resolve;
403396

404-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
405397
vscode.window
406398
.showQuickPick(
407399
["Cancel"],
@@ -412,17 +404,15 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
412404
this.clearWaitingToken();
413405
reject();
414406
}
415-
});
407+
},undefined);
416408

417409
// Cancel the loading prompt after 60 seconds
418410
setTimeout(() => {
419411
if (this.waitingForClientToken) {
420412
this.clearWaitingToken();
421413
reject();
422414

423-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
424-
vscode.window.showErrorMessage(
425-
"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.");
426416
}
427417
}, 60000);
428418
},
@@ -495,7 +485,7 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
495485
private waitingForClientToken?: vscode.CancellationTokenSource;
496486
private getLanguageClientResolve?: (value: LanguageClient) => void;
497487

498-
constructor() {
488+
constructor(privatelogger: Logger) {
499489
super();
500490
this.command =
501491
vscode.commands.registerCommand("PowerShell.PickRunspace", (processId) => {
@@ -529,7 +519,6 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
529519
(resolve, reject) => {
530520
this.getLanguageClientResolve = resolve;
531521

532-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
533522
vscode.window
534523
.showQuickPick(
535524
["Cancel"],
@@ -540,17 +529,15 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
540529
this.clearWaitingToken();
541530
reject();
542531
}
543-
});
532+
},undefined);
544533

545534
// Cancel the loading prompt after 60 seconds
546535
setTimeout(() => {
547536
if (this.waitingForClientToken) {
548537
this.clearWaitingToken();
549538
reject();
550539

551-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
552-
vscode.window.showErrorMessage(
553-
"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.");
554541
}
555542
}, 60000);
556543
},

‎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

0 commit comments

Comments
(0)

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