Skip to content

Commit

Permalink
fix: Cell tracking issue, with unsaved notebooks
Browse files Browse the repository at this point in the history
Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
  • Loading branch information
GordonSmith committed Oct 9, 2023
1 parent 99c9b2a commit 8365ee6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/notebook/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ export class Controller {
break;
}
});

vscode.workspace.onDidChangeNotebookDocument(evt => {
for (const contentChange of evt.contentChanges) {
for (const removed of contentChange.removedCells) {
const execution = this._controller.createNotebookCellExecution(removed);
execution.executionOrder = ++this._executionOrder;
execution.start(Date.now());
execution.clearOutput(removed);
execution.end(true, Date.now());
}
}
});

}

configToIOptions(config?: LaunchRequestArguments): IOptions {
Expand Down
10 changes: 7 additions & 3 deletions src/notebook/controller/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Serializer implements NotebookSerializer {

node(cell: NotebookCell): ohq.Node {
return this._meta.node[cell.metadata?.id] ?? {
id: uuidv4(),
id: `tmp-${cell.index}`,
mode: cell.document.languageId,
value: cell.document.getText()
};
Expand Down Expand Up @@ -207,6 +207,7 @@ export class Serializer implements NotebookSerializer {
const jsonNotebook: ohq.Notebook = this._meta.notebook[data.metadata?.id];
jsonNotebook.nodes = [];

let cellIndex = 0;
for (const cell of data.cells) {
let mode: string;
const outputs: string[] = [];
Expand Down Expand Up @@ -235,15 +236,18 @@ export class Serializer implements NotebookSerializer {
} catch (e) { }
});
});
const node: Partial<ohq.Node> = this._meta.node[cell.metadata?.id];
cell.metadata = cell.metadata ?? {};
cell.metadata.id = cell.metadata?.id ?? `tmp-${cellIndex++}`;
const node: Partial<ohq.Node> = this._meta.node[cell.metadata.id];
const item: ohq.Node = {
id: cell.metadata?.id ?? uuidv4(),
id: cell.metadata?.id,
name: "",
...node,
value: cell.value,
mode,
outputs
};
this._meta.node[cell.metadata.id] = item;
jsonNotebook.nodes.push(item);
}

Expand Down

0 comments on commit 8365ee6

Please sign in to comment.