From 376410a8919fffd5e7a4f13c9beaa8a0115e4fc6 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sun, 15 Jul 2018 12:31:00 -0600 Subject: [PATCH] First approach to fix issue with dbg/run start before PSES running 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 - https://github.com/Microsoft/vscode/issues/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. --- src/features/DebugSession.ts | 16 +++++++++++----- src/session.ts | 4 ++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 0cb14ed75f..13fa25ddd6 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -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"); @@ -48,6 +48,14 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider config: DebugConfiguration, token?: CancellationToken): ProviderResult { + // 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; @@ -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; }); diff --git a/src/session.ts b/src/session.ts index 43a8a570ce..990728d995 100644 --- a/src/session.ts +++ b/src/session.ts @@ -222,6 +222,10 @@ export class SessionManager implements Middleware { return this.sessionDetails; } + public getSessionStatus(): SessionStatus { + return this.sessionStatus; + } + public getPowerShellVersionDetails(): IPowerShellVersionDetails { return this.versionDetails; }