mirror of
https://github.com/Microsoft/vscode
synced 2024-10-12 06:17:18 +00:00
Serializer cleanup
This commit is contained in:
parent
52414e5cd8
commit
7caab9b3bc
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue