diff --git a/source/pip/qsharp/_qsharp.py b/source/pip/qsharp/_qsharp.py index 118d292a2d..a9072ed8b2 100644 --- a/source/pip/qsharp/_qsharp.py +++ b/source/pip/qsharp/_qsharp.py @@ -40,6 +40,7 @@ import os import sys import types +from pathlib import Path from time import monotonic from dataclasses import make_dataclass @@ -160,8 +161,7 @@ def __init__( # For now, we only support local project roots, so use a file schema in the URI. # In the future, we may support other schemes, such as github, if/when # we have VS Code Web + Jupyter support. - normalized_root = os.path.normpath(os.path.join(os.getcwd(), project_root)) - self._config["projectRoot"] = "file://" + normalized_root + self._config["projectRoot"] = Path(os.getcwd(), project_root).as_uri() def __repr__(self) -> str: return "Q# initialized with configuration: " + str(self._config) diff --git a/source/vscode/src/language-service/notebook.ts b/source/vscode/src/language-service/notebook.ts index 66c2146215..1d9807dc1f 100644 --- a/source/vscode/src/language-service/notebook.ts +++ b/source/vscode/src/language-service/notebook.ts @@ -147,7 +147,16 @@ function getQSharpConfigMetadata(notebook: vscode.NotebookDocument): object { if (data) { const dataString = new TextDecoder().decode(data); log.trace("found Q# config metadata: " + dataString); - return JSON.parse(dataString); + const dataStringJSON = JSON.parse(dataString); + // Re-normalize projectRoot URI if present. + // Python and VS Code have different URI normalization logic, + // so we need to parse and re-serialize it here. + if (typeof dataStringJSON.projectRoot === "string") { + const projectRootUri = vscode.Uri.parse(dataStringJSON.projectRoot, true); + dataStringJSON.projectRoot = projectRootUri.toString(); + } + + return dataStringJSON; } else { // Default to Unrestricted profile for notebooks when no explicit configuration is provided // This aligns with the Python qsharp runtime behavior