Skip to content

Commit

Permalink
Support separate vmServiceUri from observatoryUri
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Mar 27, 2019
1 parent 9e06404 commit a27efb8
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 26 deletions.
15 changes: 10 additions & 5 deletions src/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { DevTools } from "../sdk/dev_tools";
import { showDevToolsNotificationIfAppropriate } from "../user_prompts";
import { fsPath, getDartWorkspaceFolders, openInBrowser, ProjectType, Sdks } from "../utils";
import { DartDebugSessionInformation } from "../utils/debug";
import { handleDebugLogEvent } from "../utils/log";
import { handleDebugLogEvent, logWarn } from "../utils/log";

export const debugSessions: DartDebugSessionInformation[] = [];
// export let mostRecentAttachedProbablyReusableObservatoryUri: string;
Expand Down Expand Up @@ -86,8 +86,9 @@ export class DebugCommands {
session.progressReporter = undefined;
}
}
} else if (e.event === "dart.observatoryUri") {
} else if (e.event === "dart.debuggerUris") {
session.observatoryUri = e.body.observatoryUri;
session.vmServiceUri = e.body.vmServiceUri;
if (sdks.projectType === ProjectType.Flutter)
showDevToolsNotificationIfAppropriate(context);
// if (e.body.isProbablyReconnectable) {
Expand Down Expand Up @@ -181,9 +182,11 @@ export class DebugCommands {
const session = debugSessions.length === 1
? debugSessions[0]
: await this.promptForDebugSession();
if (session && session.observatoryUri) {
if (session && !session.session.configuration.noDebug && session.observatoryUri) {
openInBrowser(session.observatoryUri);
analytics.logDebuggerOpenObservatory();
} else if (session) {
logWarn("Cannot start Observatory for session without debug/observatoryUri");
}
}));
context.subscriptions.push(vs.commands.registerCommand("flutter.openTimeline", async () => {
Expand All @@ -192,9 +195,11 @@ export class DebugCommands {
const session = debugSessions.length === 1
? debugSessions[0]
: await this.promptForDebugSession();
if (session && session.observatoryUri) {
if (session && !session.session.configuration.noDebug && session.observatoryUri) {
openInBrowser(session.observatoryUri + "/#/timeline-dashboard");
analytics.logDebuggerOpenTimeline();
} else if (session) {
logWarn("Cannot start Observatory for session without debug/observatoryUri");
}
}));
context.subscriptions.push(vs.commands.registerCommand("_dart.openDevTools.touchBar", (args: any) => vs.commands.executeCommand("dart.openDevTools", args)));
Expand All @@ -209,7 +214,7 @@ export class DebugCommands {
if (!session)
return; // User cancelled

if (session.observatoryUri) {
if (session.vmServiceUri) {
return this.devTools.spawnForSession(session);
} else if (session.session.configuration.noDebug) {
vs.window.showInformationMessage("You must start your app with debugging in order to use DevTools.");
Expand Down
40 changes: 26 additions & 14 deletions src/debug/dart_debug_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class DartDebugSession extends DebugSession {
protected processExited = false;
public observatory?: ObservatoryConnection;
protected cwd?: string;
protected noDebug?: boolean;
private logFile?: string;
private logStream?: fs.WriteStream;
public debugSdkLibraries: boolean;
Expand All @@ -43,6 +44,7 @@ export class DartDebugSession extends DebugSession {
protected threadManager: ThreadManager;
public packageMap?: PackageMap;
protected sendStdOutToConsole: boolean = true;
protected supportsObservatory: boolean = true;
protected parseObservatoryUriFromStdOut: boolean = true;
protected requiresProgram: boolean = true;
protected pollforMemoryMs?: number; // If set, will poll for memory usage and send events back.
Expand Down Expand Up @@ -87,6 +89,7 @@ export class DartDebugSession extends DebugSession {
args.program = path.join(args.cwd, args.program);
this.shouldKillProcessOnTerminate = true;
this.cwd = args.cwd;
this.noDebug = args.noDebug;
this.packageMap = new PackageMap(PackageMap.findPackagesFile(args.program || args.cwd));
this.debugSdkLibraries = args.debugSdkLibraries;
this.debugExternalLibraries = args.debugExternalLibraries;
Expand All @@ -104,7 +107,7 @@ export class DartDebugSession extends DebugSession {
process.stdout.setEncoding("utf8");
process.stdout.on("data", (data) => {
let match: RegExpExecArray;
if (!args.noDebug && this.parseObservatoryUriFromStdOut && !this.observatory) {
if (!this.noDebug && this.parseObservatoryUriFromStdOut && !this.observatory) {
match = ObservatoryConnection.bannerRegex.exec(data.toString());
}
if (match) {
Expand Down Expand Up @@ -231,20 +234,29 @@ export class DartDebugSession extends DebugSession {
}

protected initObservatory(uri: string): Promise<void> {
// Send the uri back to the editor so it can be used to launch browsers etc.
let browserFriendlyUri: string;
if (uri.endsWith("/ws")) {
browserFriendlyUri = uri.substring(0, uri.length - 3);
if (browserFriendlyUri.startsWith("ws:"))
browserFriendlyUri = "http:" + browserFriendlyUri.substring(3);
} else {
browserFriendlyUri = uri;
}

this.sendEvent(new Event("dart.debuggerUris", {
// If we won't be killing the process on terminate, then it's likely the
// process will remain around and can be reconnected to, so let the
// editor know that it should stash this URL for easier re-attaching.
// isProbablyReconnectable: this.observatoryUriIsProbablyReconnectable,
observatoryUri: this.supportsObservatory ? browserFriendlyUri.toString() : undefined,
vmServiceUri: browserFriendlyUri.toString(),
}));

if (this.noDebug)
return;

return new Promise<void>((resolve, reject) => {
// Send the uri back to the editor so it can be used to launch browsers etc.
if (uri.endsWith("/ws")) {
let browserFriendlyUri = uri.substring(0, uri.length - 3);
if (browserFriendlyUri.startsWith("ws:"))
browserFriendlyUri = "http:" + browserFriendlyUri.substring(3);
this.sendEvent(new Event("dart.observatoryUri", {
// If we won't be killing the process on terminate, then it's likely the
// process will remain around and can be reconnected to, so let the
// editor know that it should stash this URL for easier re-attaching.
// isProbablyReconnectable: this.observatoryUriIsProbablyReconnectable,
observatoryUri: browserFriendlyUri.toString(),
}));
}
this.observatory = new ObservatoryConnection(uri);
this.observatory.onLogging((message) => this.log(message));
this.observatory.onOpen(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/debug/dart_test_debug_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { ErrorNotification, GroupNotification, PrintNotification, SuiteNotificat
import { DartDebugSession } from "./dart_debug_impl";
import { ObservatoryConnection } from "./dart_debug_protocol";
import { TestRunner } from "./test_runner";
import { DartLaunchRequestArguments, FlutterLaunchRequestArguments, LogCategory, LogMessage, LogSeverity } from "./utils";
import { DartLaunchRequestArguments, LogCategory, LogMessage, LogSeverity } from "./utils";

const tick = "✓";
const cross = "✖";

export class DartTestDebugSession extends DartDebugSession {
protected args: FlutterLaunchRequestArguments;
constructor() {
super();

Expand Down
4 changes: 1 addition & 3 deletions src/debug/flutter_debug_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class FlutterDebugSession extends DartDebugSession {
private currentRunningAppId?: string;
private appHasStarted = false;
private observatoryUri?: string;
private noDebug = false;
private isReloadInProgress = false;

// Allow flipping into stderr mode for red exceptions when we see the start/end of a Flutter exception dump.
Expand Down Expand Up @@ -59,7 +58,6 @@ export class FlutterDebugSession extends DartDebugSession {
}

protected spawnProcess(args: FlutterLaunchRequestArguments): any {
this.noDebug = args.noDebug;
const isAttach = args.request === "attach";
if (isAttach)
this.sendEvent(new Event("dart.launching", { message: "Waiting for Application to connect...", finished: false }));
Expand Down Expand Up @@ -173,7 +171,7 @@ export class FlutterDebugSession extends DartDebugSession {
}

private connectToObservatoryIfReady() {
if (!this.noDebug && this.observatoryUri && this.appHasStarted && !this.observatory)
if (this.observatoryUri && this.appHasStarted && !this.observatory)
this.initObservatory(this.observatoryUri);
}

Expand Down
2 changes: 1 addition & 1 deletion src/sdk/dev_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class DevTools implements vs.Disposable {
return;
}

const observatoryPort = extractObservatoryPort(session.observatoryUri);
const observatoryPort = extractObservatoryPort(session.vmServiceUri);

if (!this.devtoolsUrl) {
this.devtoolsUrl = vs.window.withProgress({
Expand Down
1 change: 1 addition & 0 deletions src/utils/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function extractObservatoryPort(observatoryUri: string): number | undefin

export class DartDebugSessionInformation {
public observatoryUri?: string;
public vmServiceUri?: string;
/// Reporting for the launch step.
public readonly launchProgressPromise = new PromiseCompleter<void>();
public launchProgressReporter: vs.Progress<{ message?: string; increment?: number; }>; // Set to undefined when launch finishes as a signal.
Expand Down
5 changes: 4 additions & 1 deletion test/dart_debug_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export class DartDebugClient extends DebugClient {
super(runtime, executable, debugType, spawnOptions);
this.on("dart.log", (e: DebugSessionCustomEvent) => handleDebugLogEvent(e.event, e.body));
// TODO: Make it so we don't have to keep copying logic from debug.ts into here...
this.on("dart.observatoryUri", (e: DebugSessionCustomEvent) => debugSessions[0].observatoryUri = e.body.observatoryUri);
this.on("dart.debuggerUris", (e: DebugSessionCustomEvent) => {
debugSessions[0].observatoryUri = e.body.observatoryUri;
debugSessions[0].vmServiceUri = e.body.vmServiceUri;
});
// Log important events to make troubleshooting tests easier.
this.on("output", (event: DebugProtocol.OutputEvent) => {
log(`[${event.body.category}] ${event.body.output}`);
Expand Down

0 comments on commit a27efb8

Please sign in to comment.