diff --git a/vscode/src/language-service/notebook.ts b/vscode/src/language-service/notebook.ts index eeb05809d3..9a2b6f6e12 100644 --- a/vscode/src/language-service/notebook.ts +++ b/vscode/src/language-service/notebook.ts @@ -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" }; } } diff --git a/vscode/test/suites/language-service/notebook.test.ts b/vscode/test/suites/language-service/notebook.test.ts index 1f298783ae..e09be71b1e 100644 --- a/vscode/test/suites/language-service/notebook.test.ts +++ b/vscode/test/suites/language-service/notebook.test.ts @@ -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", + ); + }); }); diff --git a/vscode/test/suites/language-service/test-workspace/test-unrestricted-default.ipynb b/vscode/test/suites/language-service/test-workspace/test-unrestricted-default.ipynb new file mode 100644 index 0000000000..9716271462 --- /dev/null +++ b/vscode/test/suites/language-service/test-workspace/test-unrestricted-default.ipynb @@ -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 +} \ No newline at end of file