Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 14 additions & 3 deletions src/polyglot-notebooks-vscode-common/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 10.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Yes.


await waitForSdkPackExtension();

// this must happen early, because some following functions use the acquisition command
Expand Down
18 changes: 18 additions & 0 deletions src/polyglot-notebooks-vscode-common/src/notebookSerializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscode.NotebookData> {
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<Uint8Array> {
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,
Expand Down
2 changes: 1 addition & 1 deletion src/polyglot-notebooks-vscode-insiders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
]
},
{
"type": "polyglot-nortebook-window",
"type": "polyglot-notebook-window",
"displayName": "Polyglot Notebook",
"selector": []
}
Expand Down
2 changes: 1 addition & 1 deletion src/polyglot-notebooks-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
]
},
{
"type": "polyglot-nortebook-window",
"type": "polyglot-notebook-window",
"displayName": "Polyglot Notebook",
"selector": []
}
Expand Down