Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS Code extension throws on launch if Q# notebook cell is open #2044

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

minestarks
Copy link
Member

@minestarks minestarks commented Nov 25, 2024

Repro

  1. Create a notebook like so - with one cell with language set to "Q#" but no %%qsharp magic

image

  1. Save this notebook, and launch VS Code with only this notebook open

Exception:

2024-11-25 12:23:42.755 [error] ReferenceError: Cannot access 'defaultLanguageId' before initialization
	at updateQSharpCellLanguages (http://localhost:3000/static/devextensions/out/extension.js#vscode-extension:40620:57)
	at eval (http://localhost:3000/static/devextensions/out/extension.js#vscode-extension:40577:7)
	at Array.forEach (<anonymous>)
	at registerQSharpNotebookHandlers (http://localhost:3000/static/devextensions/out/extension.js#vscode-extension:40575:40)
	at activate (http://localhost:3000/static/devextensions/out/extension.js#vscode-extension:40979:33)
	at async F1.n (http://localhost:3000/static/build/out/vs/workbench/api/worker/extensionHostWorkerMain.js:113:4450)
	at async F1.m (http://localhost:3000/static/build/out/vs/workbench/api/worker/extensionHostWorkerMain.js:113:4413)
	at async F1.l (http://localhost:3000/static/build/out/vs/workbench/api/worker/extensionHostWorkerMain.js:113:3869)

The bug comes down to this sort of pattern causing an exception in JavaScript:

foo(); // ReferenceError: Cannot access 'x' before initialization

let x = 1;

function foo() { x } 

Fix is to declare defaultLanguageId at the global scope so that initialization is guaranteed before the function that closes over it is ever called.

@minestarks minestarks added this pull request to the merge queue Nov 26, 2024
Merged via the queue into main with commit 178bd78 Nov 26, 2024
18 checks passed
@minestarks minestarks deleted the minestarks/exception-activate branch November 26, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants