-
Notifications
You must be signed in to change notification settings - Fork 12
Getting model from widget first than fallback to documentManager #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
146e6ad
5521434
0c28684
8a4b704
b1124d0
a41f6d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,10 @@ import { PathExt } from '@jupyterlab/coreutils'; | |||||||||
|
|
||||||||||
| import { IDocumentManager } from '@jupyterlab/docmanager'; | ||||||||||
|
|
||||||||||
| import { IDocumentWidget } from '@jupyterlab/docregistry'; | ||||||||||
|
|
||||||||||
| import { INotebookModel, Notebook } from '@jupyterlab/notebook'; | ||||||||||
|
|
||||||||||
| import { UUID } from '@lumino/coreutils'; | ||||||||||
|
|
||||||||||
| import { ISignal, Signal } from '@lumino/signaling'; | ||||||||||
|
|
@@ -24,6 +28,8 @@ import { AISettingsModel } from './models/settings-model'; | |||||||||
|
|
||||||||||
| import { ITokenUsage } from './tokens'; | ||||||||||
|
|
||||||||||
| import { YNotebook } from '@jupyter/ydoc'; | ||||||||||
|
|
||||||||||
| import * as nbformat from '@jupyterlab/nbformat'; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
|
|
@@ -623,23 +629,45 @@ ${toolsList} | |||||||||
| } | ||||||||||
|
|
||||||||||
| try { | ||||||||||
| const model = await this.input.documentManager?.services.contents.get( | ||||||||||
| // Try reading from live notebook if open | ||||||||||
| const widget = this.input.documentManager?.findWidget( | ||||||||||
| attachment.value | ||||||||||
| ); | ||||||||||
| if (!model || model.type !== 'notebook') { | ||||||||||
| return null; | ||||||||||
| } | ||||||||||
| ) as IDocumentWidget<Notebook, INotebookModel> | undefined; | ||||||||||
| let cellData: nbformat.ICell[] | null = null; | ||||||||||
| let kernelLang = 'text'; | ||||||||||
|
|
||||||||||
| const ymodel = widget?.context?.model?.sharedModel as YNotebook; | ||||||||||
|
||||||||||
| const ymodel = widget?.context?.model?.sharedModel as YNotebook; | |
| const ymodel = widget?.context.model.sharedModel as YNotebook; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| nb.metadata?.language_info?.name || | |
| nb.metadata?.kernelspec?.language || | |
| nb.metadata.language_info?.name || | |
| nb.metadata.kernelspec?.language || |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cellData = model.content.cells; | |
| cellData = model.content.cells ?? []; |
Related to above comment
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const cell = cellData!.find(c => c.id === cellInfo.id); | |
| const cell = cellData.find(c => c.id === cellInfo.id); |
Related to above comments
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reach this comparison ?
The YNotebook always has a getSource() function defined, AFAIK https://github.com/jupyter-server/jupyter_ydoc/blob/fdbf658e072467f49048ddef513a5e569207f25b/javascript/src/ynotebook.ts#L408
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are correct Nicolas!. This comparison is unreachable as you say earlier YNotebook always implements getSource(), and getSource() internally calls toJSON().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.