Skip to content

Commit ed6f295

Browse files
committed
Improve "Copy VM Service URI" when a debug session has both local+remote URIs
Fixes #5500 Fixes #5501
1 parent c0b99f1 commit ed6f295

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

src/extension/commands/debug.ts

+43-11
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,52 @@ export class DebugCommands implements IAmDisposable {
139139
}
140140
}));
141141
this.disposables.push(vs.commands.registerCommand("dart.copyVmServiceUri", async () => {
142-
const session = await this.getDebugSession();
143-
if (!session) {
144-
await vs.window.showInformationMessage("No Dart/Flutter debug session available");
145-
return;
142+
const options: Array<vs.QuickPickItem & { session: DartDebugSessionInformation, vmServiceUri: string }> = [];
143+
144+
function addOption(s: DartDebugSessionInformation, vmServiceUri: string, vmServiceKindDescription: string | undefined) {
145+
const description = [
146+
s.session.workspaceFolder?.name,
147+
s.session.configuration.deviceName,
148+
`Started ${s.sessionStart.toLocaleTimeString()}`,
149+
].filter((s) => s).join(", ");
150+
options.push(
151+
{
152+
// TODO: add both vm service uri and description here somewhere
153+
description,
154+
detail: vmServiceKindDescription ? `${vmServiceUri} (${vmServiceKindDescription})` : vmServiceUri,
155+
label: s.session.name,
156+
session: s,
157+
vmServiceUri,
158+
}
159+
);
146160
}
147-
const vmUri = session?.vmServiceUri;
148-
if (!vmUri) {
149-
if (session?.hasStarted)
150-
await vs.window.showInformationMessage("This debug session does not have a VM Service");
151-
else
152-
await vs.window.showInformationMessage("This debug session is not ready yet");
161+
162+
for (const debugSession of debugSessions) {
163+
const vmServiceUri = debugSession.vmServiceUri;
164+
let exposedVmServiceUri = debugSession.clientVmServiceUri ?? (vmServiceUri ? await envUtils.exposeUrl(vmServiceUri) : undefined);
165+
if (exposedVmServiceUri === vmServiceUri)
166+
exposedVmServiceUri = undefined;
167+
168+
if (vmServiceUri)
169+
addOption(debugSession, vmServiceUri, exposedVmServiceUri ? "Local URI on the remote machine" : undefined);
170+
if (exposedVmServiceUri)
171+
addOption(debugSession, exposedVmServiceUri, "The URI exposed to the client");
172+
}
173+
174+
if (options.length === 0) {
175+
await vs.window.showInformationMessage(
176+
debugSessions.length === 0
177+
? "No Dart/Flutter debug session available"
178+
: "No running Dart/Flutter debug sessions have VM Service connections available"
179+
);
153180
return;
154181
}
155-
await vs.env.clipboard.writeText(vmUri.toString());
182+
183+
const selectedOption = options.length === 1 ? options[0] : await vs.window.showQuickPick(options, { placeHolder: "Which debug session / VM Service URI?" });
184+
if (!selectedOption)
185+
return;
186+
187+
await vs.env.clipboard.writeText(selectedOption.vmServiceUri);
156188
}));
157189
this.disposables.push(vs.commands.registerCommand("dart.openDevTools.external", () => vs.commands.executeCommand("dart.openDevTools", { commandSource: CommandSource.commandPalette, location: "external" as DevToolsLocation })));
158190
this.disposables.push(vs.commands.registerCommand("_dart.openDevTools.touchBar", () => vs.commands.executeCommand("dart.openDevTools", { commandSource: CommandSource.touchbar })));

0 commit comments

Comments
 (0)