-
Notifications
You must be signed in to change notification settings - Fork 294
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
Minor refactoring #7837
Minor refactoring #7837
Conversation
Codecov Report
@@ Coverage Diff @@
## main #7837 +/- ##
======================================
- Coverage 70% 69% -1%
======================================
Files 363 362 -1
Lines 22299 22274 -25
Branches 3373 3373
======================================
- Hits 15726 15486 -240
- Misses 5215 5450 +235
+ Partials 1358 1338 -20
|
@@ -164,6 +164,7 @@ export interface IKernelProvider extends IAsyncDisposable { | |||
readonly kernels: Readonly<IKernel[]>; | |||
onDidRestartKernel: Event<IKernel>; | |||
onDidDisposeKernel: Event<IKernel>; | |||
onKernelStatusChanged: Event<{status: ServerStatus, kernel: IKernel}>; |
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.
Moved kernel state change from INotebook to IKernelProvider
@@ -611,7 +609,7 @@ export class Kernel implements IKernel { | |||
} | |||
} | |||
|
|||
export async function executeSilently(session: IJupyterSession, code: string): Promise<nbformat.IOutput[]> { | |||
export async function executeSilently(session: Pick<JupyterKernel.IKernelConnection, 'requestExecute'>, code: string): Promise<nbformat.IOutput[]> { |
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.
We're using Jupyter lab API types directly, not IJupyterSession (makes it easier to re-factor later on to use pure Jupyter npm API)
) { | ||
this.updateContextOfActiveInteractiveWindowKernel(); | ||
} else if (activeEditor && activeEditor.document.uri.toString() === notebook.identity.toString()) { | ||
this.updateContextOfActiveNotebookKernel(activeEditor); | ||
} else if (kernel.notebookDocument.notebookType === JupyterNotebookView && kernel.notebookDocument === this.vscNotebook.activeNotebookEditor?.document) { |
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.
Some cleanup to use IKernel
Also comparing notebook documents instead of comparing strings.
@@ -172,56 +190,7 @@ export class NotebookWatcher implements INotebookWatcher { | |||
} | |||
|
|||
// Check to see if this event was on the active notebook | |||
private async isActiveNotebookEvent(kernelStateEvent: KernelStateEventArgs): Promise<boolean> { |
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.
Cleaned up to use a dictionary instead of an array, we always have notebook documents, hence 1-1 relationship.
kernelStateEvent.cell.executionSummary?.executionOrder | ||
); | ||
} | ||
|
||
// Next, if this is the active document, send out our notifications | ||
if ( | ||
(await this.isActiveNotebookEvent(kernelStateEvent)) && | ||
this.isActiveNotebookEvent(kernelStateEvent) && |
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.
Removed a lot of awaits
@@ -164,6 +164,7 @@ export interface IKernelProvider extends IAsyncDisposable { | |||
readonly kernels: Readonly<IKernel[]>; | |||
onDidRestartKernel: Event<IKernel>; | |||
onDidDisposeKernel: Event<IKernel>; | |||
onKernelStatusChanged: Event<{ status: ServerStatus; kernel: IKernel }>; |
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.
Moved from INotebook to IKernel, easier & looking at NotebookWatcher, we were using Inotebook to detect changes in IKernel,
this change also makes it easier to remove INotbeook (fewer usages)
@@ -611,7 +609,10 @@ export class Kernel implements IKernel { | |||
} | |||
} | |||
|
|||
export async function executeSilently(session: IJupyterSession, code: string): Promise<nbformat.IOutput[]> { | |||
export async function executeSilently( | |||
session: Pick<JupyterKernel.IKernelConnection, 'requestExecute'>, |
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.
No longer using our types, directly using Jupyter Lab API types.
Much easier to refactor later on (as we have fewer layers)
} | ||
public get notebookEditor(): NotebookEditor | undefined { | ||
return this._notebookEditor; | ||
} | ||
public get notebookDocument(): NotebookDocument | undefined { |
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.
Exposed a property notebookDocument
, we have a lot of notebookUri.toString()
comparisons of strings, instead of just comparing the object refs.
be37e66
to
b84eb3a
Compare
@@ -116,7 +125,7 @@ export class DataViewer extends WebviewPanelHost<IDataViewerMapping> implements | |||
public get notebook(): INotebook | undefined { | |||
if (this.dataProvider && 'notebook' in this.dataProvider) { | |||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |||
return (this.dataProvider as any).notebook; | |||
return this.dataProvider.notebook; |
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.
Changed the type of dataProvider
the benefit is strong typeing yes, but this way when we look at removing INotebook
we won't miss such instances (i.e. this change was for future proofing changes related to INotebook)
Was looking at fixing #7697, but then realized its not going to be easy.
This PR only refactors some code that I came across while attempting to fix the issue (fixes have been reverted, but left refactoring)
This can be solved better by only fetching variables when reqruied.
E.g. when using run by line and running to completion I can see variables being requested 4 times, when it should be fetched just once.