Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 16 additions & 2 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
16 changes: 11 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,39 @@ export class WorkspaceTreeItem extends vscode.TreeItem {
case "job": {
const job = itemData as Job;
this.collapsibleState = vscode.TreeItemCollapsibleState.None;
const endpointMatch = workspace.endpointUri.match(
Comment thread
ScottCarda-MS marked this conversation as resolved.
Outdated
QuantumUris.endpointRegExp,
);
const isV2Workspace = endpointMatch?.groups?.versionSuffix === "-v2";
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
41 changes: 38 additions & 3 deletions source/vscode/src/azure/workspaceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,45 @@ 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 endpointMatch = workspace.endpointUri.match(QuantumUris.endpointRegExp);
const isV2Workspace = endpointMatch?.groups?.versionSuffix === "-v2";

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
Loading