diff --git a/src/polyglot-notebooks-vscode-common/src/extension.ts b/src/polyglot-notebooks-vscode-common/src/extension.ts index 6e54a61d23..2f72a23171 100644 --- a/src/polyglot-notebooks-vscode-common/src/extension.ts +++ b/src/polyglot-notebooks-vscode-common/src/extension.ts @@ -70,9 +70,6 @@ const disposables: (() => void)[] = []; let surveryBanner: SurveyBanner; export async function activate(context: vscode.ExtensionContext) { - const dotnetConfig = vscode.workspace.getConfiguration(constants.DotnetConfigurationSectionName); - const polyglotConfig = vscode.workspace.getConfiguration(constants.PolyglotConfigurationSectionName); - const minDotNetSdkVersion = '9.0'; const diagnosticsChannel = new OutputChannelAdapter(vscode.window.createOutputChannel('Polyglot Notebook : diagnostics')); const loggerChannel = new OutputChannelAdapter(vscode.window.createOutputChannel('Polyglot Notebook : logger')); DotNetPathManager.setOutputChannelAdapter(diagnosticsChannel); @@ -88,6 +85,20 @@ export async function activate(context: vscode.ExtensionContext) { } }); + try { + await activateCore(context, diagnosticsChannel); + } catch (e) { + const errorMessage = e instanceof Error ? e.message : `${e}`; + diagnosticsChannel.appendLine(`Extension activation failed: ${errorMessage}`); + notebookSerializers.createAndRegisterFallbackNotebookSerializers(context, errorMessage); + } +} + +async function activateCore(context: vscode.ExtensionContext, diagnosticsChannel: OutputChannelAdapter) { + const dotnetConfig = vscode.workspace.getConfiguration(constants.DotnetConfigurationSectionName); + const polyglotConfig = vscode.workspace.getConfiguration(constants.PolyglotConfigurationSectionName); + const minDotNetSdkVersion = '9.0'; + await waitForSdkPackExtension(); // this must happen early, because some following functions use the acquisition command diff --git a/src/polyglot-notebooks-vscode-common/src/notebookSerializers.ts b/src/polyglot-notebooks-vscode-common/src/notebookSerializers.ts index adba420ff1..b9ec3a9d8c 100644 --- a/src/polyglot-notebooks-vscode-common/src/notebookSerializers.ts +++ b/src/polyglot-notebooks-vscode-common/src/notebookSerializers.ts @@ -96,6 +96,24 @@ export function createAndRegisterNotebookSerializers(context: vscode.ExtensionCo return serializers; } +export function createAndRegisterFallbackNotebookSerializers(context: vscode.ExtensionContext, activationError: string): void { + const serializer: vscode.NotebookSerializer = { + deserializeNotebook(_content: Uint8Array, _token: vscode.CancellationToken): Promise { + const cellData = new vscode.NotebookCellData( + vscode.NotebookCellKind.Markup, + `## Polyglot Notebooks failed to activate\n\n${activationError}\n\nPlease check the **Polyglot Notebook : diagnostics** output channel for more details.`, + 'markdown' + ); + return Promise.resolve(new vscode.NotebookData([cellData])); + }, + serializeNotebook(_data: vscode.NotebookData, _token: vscode.CancellationToken): Promise { + throw new Error('The Polyglot Notebooks extension failed to activate. Saving is disabled to prevent data loss.'); + }, + }; + const notebookSerializer = vscode.workspace.registerNotebookSerializer(constants.NotebookViewType, serializer); + context.subscriptions.push(notebookSerializer); +} + function toVsCodeNotebookCellData(cell: commandsAndEvents.InteractiveDocumentElement): vscode.NotebookCellData { const cellData = new vscode.NotebookCellData( languageToCellKind(cell.kernelName) as number, diff --git a/src/polyglot-notebooks-vscode-insiders/package.json b/src/polyglot-notebooks-vscode-insiders/package.json index 20a283f755..1b5b0e80e8 100644 --- a/src/polyglot-notebooks-vscode-insiders/package.json +++ b/src/polyglot-notebooks-vscode-insiders/package.json @@ -78,7 +78,7 @@ ] }, { - "type": "polyglot-nortebook-window", + "type": "polyglot-notebook-window", "displayName": "Polyglot Notebook", "selector": [] } diff --git a/src/polyglot-notebooks-vscode/package.json b/src/polyglot-notebooks-vscode/package.json index 894360225f..560c4e64c2 100644 --- a/src/polyglot-notebooks-vscode/package.json +++ b/src/polyglot-notebooks-vscode/package.json @@ -78,7 +78,7 @@ ] }, { - "type": "polyglot-nortebook-window", + "type": "polyglot-notebook-window", "displayName": "Polyglot Notebook", "selector": [] }