Skip to content

Commit bb545ab

Browse files
authored
First approach to fix issue with dbg/run start before PSES running (#1436)
Fix #1433 One minor issue is that if you abort (return null|undefined) from resolveDebugConfiguration, VSCode "helpfully" opens your launch.json file for you. Actually, that is quite annoying. I found an issue and on this and voted it up - microsoft/vscode#54213 Also fix logic for "attach" error. We only need to test if OS != Windows. If on Windows, PS Core supports attach. And tweaked the error message wording to make more clear. If the user attempts to start a dgb or "run with out debugging" session before PSES is running, a NullRefEx occurs in PSES. Ideally, we would wait in the resolveDebugConfiguration method for PSES to finish initializing with a max wait time of say 10 seconds. Unfortunately, "sleep" in a loop in JavaScript is not so easy. AFAIT requires a significant rewrite of the method using setTimeout(). Not sure it is worth it, unless someone more knowledgable in JS can find an easy way to do the poll (for sessionstatus)/sleep loop. BTW there is probably a fix we need to make in PSES to check if SynchronizationContext is not null before we try to use it.
1 parent b4a66c3 commit bb545ab

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/features/DebugSession.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { LanguageClient, NotificationType, RequestType } from "vscode-languagecl
99
import { IFeature } from "../feature";
1010
import { getPlatformDetails, OperatingSystem } from "../platform";
1111
import { PowerShellProcess} from "../process";
12-
import { SessionManager } from "../session";
12+
import { SessionManager, SessionStatus } from "../session";
1313
import Settings = require("../settings");
1414
import utils = require("../utils");
1515

@@ -48,6 +48,14 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
4848
config: DebugConfiguration,
4949
token?: CancellationToken): ProviderResult<DebugConfiguration> {
5050

51+
// Make sure there is a session running before attempting to debug/run a program
52+
if (this.sessionManager.getSessionStatus() !== SessionStatus.Running) {
53+
const msg = "Cannot debug or run a PowerShell script until the PowerShell session has started. " +
54+
"Wait for the PowerShell session to finish starting and try again.";
55+
vscode.window.showWarningMessage(msg);
56+
return;
57+
}
58+
5159
// Starting a debug session can be done when there is no document open e.g. attach to PS host process
5260
const currentDocument = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document : undefined;
5361
const debugCurrentScript = (config.script === "${file}") || !config.request;
@@ -60,10 +68,8 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
6068
const platformDetails = getPlatformDetails();
6169
const versionDetails = this.sessionManager.getPowerShellVersionDetails();
6270

63-
if (versionDetails.edition.toLowerCase() === "core" &&
64-
platformDetails.operatingSystem !== OperatingSystem.Windows) {
65-
66-
const msg = "PowerShell Core only supports attaching to a host process on Windows.";
71+
if (platformDetails.operatingSystem !== OperatingSystem.Windows) {
72+
const msg = "Attaching to a PowerShell Host Process is supported only on Windows.";
6773
return vscode.window.showErrorMessage(msg).then((_) => {
6874
return undefined;
6975
});

src/session.ts

+4
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ export class SessionManager implements Middleware {
222222
return this.sessionDetails;
223223
}
224224

225+
public getSessionStatus(): SessionStatus {
226+
return this.sessionStatus;
227+
}
228+
225229
public getPowerShellVersionDetails(): IPowerShellVersionDetails {
226230
return this.versionDetails;
227231
}

0 commit comments

Comments
 (0)