Skip to content

Commit 640e976

Browse files
committed
use watching of notebookDocument instead of textEditor
1 parent 74a31ef commit 640e976

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

src/client/extensionActivation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ export function activateFeatures(ext: ExtensionState, _components: Components):
116116
registerReplCommands(ext.disposables, interpreterService, executionHelper, commandManager, ext.context);
117117
registerReplExecuteOnEnter(ext.disposables, interpreterService, commandManager, ext.context);
118118

119-
// TODO check tabs and if they match with memto it knows about.
120-
// create repl, reload repl, close tab, then open notebook, and then we fall into trap where we think notebook is repl.
119+
// TODO cover edge case: create repl, reload repl, close tab, then open notebook, and then we fall into trap where we think notebook is repl.
121120
// check label of editor name - if its python repl or not.
122121
}
123122

src/client/repl/nativeRepl.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,36 +158,28 @@ export class NativeRepl implements Disposable {
158158
public async sendToNativeRepl(code?: string): Promise<void> {
159159
const mementoValue = (await this.context.globalState.get(NATIVE_REPL_URI_MEMENTO)) as string | undefined;
160160
let mementoUri = mementoValue ? Uri.parse(mementoValue) : undefined;
161+
const openNotebookDocuments = workspace.notebookDocuments.map((doc) => doc.uri);
161162

162-
// const mementoFsPath = mementoUri?.fsPath;
163-
164-
const openEditors = workspace.textDocuments.map((doc) => doc.uri);
165-
const openEditorsFsPath = workspace.textDocuments.map((doc) => doc.uri.fsPath);
166-
// TODO need to check if that memento URI exist in my tab
167-
// plain untitled notebook same uri as REPL.
168-
// editor option check
169-
if (mementoUri?.fsPath) {
170-
const matchingEditor = openEditors.find((uri) => uri.fsPath === mementoUri?.fsPath);
171-
if (matchingEditor) {
172-
this.replUri = matchingEditor;
163+
if (mementoUri) {
164+
const replTabBeforeReload = openNotebookDocuments.find((uri) => uri.fsPath === mementoUri?.fsPath);
165+
if (replTabBeforeReload) {
166+
this.replUri = replTabBeforeReload;
173167
this.notebookDocument = workspace.notebookDocuments.find(
174-
(doc) => doc.uri.fsPath === matchingEditor.fsPath,
168+
(doc) => doc.uri.fsPath === replTabBeforeReload.fsPath,
175169
);
176170
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, this.replUri.toString());
177171
}
178172
} else {
179173
this.replUri = undefined;
180-
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, undefined);
181174
mementoUri = undefined;
175+
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, undefined);
182176
}
183177

184-
// try to restore notebook doc based on memento value.
185-
// if I cant, then clear momento and openInteractiveREPL.
186-
187178
const notebookEditor = await openInteractiveREPL(this.replController, this.notebookDocument, mementoUri);
179+
188180
this.notebookDocument = notebookEditor.notebook;
189181
this.replUri = this.notebookDocument.uri;
190-
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, this.replUri.toString()); // TODO store Uri as string and then parse this on recovery.
182+
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, this.replUri.toString());
191183

192184
if (this.notebookDocument) {
193185
this.replController.updateNotebookAffinity(this.notebookDocument, NotebookControllerAffinity.Default);

0 commit comments

Comments
 (0)