Skip to content

Commit c8266b6

Browse files
authored
Update notebook API with latest changes (#13836)
1 parent d061ed8 commit c8266b6

File tree

5 files changed

+132
-31
lines changed

5 files changed

+132
-31
lines changed

src/client/datascience/jupyter/kernels/kernelSelections.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ export class KernelSelectionProvider {
207207
private remoteSuggestionsCache: IKernelSpecQuickPickItem<
208208
LiveKernelConnectionMetadata | KernelSpecConnectionMetadata
209209
>[] = [];
210-
private _listChanged = new EventEmitter<void>();
211-
public get SelectionsChanged() {
210+
private _listChanged = new EventEmitter<Resource>();
211+
public get onDidChangeSelections() {
212212
return this._listChanged.event;
213213
}
214214
constructor(
@@ -357,7 +357,7 @@ export class KernelSelectionProvider {
357357
liveItemsList.length > 0 &&
358358
JSON.stringify(liveItemsList) !== JSON.stringify(cachedItemsList)
359359
) {
360-
this._listChanged.fire();
360+
this._listChanged.fire(resource);
361361
}
362362
} catch (ex) {
363363
traceError('Error in fetching kernel selections', ex);

src/client/datascience/notebook/kernelProvider.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class VSCodeNotebookKernelMetadata implements VSCNotebookKernel {
5454

5555
@injectable()
5656
export class VSCodeKernelPickerProvider implements NotebookKernelProvider {
57-
public get onDidChangeKernels(): Event<void> {
57+
public get onDidChangeKernels(): Event<NotebookDocument | undefined> {
5858
return this._onDidChangeKernels.event;
5959
}
60-
private readonly _onDidChangeKernels = new EventEmitter<void>();
60+
private readonly _onDidChangeKernels = new EventEmitter<NotebookDocument | undefined>();
6161
private notebookKernelChangeHandled = new WeakSet<INotebook>();
6262
constructor(
6363
@inject(KernelSelectionProvider) private readonly kernelSelectionProvider: KernelSelectionProvider,
@@ -70,7 +70,19 @@ export class VSCodeKernelPickerProvider implements NotebookKernelProvider {
7070
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
7171
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService
7272
) {
73-
this.kernelSelectionProvider.SelectionsChanged(() => this._onDidChangeKernels.fire(), this, disposables);
73+
this.kernelSelectionProvider.onDidChangeSelections(
74+
(e) => {
75+
if (e) {
76+
const doc = this.notebook.notebookDocuments.find((d) => d.uri.fsPath === e.fsPath);
77+
if (doc) {
78+
return this._onDidChangeKernels.fire(doc);
79+
}
80+
}
81+
this._onDidChangeKernels.fire(undefined);
82+
},
83+
this,
84+
disposables
85+
);
7486
this.notebook.onDidChangeActiveNotebookKernel(this.onDidChangeActiveNotebookKernel, this, disposables);
7587
}
7688
public async provideKernels(

types/vscode-proposed/index.d.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ export interface NotebookDocument {
222222
readonly isUntitled: boolean;
223223
readonly cells: ReadonlyArray<NotebookCell>;
224224
languages: string[];
225-
displayOrder?: GlobPattern[];
226225
metadata: NotebookDocumentMetadata;
227226
}
228227

@@ -280,6 +279,27 @@ export interface NotebookEditorCellEdit {
280279
delete(index: number): void;
281280
}
282281

282+
export interface NotebookCellRange {
283+
readonly start: number;
284+
readonly end: number;
285+
}
286+
287+
export enum NotebookEditorRevealType {
288+
/**
289+
* The range will be revealed with as little scrolling as possible.
290+
*/
291+
Default = 0,
292+
/**
293+
* The range will always be revealed in the center of the viewport.
294+
*/
295+
InCenter = 1,
296+
/**
297+
* If the range is outside the viewport, it will be revealed in the center of the viewport.
298+
* Otherwise, it will be revealed with as little scrolling as possible.
299+
*/
300+
InCenterIfOutsideViewport = 2
301+
}
302+
283303
export interface NotebookEditor {
284304
/**
285305
* The document associated with this notebook editor.
@@ -291,6 +311,11 @@ export interface NotebookEditor {
291311
*/
292312
readonly selection?: NotebookCell;
293313

314+
/**
315+
* The current visible ranges in the editor (vertically).
316+
*/
317+
readonly visibleRanges: NotebookCellRange[];
318+
294319
/**
295320
* The column in which this editor shows.
296321
*/
@@ -335,6 +360,8 @@ export interface NotebookEditor {
335360
asWebviewUri(localResource: Uri): Uri;
336361

337362
edit(callback: (editBuilder: NotebookEditorCellEdit) => void): Thenable<boolean>;
363+
364+
revealRange(range: NotebookCellRange, revealType?: NotebookEditorRevealType): void;
338365
}
339366

340367
export interface NotebookOutputSelector {
@@ -398,6 +425,11 @@ export interface NotebookEditorSelectionChangeEvent {
398425
readonly selection?: NotebookCell;
399426
}
400427

428+
export interface NotebookEditorVisibleRangesChangeEvent {
429+
readonly notebookEditor: NotebookEditor;
430+
readonly visibleRanges: ReadonlyArray<NotebookCellRange>;
431+
}
432+
401433
export interface NotebookCellData {
402434
readonly cellKind: CellKind;
403435
readonly source: string;
@@ -529,6 +561,7 @@ export interface NotebookKernel {
529561
readonly id?: string;
530562
label: string;
531563
description?: string;
564+
detail?: string;
532565
isPreferred?: boolean;
533566
preloads?: Uri[];
534567
executeCell(document: NotebookDocument, cell: NotebookCell): void;
@@ -538,13 +571,12 @@ export interface NotebookKernel {
538571
}
539572

540573
export interface NotebookDocumentFilter {
541-
viewType?: string;
542-
filenamePattern?: GlobPattern;
543-
excludeFileNamePattern?: GlobPattern;
574+
viewType?: string | string[];
575+
filenamePattern?: GlobPattern | { include: GlobPattern; exclude: GlobPattern };
544576
}
545577

546578
export interface NotebookKernelProvider<T extends NotebookKernel = NotebookKernel> {
547-
onDidChangeKernels?: Event<void>;
579+
onDidChangeKernels?: Event<NotebookDocument | undefined>;
548580
provideKernels(document: NotebookDocument, token: CancellationToken): ProviderResult<T[]>;
549581
resolveKernel?(
550582
kernel: T,
@@ -605,8 +637,6 @@ export namespace notebook {
605637
provider: NotebookKernelProvider
606638
): Disposable;
607639

608-
export function registerNotebookKernel(id: string, selectors: GlobPattern[], kernel: NotebookKernel): Disposable;
609-
610640
export const onDidOpenNotebookDocument: Event<NotebookDocument>;
611641
export const onDidCloseNotebookDocument: Event<NotebookDocument>;
612642
export const onDidSaveNotebookDocument: Event<NotebookDocument>;
@@ -622,6 +652,7 @@ export namespace notebook {
622652
export const activeNotebookEditor: NotebookEditor | undefined;
623653
export const onDidChangeActiveNotebookEditor: Event<NotebookEditor | undefined>;
624654
export const onDidChangeNotebookEditorSelection: Event<NotebookEditorSelectionChangeEvent>;
655+
export const onDidChangeNotebookEditorVisibleRanges: Event<NotebookEditorVisibleRangesChangeEvent>;
625656
export const onDidChangeNotebookCells: Event<NotebookCellsChangeEvent>;
626657
export const onDidChangeCellOutputs: Event<NotebookCellOutputsChangeEvent>;
627658
export const onDidChangeCellLanguage: Event<NotebookCellLanguageChangeEvent>;

types/vscode.proposed.d.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ declare module 'vscode' {
208208
readonly isUntitled: boolean;
209209
readonly cells: ReadonlyArray<NotebookCell>;
210210
languages: string[];
211-
displayOrder?: GlobPattern[];
212211
metadata: NotebookDocumentMetadata;
213212
}
214213

@@ -266,6 +265,27 @@ declare module 'vscode' {
266265
delete(index: number): void;
267266
}
268267

268+
export interface NotebookCellRange {
269+
readonly start: number;
270+
readonly end: number;
271+
}
272+
273+
export enum NotebookEditorRevealType {
274+
/**
275+
* The range will be revealed with as little scrolling as possible.
276+
*/
277+
Default = 0,
278+
/**
279+
* The range will always be revealed in the center of the viewport.
280+
*/
281+
InCenter = 1,
282+
/**
283+
* If the range is outside the viewport, it will be revealed in the center of the viewport.
284+
* Otherwise, it will be revealed with as little scrolling as possible.
285+
*/
286+
InCenterIfOutsideViewport = 2
287+
}
288+
269289
export interface NotebookEditor {
270290
/**
271291
* The document associated with this notebook editor.
@@ -277,6 +297,11 @@ declare module 'vscode' {
277297
*/
278298
readonly selection?: NotebookCell;
279299

300+
/**
301+
* The current visible ranges in the editor (vertically).
302+
*/
303+
readonly visibleRanges: NotebookCellRange[];
304+
280305
/**
281306
* The column in which this editor shows.
282307
*/
@@ -321,6 +346,8 @@ declare module 'vscode' {
321346
asWebviewUri(localResource: Uri): Uri;
322347

323348
edit(callback: (editBuilder: NotebookEditorCellEdit) => void): Thenable<boolean>;
349+
350+
revealRange(range: NotebookCellRange, revealType?: NotebookEditorRevealType): void;
324351
}
325352

326353
export interface NotebookOutputSelector {
@@ -384,6 +411,11 @@ declare module 'vscode' {
384411
readonly selection?: NotebookCell;
385412
}
386413

414+
export interface NotebookEditorVisibleRangesChangeEvent {
415+
readonly notebookEditor: NotebookEditor;
416+
readonly visibleRanges: ReadonlyArray<NotebookCellRange>;
417+
}
418+
387419
export interface NotebookCellData {
388420
readonly cellKind: CellKind;
389421
readonly source: string;
@@ -515,6 +547,7 @@ declare module 'vscode' {
515547
readonly id?: string;
516548
label: string;
517549
description?: string;
550+
detail?: string;
518551
isPreferred?: boolean;
519552
preloads?: Uri[];
520553
executeCell(document: NotebookDocument, cell: NotebookCell): void;
@@ -524,13 +557,12 @@ declare module 'vscode' {
524557
}
525558

526559
export interface NotebookDocumentFilter {
527-
viewType?: string;
528-
filenamePattern?: GlobPattern;
529-
excludeFileNamePattern?: GlobPattern;
560+
viewType?: string | string[];
561+
filenamePattern?: GlobPattern | { include: GlobPattern; exclude: GlobPattern };
530562
}
531563

532564
export interface NotebookKernelProvider<T extends NotebookKernel = NotebookKernel> {
533-
onDidChangeKernels?: Event<void>;
565+
onDidChangeKernels?: Event<NotebookDocument | undefined>;
534566
provideKernels(document: NotebookDocument, token: CancellationToken): ProviderResult<T[]>;
535567
resolveKernel?(
536568
kernel: T,
@@ -591,12 +623,6 @@ declare module 'vscode' {
591623
provider: NotebookKernelProvider
592624
): Disposable;
593625

594-
export function registerNotebookKernel(
595-
id: string,
596-
selectors: GlobPattern[],
597-
kernel: NotebookKernel
598-
): Disposable;
599-
600626
export const onDidOpenNotebookDocument: Event<NotebookDocument>;
601627
export const onDidCloseNotebookDocument: Event<NotebookDocument>;
602628
export const onDidSaveNotebookDocument: Event<NotebookDocument>;
@@ -612,6 +638,7 @@ declare module 'vscode' {
612638
export const activeNotebookEditor: NotebookEditor | undefined;
613639
export const onDidChangeActiveNotebookEditor: Event<NotebookEditor | undefined>;
614640
export const onDidChangeNotebookEditorSelection: Event<NotebookEditorSelectionChangeEvent>;
641+
export const onDidChangeNotebookEditorVisibleRanges: Event<NotebookEditorVisibleRangesChangeEvent>;
615642
export const onDidChangeNotebookCells: Event<NotebookCellsChangeEvent>;
616643
export const onDidChangeCellOutputs: Event<NotebookCellOutputsChangeEvent>;
617644
export const onDidChangeCellLanguage: Event<NotebookCellLanguageChangeEvent>;

typings/vscode-proposed/index.d.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ export interface NotebookDocument {
222222
readonly isUntitled: boolean;
223223
readonly cells: ReadonlyArray<NotebookCell>;
224224
languages: string[];
225-
displayOrder?: GlobPattern[];
226225
metadata: NotebookDocumentMetadata;
227226
}
228227

@@ -280,6 +279,27 @@ export interface NotebookEditorCellEdit {
280279
delete(index: number): void;
281280
}
282281

282+
export interface NotebookCellRange {
283+
readonly start: number;
284+
readonly end: number;
285+
}
286+
287+
export enum NotebookEditorRevealType {
288+
/**
289+
* The range will be revealed with as little scrolling as possible.
290+
*/
291+
Default = 0,
292+
/**
293+
* The range will always be revealed in the center of the viewport.
294+
*/
295+
InCenter = 1,
296+
/**
297+
* If the range is outside the viewport, it will be revealed in the center of the viewport.
298+
* Otherwise, it will be revealed with as little scrolling as possible.
299+
*/
300+
InCenterIfOutsideViewport = 2
301+
}
302+
283303
export interface NotebookEditor {
284304
/**
285305
* The document associated with this notebook editor.
@@ -291,6 +311,11 @@ export interface NotebookEditor {
291311
*/
292312
readonly selection?: NotebookCell;
293313

314+
/**
315+
* The current visible ranges in the editor (vertically).
316+
*/
317+
readonly visibleRanges: NotebookCellRange[];
318+
294319
/**
295320
* The column in which this editor shows.
296321
*/
@@ -335,6 +360,8 @@ export interface NotebookEditor {
335360
asWebviewUri(localResource: Uri): Uri;
336361

337362
edit(callback: (editBuilder: NotebookEditorCellEdit) => void): Thenable<boolean>;
363+
364+
revealRange(range: NotebookCellRange, revealType?: NotebookEditorRevealType): void;
338365
}
339366

340367
export interface NotebookOutputSelector {
@@ -398,6 +425,11 @@ export interface NotebookEditorSelectionChangeEvent {
398425
readonly selection?: NotebookCell;
399426
}
400427

428+
export interface NotebookEditorVisibleRangesChangeEvent {
429+
readonly notebookEditor: NotebookEditor;
430+
readonly visibleRanges: ReadonlyArray<NotebookCellRange>;
431+
}
432+
401433
export interface NotebookCellData {
402434
readonly cellKind: CellKind;
403435
readonly source: string;
@@ -529,6 +561,7 @@ export interface NotebookKernel {
529561
readonly id?: string;
530562
label: string;
531563
description?: string;
564+
detail?: string;
532565
isPreferred?: boolean;
533566
preloads?: Uri[];
534567
executeCell(document: NotebookDocument, cell: NotebookCell): void;
@@ -538,13 +571,12 @@ export interface NotebookKernel {
538571
}
539572

540573
export interface NotebookDocumentFilter {
541-
viewType?: string;
542-
filenamePattern?: GlobPattern;
543-
excludeFileNamePattern?: GlobPattern;
574+
viewType?: string | string[];
575+
filenamePattern?: GlobPattern | { include: GlobPattern; exclude: GlobPattern };
544576
}
545577

546578
export interface NotebookKernelProvider<T extends NotebookKernel = NotebookKernel> {
547-
onDidChangeKernels?: Event<void>;
579+
onDidChangeKernels?: Event<NotebookDocument | undefined>;
548580
provideKernels(document: NotebookDocument, token: CancellationToken): ProviderResult<T[]>;
549581
resolveKernel?(
550582
kernel: T,
@@ -605,8 +637,6 @@ export namespace notebook {
605637
provider: NotebookKernelProvider
606638
): Disposable;
607639

608-
export function registerNotebookKernel(id: string, selectors: GlobPattern[], kernel: NotebookKernel): Disposable;
609-
610640
export const onDidOpenNotebookDocument: Event<NotebookDocument>;
611641
export const onDidCloseNotebookDocument: Event<NotebookDocument>;
612642
export const onDidSaveNotebookDocument: Event<NotebookDocument>;
@@ -622,6 +652,7 @@ export namespace notebook {
622652
export const activeNotebookEditor: NotebookEditor | undefined;
623653
export const onDidChangeActiveNotebookEditor: Event<NotebookEditor | undefined>;
624654
export const onDidChangeNotebookEditorSelection: Event<NotebookEditorSelectionChangeEvent>;
655+
export const onDidChangeNotebookEditorVisibleRanges: Event<NotebookEditorVisibleRangesChangeEvent>;
625656
export const onDidChangeNotebookCells: Event<NotebookCellsChangeEvent>;
626657
export const onDidChangeCellOutputs: Event<NotebookCellOutputsChangeEvent>;
627658
export const onDidChangeCellLanguage: Event<NotebookCellLanguageChangeEvent>;

0 commit comments

Comments
 (0)