Skip to content

Commit

Permalink
use watching of notebookDocument instead of textEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Nov 14, 2024
1 parent 74a31ef commit 640e976
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/client/extensionActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ export function activateFeatures(ext: ExtensionState, _components: Components):
registerReplCommands(ext.disposables, interpreterService, executionHelper, commandManager, ext.context);
registerReplExecuteOnEnter(ext.disposables, interpreterService, commandManager, ext.context);

// TODO check tabs and if they match with memto it knows about.
// create repl, reload repl, close tab, then open notebook, and then we fall into trap where we think notebook is repl.
// 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.
// check label of editor name - if its python repl or not.
}

Expand Down
26 changes: 9 additions & 17 deletions src/client/repl/nativeRepl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,36 +158,28 @@ export class NativeRepl implements Disposable {
public async sendToNativeRepl(code?: string): Promise<void> {
const mementoValue = (await this.context.globalState.get(NATIVE_REPL_URI_MEMENTO)) as string | undefined;
let mementoUri = mementoValue ? Uri.parse(mementoValue) : undefined;
const openNotebookDocuments = workspace.notebookDocuments.map((doc) => doc.uri);

// const mementoFsPath = mementoUri?.fsPath;

const openEditors = workspace.textDocuments.map((doc) => doc.uri);
const openEditorsFsPath = workspace.textDocuments.map((doc) => doc.uri.fsPath);
// TODO need to check if that memento URI exist in my tab
// plain untitled notebook same uri as REPL.
// editor option check
if (mementoUri?.fsPath) {
const matchingEditor = openEditors.find((uri) => uri.fsPath === mementoUri?.fsPath);
if (matchingEditor) {
this.replUri = matchingEditor;
if (mementoUri) {
const replTabBeforeReload = openNotebookDocuments.find((uri) => uri.fsPath === mementoUri?.fsPath);
if (replTabBeforeReload) {
this.replUri = replTabBeforeReload;
this.notebookDocument = workspace.notebookDocuments.find(
(doc) => doc.uri.fsPath === matchingEditor.fsPath,
(doc) => doc.uri.fsPath === replTabBeforeReload.fsPath,
);
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, this.replUri.toString());
}
} else {
this.replUri = undefined;
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, undefined);
mementoUri = undefined;
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, undefined);
}

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

const notebookEditor = await openInteractiveREPL(this.replController, this.notebookDocument, mementoUri);

this.notebookDocument = notebookEditor.notebook;
this.replUri = this.notebookDocument.uri;
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, this.replUri.toString()); // TODO store Uri as string and then parse this on recovery.
await this.context.globalState.update(NATIVE_REPL_URI_MEMENTO, this.replUri.toString());

if (this.notebookDocument) {
this.replController.updateNotebookAffinity(this.notebookDocument, NotebookControllerAffinity.Default);
Expand Down

0 comments on commit 640e976

Please sign in to comment.