Skip to content

Commit 7a2a372

Browse files
committed
Enable VM service even when running "without debugging"
This will allow all service extension functionality to work (such as toggling perf graph, debug banner etc.) and will also allow us to detect whether Hot Reload / Hot Restart extensions are loaded when not debugging (which is the only supported way for web right now). Fixes #1602.
1 parent 79bf543 commit 7a2a372

5 files changed

Lines changed: 42 additions & 34 deletions

File tree

‎src/debug/dart_debug_impl.ts‎

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export class DartDebugSession extends DebugSession {
9090
this.shouldKillProcessOnTerminate = true;
9191
this.cwd = args.cwd;
9292
this.noDebug = args.noDebug;
93+
// Set default exception mode based on noDebug. This will be sent to threads
94+
// prior to VS Code sending (or, in the case of noDebug, due to not sending)
95+
// the exception mode.
96+
this.threadManager.setExceptionPauseMode(this.noDebug ? "None" : "Unhandled");
9397
this.packageMap = new PackageMap(PackageMap.findPackagesFile(args.program || args.cwd));
9498
this.debugSdkLibraries = args.debugSdkLibraries;
9599
this.debugExternalLibraries = args.debugExternalLibraries;
@@ -107,7 +111,7 @@ export class DartDebugSession extends DebugSession {
107111
process.stdout.setEncoding("utf8");
108112
process.stdout.on("data", (data) => {
109113
let match: RegExpExecArray | null = null;
110-
if (!this.noDebug && this.parseObservatoryUriFromStdOut && !this.observatory) {
114+
if (this.parseObservatoryUriFromStdOut && !this.observatory) {
111115
match = ObservatoryConnection.bannerRegex.exec(data.toString());
112116
}
113117
if (match) {
@@ -131,9 +135,6 @@ export class DartDebugSession extends DebugSession {
131135
this.logToUser(`Exited (${signal ? `${signal}`.toLowerCase() : code})\n`);
132136
this.sendEvent(new TerminatedEvent());
133137
});
134-
135-
if (args.noDebug)
136-
this.sendEvent(new InitializedEvent());
137138
}
138139

139140
protected async attachRequest(response: DebugProtocol.AttachResponse, args: DartAttachRequestArguments): Promise<void> {
@@ -177,12 +178,9 @@ export class DartDebugSession extends DebugSession {
177178
}
178179

179180
protected spawnProcess(args: DartLaunchRequestArguments) {
180-
const debug = !args.noDebug;
181181
let appArgs = [];
182-
if (debug) {
183-
appArgs.push("--enable-vm-service=0");
184-
appArgs.push("--pause_isolates_on_start=true");
185-
}
182+
appArgs.push("--enable-vm-service=0");
183+
appArgs.push("--pause_isolates_on_start=true");
186184
if (args.enableAsserts !== false) { // undefined = on
187185
appArgs.push("--enable-asserts");
188186
}
@@ -255,9 +253,6 @@ export class DartDebugSession extends DebugSession {
255253
vmServiceUri: browserFriendlyUri.toString(),
256254
}));
257255

258-
if (this.noDebug)
259-
return;
260-
261256
return new Promise<void>((resolve, reject) => {
262257
this.observatory = new ObservatoryConnection(uri);
263258
this.observatory.onLogging((message) => this.log(message));
@@ -448,6 +443,12 @@ export class DartDebugSession extends DebugSession {
448443
response: DebugProtocol.SetBreakpointsResponse,
449444
args: DebugProtocol.SetBreakpointsArguments,
450445
): Promise<void> {
446+
if (this.noDebug) {
447+
response.body = { breakpoints: args.breakpoints.map((b) => ({ verified: false })) };
448+
this.sendResponse(response);
449+
return;
450+
}
451+
451452
const source: DebugProtocol.Source = args.source;
452453
let breakpoints: DebugProtocol.SourceBreakpoint[] = args.breakpoints;
453454
if (!breakpoints)
@@ -481,10 +482,14 @@ export class DartDebugSession extends DebugSession {
481482
const filters: string[] = args.filters;
482483

483484
let mode: VmExceptionMode = "None";
484-
if (filters.indexOf("Unhandled") !== -1)
485-
mode = "Unhandled";
486-
if (filters.indexOf("All") !== -1)
487-
mode = "All";
485+
486+
// If we're running in noDebug mode, we'll always set None.
487+
if (!this.noDebug) {
488+
if (filters.indexOf("Unhandled") !== -1)
489+
mode = "Unhandled";
490+
if (filters.indexOf("All") !== -1)
491+
mode = "All";
492+
}
488493

489494
this.threadManager.setExceptionPauseMode(mode);
490495

@@ -1020,8 +1025,21 @@ export class DartDebugSession extends DebugSession {
10201025
case "requestCoverageUpdate":
10211026
this.requestCoverageUpdate("editor");
10221027
break;
1023-
1028+
// Flutter requests that may be sent during test runs or other places
1029+
// that we don't currently support. TODO: Fix this by moving all the
1030+
// service extension stufff out of Flutter to here, and making it not
1031+
// Flutter-specific. This requires sending all service extensions
1032+
// directly to the VM and not via Flutter's run daemon.
1033+
case "checkPlatformOverride":
1034+
case "checkIsWidgetCreationTracked":
1035+
case "hotReload":
1036+
case "hotRestart":
1037+
// TODO: Get rid of this!
1038+
this.log(`Ignoring Flutter customRequest ${request} for non-Flutter-run app`, LogSeverity.Warn);
1039+
this.sendResponse(response);
1040+
break;
10241041
default:
1042+
this.log(`Unknown customRequest ${request}`, LogSeverity.Warn);
10251043
super.customRequest(request, response, args);
10261044
break;
10271045
}

‎src/debug/dart_test_debug_impl.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ export class DartTestDebugSession extends DartDebugSession {
2626
// deifferent to the isolates being paused). To do that, we need to change
2727
// how our "unpause" logic works in the base debug adapter (since it won't
2828
// be paused at startup).
29-
// if (debug) {
30-
// appArgs.push("--pause-after-load");
31-
// }
29+
// appArgs.push("--pause-after-load");
3230

3331
// Instead, we do it the VM way for now...
34-
if (debug) {
35-
appArgs.push("--enable-vm-service=0");
36-
appArgs.push("--pause_isolates_on_start=true");
37-
}
32+
appArgs.push("--enable-vm-service=0");
33+
appArgs.push("--pause_isolates_on_start=true");
34+
3835
if (args.vmAdditionalArgs) {
3936
appArgs = appArgs.concat(args.vmAdditionalArgs);
4037
}

‎src/debug/flutter_debug_impl.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ export class FlutterDebugSession extends DartDebugSession {
158158
}
159159
}
160160

161-
if (!args.noDebug) {
162-
appArgs.push("--start-paused");
163-
}
161+
appArgs.push("--start-paused");
164162
}
165163

166164
if (args.args) {

‎src/debug/flutter_test_debug_impl.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ import { FlutterLaunchRequestArguments, LogCategory, LogMessage, LogSeverity } f
66
export class FlutterTestDebugSession extends DartTestDebugSession {
77

88
protected spawnProcess(args: FlutterLaunchRequestArguments): any {
9-
const debug = !args.noDebug;
109
let appArgs: string[] = [];
1110

12-
if (debug) {
13-
appArgs.push("--start-paused");
14-
}
11+
appArgs.push("--start-paused");
1512

1613
if (args.args) {
1714
appArgs = appArgs.concat(args.args);

‎src/debug/flutter_web_debug_impl.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ export class FlutterWebDebugSession extends FlutterDebugSession {
2929
// }
3030
// }
3131

32-
// if (!args.noDebug) {
33-
// appArgs.push("--start-paused");
34-
// }
32+
// appArgs.push("--start-paused");
3533
// }
3634

3735
if (args.args) {

0 commit comments

Comments
 (0)