Skip to content

Commit

Permalink
Improved ability to overwrite notebook services (eclipse-theia#13776)
Browse files Browse the repository at this point in the history
* improved ability to overwrite notebook services
private fields and methods to protected

Signed-off-by: Jonah Iden <[email protected]>

* more private to protected

Signed-off-by: Jonah Iden <[email protected]>

---------

Signed-off-by: Jonah Iden <[email protected]>
  • Loading branch information
jonah-iden authored Jun 6, 2024
1 parent e0517ad commit fcd227a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export class NotebookEditorWidgetService {
@inject(ContextKeyService)
protected contextKeyService: ContextKeyService;

private readonly notebookEditors = new Map<string, NotebookEditorWidget>();
protected readonly notebookEditors = new Map<string, NotebookEditorWidget>();

private readonly onNotebookEditorAddEmitter = new Emitter<NotebookEditorWidget>();
private readonly onNotebookEditorRemoveEmitter = new Emitter<NotebookEditorWidget>();
protected readonly onNotebookEditorAddEmitter = new Emitter<NotebookEditorWidget>();
protected readonly onNotebookEditorRemoveEmitter = new Emitter<NotebookEditorWidget>();
readonly onDidAddNotebookEditor = this.onNotebookEditorAddEmitter.event;
readonly onDidRemoveNotebookEditor = this.onNotebookEditorRemoveEmitter.event;

private readonly onDidChangeFocusedEditorEmitter = new Emitter<NotebookEditorWidget | undefined>();
protected readonly onDidChangeFocusedEditorEmitter = new Emitter<NotebookEditorWidget | undefined>();
readonly onDidChangeFocusedEditor = this.onDidChangeFocusedEditorEmitter.event;

focusedEditor?: NotebookEditorWidget = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class NotebookExecutionService {
@inject(NotebookKernelQuickPickService)
protected notebookKernelQuickPickService: NotebookKernelQuickPickService;

private readonly cellExecutionParticipants = new Set<CellExecutionParticipant>();
protected readonly cellExecutionParticipants = new Set<CellExecutionParticipant>();

async executeNotebookCells(notebook: NotebookModel, cells: Iterable<NotebookCellModel>): Promise<void> {
const cellsArr = Array.from(cells)
Expand Down Expand Up @@ -117,7 +117,7 @@ export class NotebookExecutionService {
return Disposable.create(() => this.cellExecutionParticipants.delete(participant));
}

private async runExecutionParticipants(executions: CellExecution[]): Promise<void> {
protected async runExecutionParticipants(executions: CellExecution[]): Promise<void> {
for (const participant of this.cellExecutionParticipants) {
await participant.onWillExecuteCell(executions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ export class NotebookExecutionStateService implements Disposable {

protected readonly executions = new Map<string, Map<number, CellExecution>>();

private readonly onDidChangeExecutionEmitter = new Emitter<CellExecutionStateChangedEvent>();
protected readonly onDidChangeExecutionEmitter = new Emitter<CellExecutionStateChangedEvent>();
onDidChangeExecution = this.onDidChangeExecutionEmitter.event;

private readonly onDidChangeLastRunFailStateEmitter = new Emitter<NotebookFailStateChangedEvent>();
protected readonly onDidChangeLastRunFailStateEmitter = new Emitter<NotebookFailStateChangedEvent>();
onDidChangeLastRunFailState = this.onDidChangeLastRunFailStateEmitter.event;

getOrCreateCellExecution(notebookUri: URI, cellHandle: number): CellExecution {
Expand All @@ -98,7 +98,7 @@ export class NotebookExecutionStateService implements Disposable {

}

private createNotebookCellExecution(notebook: NotebookModel, cellHandle: number): CellExecution {
protected createNotebookCellExecution(notebook: NotebookModel, cellHandle: number): CellExecution {
const notebookUri = notebook.uri;
const execution = new CellExecution(cellHandle, notebook);
execution.toDispose.push(execution.onDidUpdate(() => this.onDidChangeExecutionEmitter.fire(new CellExecutionStateChangedEvent(notebookUri, cellHandle, execution))));
Expand All @@ -107,7 +107,7 @@ export class NotebookExecutionStateService implements Disposable {
return execution;
}

private onCellExecutionDidComplete(notebookUri: URI, cellHandle: number, exe: CellExecution, lastRunSuccess?: boolean): void {
protected onCellExecutionDidComplete(notebookUri: URI, cellHandle: number, exe: CellExecution, lastRunSuccess?: boolean): void {
const notebookExecutions = this.executions.get(notebookUri.toString())?.get(cellHandle);
if (!notebookExecutions) {
throw new Error('Notebook Cell Execution not found while trying to complete it');
Expand Down Expand Up @@ -138,15 +138,15 @@ export class NotebookExecutionStateService implements Disposable {
}

export class CellExecution implements Disposable {
private readonly onDidUpdateEmitter = new Emitter<void>();
protected readonly onDidUpdateEmitter = new Emitter<void>();
readonly onDidUpdate = this.onDidUpdateEmitter.event;

private readonly onDidCompleteEmitter = new Emitter<boolean | undefined>();
protected readonly onDidCompleteEmitter = new Emitter<boolean | undefined>();
readonly onDidComplete = this.onDidCompleteEmitter.event;

toDispose = new DisposableCollection();

private _state: NotebookCellExecutionState = NotebookCellExecutionState.Unconfirmed;
protected _state: NotebookCellExecutionState = NotebookCellExecutionState.Unconfirmed;
get state(): NotebookCellExecutionState {
return this._state;
}
Expand All @@ -155,19 +155,19 @@ export class CellExecution implements Disposable {
return this.notebook.uri;
}

private _didPause = false;
protected _didPause = false;
get didPause(): boolean {
return this._didPause;
}

private _isPaused = false;
protected _isPaused = false;
get isPaused(): boolean {
return this._isPaused;
}

constructor(
readonly cellHandle: number,
private readonly notebook: NotebookModel,
protected readonly notebook: NotebookModel,
) {
console.debug(`CellExecution#ctor ${this.getCellLog()}`);
}
Expand All @@ -188,7 +188,7 @@ export class CellExecution implements Disposable {
this.applyCellExecutionEditsToNotebook([startExecuteEdit]);
}

private getCellLog(): string {
protected getCellLog(): string {
return `${this.notebookURI.toString()}, ${this.cellHandle}`;
}

Expand Down Expand Up @@ -254,7 +254,7 @@ export class CellExecution implements Disposable {
this.toDispose.dispose();
}

private applyCellExecutionEditsToNotebook(edits: CellEditOperation[]): void {
protected applyCellExecutionEditsToNotebook(edits: CellEditOperation[]): void {
this.notebook.applyEdits(edits, false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export class NotebookKernelQuickPickService {
return true;
}

private async displaySelectAnotherQuickPick(editor: NotebookModel, kernelListEmpty: boolean): Promise<boolean> {
protected async displaySelectAnotherQuickPick(editor: NotebookModel, kernelListEmpty: boolean): Promise<boolean> {
const notebook: NotebookModel = editor;
const disposables = new DisposableCollection();
const quickPick = this.quickInputService.createQuickPick<KernelQuickPickItem>();
Expand Down Expand Up @@ -399,11 +399,11 @@ export class NotebookKernelQuickPickService {
return false;
}

private isUri(value: string): boolean {
protected isUri(value: string): boolean {
return /^(?<scheme>\w[\w\d+.-]*):/.test(value);
}

private async calculateKernelSources(editor: NotebookModel): Promise<QuickPickInput<KernelQuickPickItem>[]> {
protected async calculateKernelSources(editor: NotebookModel): Promise<QuickPickInput<KernelQuickPickItem>[]> {
const notebook: NotebookModel = editor;

const actions = await this.notebookKernelService.getKernelSourceActionsFromProviders(notebook);
Expand Down Expand Up @@ -448,7 +448,7 @@ export class NotebookKernelQuickPickService {
return quickPickItems;
}

private async selectOneKernel(notebook: NotebookModel, source: string, kernels: NotebookKernel[]): Promise<void> {
protected async selectOneKernel(notebook: NotebookModel, source: string, kernels: NotebookKernel[]): Promise<void> {
const quickPickItems: QuickPickInput<KernelPick>[] = kernels.map(kernel => toKernelQuickPick(kernel, undefined));
const quickPick = this.quickInputService.createQuickPick<KernelQuickPickItem>();
quickPick.items = quickPickItems;
Expand All @@ -472,7 +472,7 @@ export class NotebookKernelQuickPickService {
quickPick.show();
}

private async executeCommand<T>(notebook: NotebookModel, command: NotebookCommand): Promise<T | undefined | void> {
protected async executeCommand<T>(notebook: NotebookModel, command: NotebookCommand): Promise<T | undefined | void> {
const args = (command.arguments || []).concat([NotebookModelResource.create(notebook.uri)]);
return this.commandService.executeCommand(command.id, ...args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface NotebookTextModelLike { uri: URI; viewType: string }

class KernelInfo {

private static instanceCounter = 0;
protected static instanceCounter = 0;

score: number;
readonly kernel: NotebookKernel;
Expand Down Expand Up @@ -130,7 +130,7 @@ export class SourceCommand implements Disposable {
this.onDidChangeStateEmitter.fire();
}

private async runCommand(commandService: CommandService): Promise<void> {
protected async runCommand(commandService: CommandService): Promise<void> {
try {
await commandService.executeCommand(this.command.id, {
uri: this.model.uri,
Expand Down Expand Up @@ -278,7 +278,7 @@ export class NotebookKernelService {
return this.kernels.get(id)?.kernel;
}

private static score(kernel: NotebookKernel, notebook: NotebookTextModelLike): number {
protected static score(kernel: NotebookKernel, notebook: NotebookTextModelLike): number {
if (kernel.viewType === notebook.viewType) {
return 10;
} else if (kernel.viewType === '*') {
Expand All @@ -288,7 +288,7 @@ export class NotebookKernelService {
}
}

private tryAutoBindNotebook(notebook: NotebookModel, onlyThisKernel?: NotebookKernel): void {
protected tryAutoBindNotebook(notebook: NotebookModel, onlyThisKernel?: NotebookKernel): void {

const id = this.notebookBindings[`${notebook.viewType}/${notebook.uri}`];
if (!id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ export interface RendererMessaging extends Disposable {
@injectable()
export class NotebookRendererMessagingService implements Disposable {

private readonly postMessageEmitter = new Emitter<RendererMessage>();
protected readonly postMessageEmitter = new Emitter<RendererMessage>();
readonly onPostMessage = this.postMessageEmitter.event;

private readonly willActivateRendererEmitter = new Emitter<string>();
protected readonly willActivateRendererEmitter = new Emitter<string>();
readonly onWillActivateRenderer = this.willActivateRendererEmitter.event;

@inject(NotebookEditorWidgetService)
private readonly editorWidgetService: NotebookEditorWidgetService;
protected readonly editorWidgetService: NotebookEditorWidgetService;

private readonly activations = new Map<string /* rendererId */, undefined | RendererMessage[]>();
private readonly scopedMessaging = new Map<string /* editorId */, RendererMessaging>();
protected readonly activations = new Map<string /* rendererId */, undefined | RendererMessage[]>();
protected readonly scopedMessaging = new Map<string /* editorId */, RendererMessaging>();

receiveMessage(editorId: string | undefined, rendererId: string, message: unknown): Promise<boolean> {
if (editorId === undefined) {
Expand Down Expand Up @@ -101,7 +101,7 @@ export class NotebookRendererMessagingService implements Disposable {
return messaging;
}

private postMessage(editorId: string, rendererId: string, message: unknown): void {
protected postMessage(editorId: string, rendererId: string, message: unknown): void {
if (!this.activations.has(rendererId)) {
this.prepare(rendererId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class NotebookCellOutputModel implements Disposable {
return this.rawOutput.metadata;
}

constructor(private rawOutput: CellOutput) { }
constructor(protected rawOutput: CellOutput) { }

replaceData(rawData: CellOutput): void {
this.rawOutput = rawData;
Expand Down

0 comments on commit fcd227a

Please sign in to comment.