Skip to content
Closed
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
3 changes: 2 additions & 1 deletion vscode/src/language-service/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function getQSharpConfigMetadata(notebook: vscode.NotebookDocument): object {
log.trace("found Q# config metadata: " + dataString);
return JSON.parse(dataString);
} else {
return {};
// Default notebooks to unrestricted target profile when no explicit configuration is provided
return { targetProfile: "unrestricted" };
}
}
41 changes: 41 additions & 0 deletions vscode/test/suites/language-service/notebook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,45 @@ suite("Q# Notebook Tests", function suite() {
assert.equal(location.range.start.line, 2);
assert.equal(location.range.start.character, 10);
});

test("Notebook defaults to unrestricted target profile", async () => {
const notebook = await vscode.workspace.openNotebookDocument(
vscode.Uri.joinPath(
workspaceFolderUri,
"test-unrestricted-default.ipynb",
),
);

const qsharpCellUri = notebook.cellAt(1).document.uri;

// Wait for the Q# cell to be detected by the language service
await waitForCondition(
() =>
!!notebook
.getCells()
.find((cell) => cell.document.languageId === "qsharp"),
vscode.workspace.onDidChangeNotebookDocument,
2000,
"timed out waiting for Q# code cell",
);

// Verify that there are no target profile related diagnostics for unrestricted operations
// We use waitForCondition to ensure we give enough time for any diagnostics to appear,
// then verify that none of them are target profile related
await waitForCondition(
() => {
const diagnostics = vscode.languages.getDiagnostics(qsharpCellUri);
// Filter for target profile related errors - there should be none
const profileErrors = diagnostics.filter(
(d) =>
d.message.includes("dynamic bool") ||
d.message.includes("target profile"),
);
return profileErrors.length === 0;
},
vscode.languages.onDidChangeDiagnostics,
3000,
"expected no target profile related diagnostics for unrestricted operations",
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "1e8e4faa",
"metadata": {},
"outputs": [],
"source": [
"import qsharp\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1b55e53c",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"%%qsharp\n",
"\n",
"operation TestUnrestrictedDefault() : Unit {\n",
" use q = Qubit();\n",
" H(q);\n",
" if (M(q) == One) {\n",
" Reset(q);\n",
" } else {\n",
" X(q);\n",
" }\n",
"}\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading