Skip to content

Commit

Permalink
First approach to fix issue with dbg/run start before PSES running
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rkeithhill committed Jul 15, 2018
1 parent 65245a1 commit 376410a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/features/DebugSession.ts
Expand Up @@ -9,7 +9,7 @@ import { LanguageClient, NotificationType, RequestType } from "vscode-languagecl
import { IFeature } from "../feature";
import { getPlatformDetails, OperatingSystem } from "../platform";
import { PowerShellProcess} from "../process";
import { SessionManager } from "../session";
import { SessionManager, SessionStatus } from "../session";
import Settings = require("../settings");
import utils = require("../utils");

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

// Make sure there is a session running before attempting to debug/run a program
if (this.sessionManager.getSessionStatus() !== SessionStatus.Running) {
const msg = "Cannot debug or run a PowerShell script until the PowerShell session has started. " +
"Wait for the PowerShell session to finish starting and try again.";
vscode.window.showWarningMessage(msg);
return;
}

// Starting a debug session can be done when there is no document open e.g. attach to PS host process
const currentDocument = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document : undefined;
const debugCurrentScript = (config.script === "${file}") || !config.request;
Expand All @@ -60,10 +68,8 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
const platformDetails = getPlatformDetails();
const versionDetails = this.sessionManager.getPowerShellVersionDetails();

if (versionDetails.edition.toLowerCase() === "core" &&
platformDetails.operatingSystem !== OperatingSystem.Windows) {

const msg = "PowerShell Core only supports attaching to a host process on Windows.";
if (platformDetails.operatingSystem !== OperatingSystem.Windows) {
const msg = "Attaching to a PowerShell Host Process is supported only on Windows.";
return vscode.window.showErrorMessage(msg).then((_) => {
return undefined;
});
Expand Down
4 changes: 4 additions & 0 deletions src/session.ts
Expand Up @@ -222,6 +222,10 @@ export class SessionManager implements Middleware {
return this.sessionDetails;
}

public getSessionStatus(): SessionStatus {
return this.sessionStatus;
}

public getPowerShellVersionDetails(): IPowerShellVersionDetails {
return this.versionDetails;
}
Expand Down

0 comments on commit 376410a

Please sign in to comment.