diff --git a/.gitignore b/.gitignore index 49a6f62..0cacf8a 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,5 @@ dmypy.json # Yarn cache .yarn/ -nodpy/tests/nod/** \ No newline at end of file +nodpy/tests/nod/** +demos/** \ No newline at end of file diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index c0045dd..0df696a 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -21,24 +21,16 @@ NODCONFIG - add restart time to nodConfig? (hmm maybe) -Nod Tracking - -- set tracking where? - -- notebook() - - NodInfo (but with code transformed) - - NodLog (but with code transformed) -- write request - - Program info before (but with code transformed) - - Program info after (but with code transformed) -- execute cell -- navigate stackframe -- save notebook -- restart - - whether we write or not TODO - +- dont change cwd +- quit if program finishes without calling notebook? +— display all code above +— Highlight editable code on the scrollbar +— Bash command issue +— Multiple Nod instances +— Modules not available higher up in call stack? +- Nod log — quotes around variable name - add dependency for ipython - path concat bug - run restarts in jupyter terminal window? @@ -62,7 +54,7 @@ TODO 0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation. Nice to have - +- edit function arguments - persist lock through reload? - - clear old kernels from jupyter (get shutdown registering properly??) - layoutrestorer, restorablepool diff --git a/nodpy/__main__.py b/nodpy/__main__.py new file mode 100644 index 0000000..e69de29 diff --git a/nodpy/tests/simpletest.py b/nodpy/tests/simpletest.py index 068817c..c35d6ce 100644 --- a/nodpy/tests/simpletest.py +++ b/nodpy/tests/simpletest.py @@ -6,7 +6,84 @@ x = 0 +# **test comment +# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# **test comment + +# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test# **test comment + + +# test +# test def baller(a, b: int, c: int): global x global z diff --git a/src/codeViewers.ts b/src/codeViewers.ts index e53140b..823dadb 100644 --- a/src/codeViewers.ts +++ b/src/codeViewers.ts @@ -14,10 +14,10 @@ import { } from '@jupyterlab/cells'; import { nodState } from './state'; import { NotebookPanel, INotebookModel } from '@jupyterlab/notebook'; -import { Widget } from '@lumino/widgets'; import { IDisposable, DisposableDelegate } from '@lumino/disposable'; import { DocumentRegistry } from '@jupyterlab/docregistry'; import { hasFileInfo } from './types'; +import { Widget } from '@lumino/widgets'; // const INPUT_AREA_CLASS = 'jp-InputArea'; // const INPUT_AREA_EDITOR_CLASS = 'jp-InputArea-editor'; const NOD_VIEWER_CLASS = 'jp-nod-viewer'; @@ -43,14 +43,34 @@ function addCodeViewers(panel: NotebookPanel) { if (parentNode) { if (panel.isAttached) { - Widget.attach(header, parentNode, innerPanel); - Widget.attach(func, parentNode, innerPanel); + const ref = panel.content.viewportNode.children[0] as HTMLElement; + header.processMessage(Widget.Msg.BeforeAttach); + func.processMessage(Widget.Msg.BeforeAttach); + footer.processMessage(Widget.Msg.BeforeAttach); + panel.content.viewportNode.insertBefore(header.node, ref); + panel.content.viewportNode.insertBefore(func.node, ref); Widget.attach(footer, parentNode); + header.node.dataset.windowedListIndex = `-1`; + func.node.dataset.windowedListIndex = `-1`; + footer.node.dataset.windowedListIndex = `-1`; + header.processMessage(Widget.Msg.AfterAttach); + func.processMessage(Widget.Msg.AfterAttach); + footer.processMessage(Widget.Msg.AfterAttach); } else { panel.revealed.then(() => { - Widget.attach(header, parentNode, innerPanel); - Widget.attach(func, parentNode, innerPanel); + const ref = panel.content.viewportNode.children[0] as HTMLElement; + header.processMessage(Widget.Msg.BeforeAttach); + func.processMessage(Widget.Msg.BeforeAttach); + footer.processMessage(Widget.Msg.BeforeAttach); + panel.content.viewportNode.insertBefore(header.node, ref); + panel.content.viewportNode.insertBefore(func.node, ref); Widget.attach(footer, parentNode); + header.node.dataset.windowedListIndex = `-1`; + func.node.dataset.windowedListIndex = `-1`; + footer.node.dataset.windowedListIndex = `-1`; + header.processMessage(Widget.Msg.AfterAttach); + func.processMessage(Widget.Msg.AfterAttach); + footer.processMessage(Widget.Msg.AfterAttach); }); } } @@ -99,7 +119,7 @@ export function makeCodeViewer( switch (className) { case NOD_HEADER_CLASS: { const text_above = currentFrame.file_info.text_above; - source = text_above.slice(-10).join('').split('\\n').join('\n'); + source = text_above.join('').split('\\n').join('\n'); if (source.startsWith('\n')) { source = source.slice(source.indexOf('\n')); } diff --git a/src/kernelHelpers.ts b/src/kernelHelpers.ts index 0331948..9a6ddf1 100644 --- a/src/kernelHelpers.ts +++ b/src/kernelHelpers.ts @@ -24,29 +24,28 @@ export async function openNotebookWithNodKernel( await state.app.serviceManager.kernels.refreshRunning(); const nodKernelId = await getNodKernel(); - + console.log('finding notebook:', notebookFile); + state.tracker.forEach(panel => { + console.log(panel.context.sessionContext.path); + console.log(panel.context.sessionContext.path === notebookFile); + }); const existingNotebook = state.tracker.find( - panel => panel.context.sessionContext.path === notebookFile + panel => panel.context.sessionContext.path === normalized ); + console.log('opening', normalized, nodKernelId); + const newNotebook = docManager.openOrReveal(normalized, 'default', { + name: 'nod', + id: nodKernelId + }); if (existingNotebook) { console.log('Existing Notebook with Path', existingNotebook); - existingNotebook.sessionContext.kernelPreference = { - // autoStartDefault: false, - name: 'nod', - id: nodKernelId, - shutdownOnDispose: false - }; - state.app.shell.activateById(existingNotebook.id); - // state.sessionManager.connectTo - existingNotebook.context.sessionContext.changeKernel({ - name: 'nod', - id: state.nodKernelId - }); } else { - console.log('opening', normalized, nodKernelId); - docManager.openOrReveal(normalized, 'default', { - name: 'nod', - id: nodKernelId + newNotebook?.revealed.then(() => { + nodState + .Instance() + .tracker.currentWidget?.content.activeCell!.node.scrollIntoView({ + block: 'center' + }); }); } }