mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-25 04:36:23 +00:00
Serializer cleanup
This commit is contained in:
@@ -21,29 +21,22 @@ export class NotebookSerializer implements vscode.NotebookSerializer {
|
||||
} catch {
|
||||
}
|
||||
|
||||
let json: Partial<nbformat.INotebookContent>;
|
||||
try {
|
||||
json = contents ? (JSON.parse(contents) as Partial<nbformat.INotebookContent>) : {};
|
||||
let json = contents ? (JSON.parse(contents) as Partial<nbformat.INotebookContent>) : {};
|
||||
|
||||
if (json.__webview_backup) {
|
||||
const backupId = json.__webview_backup;
|
||||
const uri = this.context.globalStorageUri;
|
||||
const folder = uri.with({ path: this.context.globalStorageUri.path.replace('vscode.ipynb', 'ms-toolsai.jupyter') });
|
||||
const fileHash = fnv.fast1a32hex(backupId) as string;
|
||||
const fileName = `${fileHash}.ipynb`;
|
||||
const file = vscode.Uri.joinPath(folder, fileName);
|
||||
const data = await vscode.workspace.fs.readFile(file);
|
||||
json = data ? JSON.parse(data.toString()) : {};
|
||||
if (json.__webview_backup) {
|
||||
const backupId = json.__webview_backup;
|
||||
const uri = this.context.globalStorageUri;
|
||||
const folder = uri.with({ path: this.context.globalStorageUri.path.replace('vscode.ipynb', 'ms-toolsai.jupyter') });
|
||||
const fileHash = fnv.fast1a32hex(backupId) as string;
|
||||
const fileName = `${fileHash}.ipynb`;
|
||||
const file = vscode.Uri.joinPath(folder, fileName);
|
||||
const data = await vscode.workspace.fs.readFile(file);
|
||||
json = data ? JSON.parse(data.toString()) : {};
|
||||
|
||||
if (json.contents && typeof json.contents === 'string') {
|
||||
contents = json.contents;
|
||||
json = JSON.parse(contents) as Partial<nbformat.INotebookContent>;
|
||||
}
|
||||
if (json.contents && typeof json.contents === 'string') {
|
||||
contents = json.contents;
|
||||
json = JSON.parse(contents) as Partial<nbformat.INotebookContent>;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(contents);
|
||||
console.log(e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Then compute indent from the contents
|
||||
|
||||
Reference in New Issue
Block a user