Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions source/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@
"group": "inline",
"when": "view == quantum-workspaces && viewItem == workspace"
},
{
"command": "qsharp-vscode.jobOpenPortal",
"group": "inline",
"when": "view == quantum-workspaces && (viewItem == job-v2 || viewItem == job-cancelable-v2 || viewItem == result-v2 || viewItem == result-download-v2)"
},
{
"command": "qsharp-vscode.workspacesRemove",
"when": "view == quantum-workspaces && viewItem == workspace"
Expand All @@ -325,22 +330,22 @@
{
"command": "qsharp-vscode.deleteJob",
"group": "inline",
"when": "view == quantum-workspaces && (viewItem == job || viewItem == job-cancelable || viewItem == result || viewItem == result-download) && qsharp-vscode.deleteJobsEnabled"
"when": "view == quantum-workspaces && (viewItem == job || viewItem == job-cancelable || viewItem == result || viewItem == result-download || viewItem == job-v2 || viewItem == job-cancelable-v2 || viewItem == result-v2 || viewItem == result-download-v2) && qsharp-vscode.deleteJobsEnabled"
},
{
"command": "qsharp-vscode.cancelJob",
"group": "inline",
"when": "view == quantum-workspaces && viewItem == job-cancelable"
"when": "view == quantum-workspaces && (viewItem == job-cancelable || viewItem == job-cancelable-v2)"
},
{
"command": "qsharp-vscode.downloadResults",
"group": "inline",
"when": "view == quantum-workspaces && viewItem == result-download"
"when": "view == quantum-workspaces && (viewItem == result-download || viewItem == result-download-v2)"
},
{
"command": "qsharp-vscode.downloadRawResults",
"group": "inline",
"when": "view == quantum-workspaces && viewItem == result-download"
"when": "view == quantum-workspaces && (viewItem == result-download || viewItem == result-download-v2)"
},
{
"command": "qsharp-vscode.workspacePythonCode",
Expand Down Expand Up @@ -475,7 +480,13 @@
{
"command": "qsharp-vscode.workspaceOpenPortal",
"category": "QDK",
"title": "Open the workspace in the Azure portal",
"title": "Open the workspace in the web portal",
"icon": "$(link-external)"
},
{
"command": "qsharp-vscode.jobOpenPortal",
"category": "QDK",
"title": "Open the job in the web portal",
"icon": "$(link-external)"
},
{
Expand Down
21 changes: 17 additions & 4 deletions source/vscode/src/azure/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
import {
cancelPendingJob,
deleteJobRequest,
getAzurePortalWorkspaceLink,
getWorkspacePortalLink,
getQuantumOsJobLink,
getJobFiles,
getPythonCodeForWorkspace,
parseConnectionString,
Expand Down Expand Up @@ -467,6 +468,19 @@ export async function initAzureWorkspaces(context: vscode.ExtensionContext) {
),
);

context.subscriptions.push(
vscode.commands.registerCommand(
`${qsharpExtensionId}.jobOpenPortal`,
async (arg: WorkspaceTreeItem) => {
const treeItem = arg || currentTreeItem;
if (treeItem?.type !== "job") return;
const job = treeItem.itemData as Job;
const link = getQuantumOsJobLink(treeItem.workspace, job.id);
vscode.env.openExternal(vscode.Uri.parse(link));
},
),
);

context.subscriptions.push(
vscode.commands.registerCommand(
`${qsharpExtensionId}.workspaceOpenPortal`,
Expand All @@ -476,7 +490,7 @@ export async function initAzureWorkspaces(context: vscode.ExtensionContext) {
if (treeItem?.type !== "workspace") return;
const workspace = treeItem.itemData as WorkspaceConnection;

const link = getAzurePortalWorkspaceLink(workspace);
const link = getWorkspacePortalLink(workspace);
vscode.env.openExternal(vscode.Uri.parse(link));
},
),
Expand Down Expand Up @@ -713,8 +727,7 @@ async function uploadSupplementalData(
token: string,
associationId: string,
) {
const endpointMatch = quantumUris.endpoint.match(QuantumUris.endpointRegExp);
const isV2Workspace = endpointMatch?.groups?.versionSuffix === "-v2";
const { isV2Workspace } = QuantumUris.parseEndpointUri(quantumUris.endpoint);

if (isV2Workspace) {
const circuitDiagram = await getCircuitJson(program);
Expand Down
14 changes: 13 additions & 1 deletion source/vscode/src/azure/networkRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,21 @@ export class QuantumUris {
// - Otherwise, keeps any other suffix as part of the location
// e.g. "https://westus.quantum.azure.com" -> location="westus", versionSuffix=undefined
// e.g. "https://eastus2-v2.quantum.azure.com" -> location="eastus2", versionSuffix="-v2"
public static readonly endpointRegExp =
private static readonly _endpointRegExp =
/https:\/\/(?<location>[^.]+?)(?<versionSuffix>-v2)?\./;

/** Parses the relevant parts out of an endpoint URI string. */
public static parseEndpointUri(endpointUri: string): {
location: string | undefined;
isV2Workspace: boolean;
} {
const match = endpointUri.match(QuantumUris._endpointRegExp);
return {
location: match?.groups?.location,
isV2Workspace: match?.groups?.versionSuffix === "-v2",
};
}

constructor(
public endpoint: string, // e.g. "https://westus.quantum.azure.com"
public id: string, // e.g. "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/quantumResourcegroup/providers/Microsoft.Quantum/Workspaces/quantumworkspace1"
Expand Down
15 changes: 10 additions & 5 deletions source/vscode/src/azure/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as vscode from "vscode";
import { queryWorkspace } from "./workspaceActions";
import { log } from "qsharp-lang";
import { targetSupportQir } from "./providerProperties";
import { QuantumUris } from "./networkRequests";

// See docs at https://code.visualstudio.com/api/extension-guides/tree-view

Expand Down Expand Up @@ -250,34 +251,38 @@ export class WorkspaceTreeItem extends vscode.TreeItem {
case "job": {
const job = itemData as Job;
this.collapsibleState = vscode.TreeItemCollapsibleState.None;
const { isV2Workspace } = QuantumUris.parseEndpointUri(
workspace.endpointUri,
);
const v2Suffix = isV2Workspace ? "-v2" : "";
switch (job.status) {
case "Executing":
this.contextValue = "job-cancelable";
this.contextValue = `job-cancelable${v2Suffix}`;
// falls through
case "Finishing":
this.iconPath = new vscode.ThemeIcon("run-all");
break;
case "Queued":
case "Waiting":
this.iconPath = new vscode.ThemeIcon("loading~spin");
this.contextValue = "job-cancelable";
this.contextValue = `job-cancelable${v2Suffix}`;
break;
case "CancellationRequested":
case "Cancelling":
this.iconPath = new vscode.ThemeIcon("circle-slash");
break;
case "Cancelled":
this.iconPath = new vscode.ThemeIcon("circle-slash");
this.contextValue = "result";
this.contextValue = `result${v2Suffix}`;
break;
case "Failed":
this.iconPath = new vscode.ThemeIcon("error");
this.contextValue = "result";
this.contextValue = `result${v2Suffix}`;
break;
case "Completed":
case "Succeeded":
this.iconPath = new vscode.ThemeIcon("pass");
this.contextValue = "result-download";
this.contextValue = `result-download${v2Suffix}`;
break;
}
// Tooltip
Expand Down
43 changes: 38 additions & 5 deletions source/vscode/src/azure/workspaceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,44 @@ import { getRandomGuid } from "../utils";
import { EventType, sendTelemetryEvent, UserFlowStatus } from "../telemetry";
import { getTenantIdAndToken, getTokenForWorkspace } from "./auth";

export function getAzurePortalWorkspaceLink(workspace: WorkspaceConnection) {
// Portal link format:
// - https://portal.azure.com/#resource/subscriptions/<sub guid>/resourceGroups/<group>/providers/Microsoft.Quantum/Workspaces/<name>/overview
export function getQuantumOsJobLink(
workspace: WorkspaceConnection,
jobId: string,
) {
// Quantum OS job page format:
// https://manage.quantum.microsoft.com/jobs/<job-id>
return `https://manage.quantum-test.microsoft.com/jobs/${jobId}`;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should https://manage.quantum-test.microsoft.com be extracted to a constant or setting? I assume this will lose the -test at some point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, having it be a VS Code setting might make it easier to dealt with the lock-step issue between the Quantum OS development and the VS Code extension development.

}

export function getWorkspacePortalLink(workspace: WorkspaceConnection) {
const { isV2Workspace } = QuantumUris.parseEndpointUri(workspace.endpointUri);

if (isV2Workspace) {
// Quantum OS link format:
// https://manage.quantum.microsoft.com/workspaces/<workspace-name>
// #tenantId=<tenant-id>&subscriptionId=<sub-id>&role=Researcher&offeringId=<provider-id>&workspaceId=<workspace-id>
//
// workspace.id starts with '/' (e.g. "/subscriptions/.../Workspaces/<name>"),
// so it is appended directly to produce a clean path with literal slashes.
const idRegex =
/\/subscriptions\/(?<subscriptionId>[^/]+)\/resourceGroups\//;
const subscriptionId =
workspace.id.match(idRegex)?.groups?.subscriptionId ?? "";

const offeringId = workspace.providers[0]?.providerId ?? "";

const fragment =
`tenantId=${workspace.tenantId}` +
`&subscriptionId=${subscriptionId}` +
`&role=Researcher` +
(offeringId ? `&offeringId=${offeringId}` : "") +
`&workspaceId=${workspace.id}`;

return `https://manage.quantum-test.microsoft.com/workspaces/${workspace.name}#${fragment}`;
}

// Azure Portal link format:
// https://portal.azure.com/#resource/subscriptions/<sub guid>/resourceGroups/<group>/providers/Microsoft.Quantum/Workspaces/<name>/overview
return `https://portal.azure.com/#resource${workspace.id}/overview`;
}

Expand Down Expand Up @@ -92,11 +126,10 @@ export function getPythonCodeForWorkspace(
/\/subscriptions\/(?<subscriptionId>[^/]+)\/resourceGroups\/(?<resourceGroup>[^/]+)/;

const idMatch = id.match(idRegex);
const endpointMatch = endpointUri.match(QuantumUris.endpointRegExp);

const subscriptionId = idMatch?.groups?.subscriptionId;
const resourceGroup = idMatch?.groups?.resourceGroup;
const location = endpointMatch?.groups?.location;
const { location } = QuantumUris.parseEndpointUri(endpointUri);

// TODO: Mention how to fetch/use connection strings

Expand Down
Loading