Skip to content
Merged
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
37 changes: 37 additions & 0 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,43 @@ function registerDocumentUpdateHandlers(languageService: ILanguageService) {
}),
);

// Watch manifest changes and update each document in the same project as the manifest.
subscriptions.push(
vscode.workspace.onDidSaveTextDocument((manifest) => {
updateProjectDocuments(manifest.uri);
}),
);

// Trigger an update on all .qs child documents when their manifest is deleted,
// so that they can get reparented to single-file-projects.
subscriptions.push(
vscode.workspace.onDidDeleteFiles((event) => {
event.files.forEach((uri) => {
updateProjectDocuments(uri);
});
}),
);

// Checks if the URI belongs to a qsharp manifest, and updates all
// open documents in the same project as the manifest.
function updateProjectDocuments(manifest: vscode.Uri) {
if (manifest.scheme === "file" && manifest.fsPath.endsWith("qsharp.json")) {
const project_folder = manifest.fsPath.slice(
0,
manifest.fsPath.length - "qsharp.json".length,
);
vscode.workspace.textDocuments.forEach((document) => {
if (
!document.isClosed &&
// Check that the document is on the same project as the manifest.
document.fileName.startsWith(project_folder)
) {
updateIfQsharpDocument(document);
}
});
}
}

function updateIfQsharpDocument(document: vscode.TextDocument) {
if (isQsharpDocument(document) && !isQsharpNotebookCell(document)) {
// Regular (not notebook) Q# document.
Expand Down