Skip to content

Commit 6b46945

Browse files
committed
WIP, workspace.textDocuments.map returns notebookcell document => invalid argument
1 parent 112c0f4 commit 6b46945

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/client/repl/nativeRepl.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,30 @@ export class NativeRepl implements Disposable {
156156
* Function that opens interactive repl, selects kernel, and send/execute code to the native repl.
157157
*/
158158
public async sendToNativeRepl(code?: string): Promise<void> {
159+
const mementoValue = (await this.context.globalState.get(NATIVE_REPL_URI_MEMENTO)) as string | undefined;
160+
let mementoUri = mementoValue ? Uri.parse(mementoValue) : undefined;
161+
162+
// const mementoFsPath = mementoUri?.fsPath;
163+
// const openEditorsFsPath = workspace.textDocuments.map((doc) => doc.uri.fsPath);
164+
const openEditors = workspace.textDocuments.map((doc) => doc.uri);
159165
// TODO need to check if that memento URI exist in my tab
160166
// plain untitled notebook same uri as REPL.
161167
// editor option check
162-
const mementoValue = this.context.globalState.get(NATIVE_REPL_URI_MEMENTO) as Uri | undefined;
163-
// mementoValue = undefined;
168+
if (mementoUri && openEditors.includes(mementoUri)) {
169+
this.replUri = mementoUri;
170+
} else {
171+
this.replUri = undefined;
172+
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, undefined);
173+
mementoUri = undefined;
174+
}
164175

165176
// try to restore notebook doc based on memento value.
166177
// if I cant, then clear momento and openInteractiveREPL.
167178

168-
const notebookEditor = await openInteractiveREPL(this.replController, this.notebookDocument, mementoValue);
179+
const notebookEditor = await openInteractiveREPL(this.replController, this.notebookDocument, mementoUri);
169180
this.notebookDocument = notebookEditor.notebook;
170181
this.replUri = this.notebookDocument.uri;
171-
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, this.replUri);
182+
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, this.replUri.toString()); // TODO store Uri as string and then parse this on recovery.
172183

173184
if (this.notebookDocument) {
174185
this.replController.updateNotebookAffinity(this.notebookDocument, NotebookControllerAffinity.Default);

0 commit comments

Comments
 (0)