Skip to content

Commit 9d2b8da

Browse files
authored
[Language Service] Fix project path on notebooks when running on Windows (#2872)
Fixes #2866
1 parent 3dc2d18 commit 9d2b8da

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

source/pip/qsharp/_qsharp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import os
4141
import sys
4242
import types
43+
from pathlib import Path
4344
from time import monotonic
4445
from dataclasses import make_dataclass
4546

@@ -160,8 +161,7 @@ def __init__(
160161
# For now, we only support local project roots, so use a file schema in the URI.
161162
# In the future, we may support other schemes, such as github, if/when
162163
# we have VS Code Web + Jupyter support.
163-
normalized_root = os.path.normpath(os.path.join(os.getcwd(), project_root))
164-
self._config["projectRoot"] = "file://" + normalized_root
164+
self._config["projectRoot"] = Path(os.getcwd(), project_root).as_uri()
165165

166166
def __repr__(self) -> str:
167167
return "Q# initialized with configuration: " + str(self._config)

source/vscode/src/language-service/notebook.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,16 @@ function getQSharpConfigMetadata(notebook: vscode.NotebookDocument): object {
147147
if (data) {
148148
const dataString = new TextDecoder().decode(data);
149149
log.trace("found Q# config metadata: " + dataString);
150-
return JSON.parse(dataString);
150+
const dataStringJSON = JSON.parse(dataString);
151+
// Re-normalize projectRoot URI if present.
152+
// Python and VS Code have different URI normalization logic,
153+
// so we need to parse and re-serialize it here.
154+
if (typeof dataStringJSON.projectRoot === "string") {
155+
const projectRootUri = vscode.Uri.parse(dataStringJSON.projectRoot, true);
156+
dataStringJSON.projectRoot = projectRootUri.toString();
157+
}
158+
159+
return dataStringJSON;
151160
} else {
152161
// Default to Unrestricted profile for notebooks when no explicit configuration is provided
153162
// This aligns with the Python qsharp runtime behavior

0 commit comments

Comments
 (0)