Merge IEditor and INotebookEditor, move editor things into notebook editor service
This commit is contained in:
parent
fc78583696
commit
85c1a17b60
11 changed files with 178 additions and 189 deletions
|
@ -19,10 +19,11 @@ import { BoundModelReferenceCollection } from 'vs/workbench/api/browser/mainThre
|
|||
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
|
||||
import { getNotebookEditorFromEditorPane, INotebookEditor, NotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
|
||||
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
|
||||
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
|
||||
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
|
||||
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
|
||||
import { ICellEditOperation, ICellRange, IEditor, IMainCellDto, INotebookDecorationRenderOptions, INotebookDocumentFilter, INotebookExclusiveDocumentFilter, INotebookKernel, NotebookCellsChangeType, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { ICellEditOperation, ICellRange, IMainCellDto, INotebookDecorationRenderOptions, INotebookDocumentFilter, INotebookExclusiveDocumentFilter, INotebookKernel, NotebookCellsChangeType, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
|
||||
import { IMainNotebookController, INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
|
@ -64,9 +65,9 @@ class DocumentAndEditorState {
|
|||
|
||||
constructor(
|
||||
readonly documents: Set<NotebookTextModel>,
|
||||
readonly textEditors: Map<string, IEditor>,
|
||||
readonly textEditors: Map<string, INotebookEditor>,
|
||||
readonly activeEditor: string | null | undefined,
|
||||
readonly visibleEditors: Map<string, IEditor>
|
||||
readonly visibleEditors: Map<string, INotebookEditor>
|
||||
) {
|
||||
//
|
||||
}
|
||||
|
@ -91,10 +92,10 @@ class DocumentAndEditorState {
|
|||
};
|
||||
}
|
||||
|
||||
private static _asEditorAddData(add: IEditor): INotebookEditorAddData {
|
||||
private static _asEditorAddData(add: INotebookEditor): INotebookEditorAddData {
|
||||
return {
|
||||
id: add.getId(),
|
||||
documentUri: add.textModel!.uri,
|
||||
documentUri: add.textModel!.uri, //todo@jrieken no !
|
||||
selections: add.getSelections(),
|
||||
visibleRanges: add.visibleRanges
|
||||
};
|
||||
|
@ -120,6 +121,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
|
|||
@IInstantiationService private readonly _instantiationService: IInstantiationService,
|
||||
@IWorkingCopyService private readonly _workingCopyService: IWorkingCopyService,
|
||||
@INotebookService private _notebookService: INotebookService,
|
||||
@INotebookEditorService private readonly _notebookEditorService: INotebookEditorService,
|
||||
@IEditorService private readonly _editorService: IEditorService,
|
||||
@ILogService private readonly _logService: ILogService,
|
||||
@INotebookCellStatusBarService private readonly _cellStatusBarService: INotebookCellStatusBarService,
|
||||
|
@ -217,7 +219,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
|
|||
}
|
||||
}));
|
||||
|
||||
this._notebookService.listNotebookEditors().forEach((e) => {
|
||||
this._notebookEditorService.listNotebookEditors().forEach((e) => {
|
||||
this._addNotebookEditor(e);
|
||||
});
|
||||
|
||||
|
@ -263,21 +265,20 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
|
|||
}
|
||||
};
|
||||
|
||||
this._notebookService.listNotebookEditors().forEach(editor => {
|
||||
notebookEditorAddedHandler(editor as INotebookEditor); //TODO@jrieken IEditor vs INotebookEditor
|
||||
this._notebookEditorService.listNotebookEditors().forEach(editor => {
|
||||
notebookEditorAddedHandler(editor);
|
||||
});
|
||||
this._register(this._notebookService.onNotebookEditorAdd(editor => {
|
||||
notebookEditorAddedHandler(editor as INotebookEditor); //TODO@jrieken IEditor vs INotebookEditor
|
||||
this._register(this._notebookEditorService.onDidAddNotebookEditor(editor => {
|
||||
notebookEditorAddedHandler(editor);
|
||||
this._addNotebookEditor(editor);
|
||||
}));
|
||||
|
||||
this._register(this._notebookService.onNotebookEditorsRemove(editors => {
|
||||
this._removeNotebookEditor(editors);
|
||||
|
||||
editors.forEach(editor => {
|
||||
this._editorEventListenersMapping.get(editor.getId())?.dispose();
|
||||
this._editorEventListenersMapping.delete(editor.getId());
|
||||
});
|
||||
this._register(this._notebookEditorService.onDidRemoveNotebookEditor(editor => {
|
||||
this._toDisposeOnEditorRemove.get(editor.getId())?.dispose();
|
||||
this._toDisposeOnEditorRemove.delete(editor.getId());
|
||||
this._editorEventListenersMapping.get(editor.getId())?.dispose();
|
||||
this._editorEventListenersMapping.delete(editor.getId());
|
||||
this._updateState();
|
||||
}));
|
||||
|
||||
|
||||
|
@ -369,46 +370,33 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
|
|||
this._updateState(notebookEditor);
|
||||
}
|
||||
|
||||
private _addNotebookEditor(e: IEditor) {
|
||||
this._toDisposeOnEditorRemove.set(e.getId(), combinedDisposable(
|
||||
e.onDidChangeModel(() => this._updateState()),
|
||||
e.onDidFocusEditorWidget(() => {
|
||||
this._updateState(e);
|
||||
}),
|
||||
private _addNotebookEditor(editor: INotebookEditor) {
|
||||
// todo@jrieken cleanup _toDisposeOnEditorRemove and _editorEventListenersMapping
|
||||
this._toDisposeOnEditorRemove.set(editor.getId(), combinedDisposable(
|
||||
editor.onDidChangeModel(() => this._updateState()),
|
||||
editor.onDidFocusEditorWidget(() => this._updateState(editor)),
|
||||
));
|
||||
|
||||
const activeNotebookEditor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
|
||||
this._updateState(activeNotebookEditor);
|
||||
}
|
||||
|
||||
private _removeNotebookEditor(editors: IEditor[]) {
|
||||
editors.forEach(e => {
|
||||
const sub = this._toDisposeOnEditorRemove.get(e.getId());
|
||||
if (sub) {
|
||||
this._toDisposeOnEditorRemove.delete(e.getId());
|
||||
sub.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
this._updateState();
|
||||
}
|
||||
|
||||
private async _updateState(focusedNotebookEditor?: IEditor) {
|
||||
private async _updateState(focusedNotebookEditor?: INotebookEditor) {
|
||||
let activeEditor: string | null = null;
|
||||
|
||||
const activeNotebookEditor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
|
||||
activeEditor = activeNotebookEditor && activeNotebookEditor.hasModel() ? activeNotebookEditor.getId() : null;
|
||||
const documentEditorsMap = new Map<string, IEditor>();
|
||||
const documentEditorsMap = new Map<string, INotebookEditor>();
|
||||
|
||||
const editors = new Map<string, IEditor>();
|
||||
this._notebookService.listNotebookEditors().forEach(editor => {
|
||||
const editors = new Map<string, INotebookEditor>();
|
||||
this._notebookEditorService.listNotebookEditors().forEach(editor => {
|
||||
if (editor.textModel) {
|
||||
editors.set(editor.getId(), editor);
|
||||
documentEditorsMap.set(editor.textModel.uri.toString(), editor);
|
||||
}
|
||||
});
|
||||
|
||||
const visibleEditorsMap = new Map<string, IEditor>();
|
||||
const visibleEditorsMap = new Map<string, INotebookEditor>();
|
||||
this._editorService.visibleEditorPanes.forEach(editorPane => {
|
||||
const nbEditorWidget = getNotebookEditorFromEditorPane(editorPane);
|
||||
if (nbEditorWidget && editors.has(nbEditorWidget.getId())) {
|
||||
|
@ -567,54 +555,54 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
|
|||
entry?.emitter.fire(uriComponents ? URI.revive(uriComponents) : undefined);
|
||||
}
|
||||
|
||||
async $postMessage(editorId: string, forRendererId: string | undefined, value: any): Promise<boolean> {
|
||||
const editor = this._notebookService.getNotebookEditor(editorId) as INotebookEditor | undefined;
|
||||
if (editor) {
|
||||
editor.postMessage(forRendererId, value);
|
||||
return true;
|
||||
async $postMessage(id: string, forRendererId: string | undefined, value: any): Promise<boolean> {
|
||||
const editor = this._notebookEditorService.getNotebookEditor(id);
|
||||
if (!editor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
editor.postMessage(forRendererId, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
async $tryRevealRange(id: string, range: ICellRange, revealType: NotebookEditorRevealType) {
|
||||
const editor = this._notebookService.listNotebookEditors().find(editor => editor.getId() === id) as INotebookEditor | undefined;
|
||||
if (editor) {
|
||||
const notebookEditor = editor as INotebookEditor;
|
||||
if (!notebookEditor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
const viewModel = notebookEditor.viewModel;
|
||||
const cell = viewModel.viewCells[range.start];
|
||||
if (!cell) {
|
||||
return;
|
||||
}
|
||||
const editor = this._notebookEditorService.getNotebookEditor(id);
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
const notebookEditor = editor as INotebookEditor;
|
||||
if (!notebookEditor.hasModel()) {
|
||||
return;
|
||||
}
|
||||
const viewModel = notebookEditor.viewModel;
|
||||
const cell = viewModel.viewCells[range.start];
|
||||
if (!cell) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (revealType) {
|
||||
case NotebookEditorRevealType.Default:
|
||||
return notebookEditor.revealCellRangeInView(range);
|
||||
case NotebookEditorRevealType.InCenter:
|
||||
return notebookEditor.revealInCenter(cell);
|
||||
case NotebookEditorRevealType.InCenterIfOutsideViewport:
|
||||
return notebookEditor.revealInCenterIfOutsideViewport(cell);
|
||||
case NotebookEditorRevealType.AtTop:
|
||||
return notebookEditor.revealInViewAtTop(cell);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (revealType) {
|
||||
case NotebookEditorRevealType.Default:
|
||||
return notebookEditor.revealCellRangeInView(range);
|
||||
case NotebookEditorRevealType.InCenter:
|
||||
return notebookEditor.revealInCenter(cell);
|
||||
case NotebookEditorRevealType.InCenterIfOutsideViewport:
|
||||
return notebookEditor.revealInCenterIfOutsideViewport(cell);
|
||||
case NotebookEditorRevealType.AtTop:
|
||||
return notebookEditor.revealInViewAtTop(cell);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$registerNotebookEditorDecorationType(key: string, options: INotebookDecorationRenderOptions) {
|
||||
this._notebookService.registerEditorDecorationType(key, options);
|
||||
this._notebookEditorService.registerEditorDecorationType(key, options);
|
||||
}
|
||||
|
||||
$removeNotebookEditorDecorationType(key: string) {
|
||||
this._notebookService.removeEditorDecorationType(key);
|
||||
this._notebookEditorService.removeEditorDecorationType(key);
|
||||
}
|
||||
|
||||
$trySetDecorations(id: string, range: ICellRange, key: string) {
|
||||
const editor = this._notebookService.listNotebookEditors().find(editor => editor.getId() === id) as INotebookEditor | undefined;
|
||||
const editor = this._notebookEditorService.getNotebookEditor(id);
|
||||
if (editor) {
|
||||
const notebookEditor = editor as INotebookEditor;
|
||||
notebookEditor.setEditorDecorations(key, range);
|
||||
|
|
|
@ -31,7 +31,7 @@ import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons';
|
|||
import { CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
|
||||
import { EditorsOrder } from 'vs/workbench/common/editor';
|
||||
import { INotebookEditorWidgetService } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidgetService';
|
||||
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions';
|
||||
|
||||
|
@ -136,7 +136,7 @@ function getContextFromActiveEditor(editorService: IEditorService) {
|
|||
|
||||
function getWidgetFromUri(accessor: ServicesAccessor, uri: URI) {
|
||||
const editorService = accessor.get(IEditorService);
|
||||
const notebookWidgetService = accessor.get(INotebookEditorWidgetService);
|
||||
const notebookEditorService = accessor.get(INotebookEditorService);
|
||||
const editorId = editorService.getEditors(EditorsOrder.SEQUENTIAL).find(editorId => editorId.editor instanceof NotebookEditorInput && editorId.editor.resource?.toString() === uri.toString());
|
||||
if (!editorId) {
|
||||
return undefined;
|
||||
|
@ -147,7 +147,7 @@ function getWidgetFromUri(accessor: ServicesAccessor, uri: URI) {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const widget = notebookWidgetService.widgets.find(widget => widget.textModel?.viewType === notebookEditorInput.viewType && widget.textModel?.uri.toString() === notebookEditorInput.resource.toString());
|
||||
const widget = notebookEditorService.listNotebookEditors().find(widget => widget.textModel?.viewType === notebookEditorInput.viewType && widget.textModel?.uri.toString() === notebookEditorInput.resource.toString());
|
||||
|
||||
if (widget && widget.hasModel()) {
|
||||
return widget;
|
||||
|
|
|
@ -46,8 +46,8 @@ import { INotebookEditorWorkerService } from 'vs/workbench/contrib/notebook/comm
|
|||
import { NotebookEditorWorkerServiceImpl } from 'vs/workbench/contrib/notebook/common/services/notebookWorkerServiceImpl';
|
||||
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
|
||||
import { NotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/browser/notebookCellStatusBarServiceImpl';
|
||||
import { INotebookEditorWidgetService } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidgetService';
|
||||
import { NotebookEditorWidgetService } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidgetServiceImpl';
|
||||
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
|
||||
import { NotebookEditorWidgetService } from 'vs/workbench/contrib/notebook/browser/notebookEditorServiceImpl';
|
||||
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
|
||||
import { IJSONSchema } from 'vs/base/common/jsonSchema';
|
||||
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
|
||||
|
@ -735,7 +735,7 @@ registerSingleton(INotebookService, NotebookService);
|
|||
registerSingleton(INotebookEditorWorkerService, NotebookEditorWorkerServiceImpl);
|
||||
registerSingleton(INotebookEditorModelResolverService, NotebookModelResolverService, true);
|
||||
registerSingleton(INotebookCellStatusBarService, NotebookCellStatusBarService, true);
|
||||
registerSingleton(INotebookEditorWidgetService, NotebookEditorWidgetService, true);
|
||||
registerSingleton(INotebookEditorService, NotebookEditorWidgetService, true);
|
||||
|
||||
const configurationRegistry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);
|
||||
configurationRegistry.registerConfiguration({
|
||||
|
|
|
@ -22,7 +22,7 @@ import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/outpu
|
|||
import { RunStateRenderer, TimerRenderer } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer';
|
||||
import { CellViewModel, IModelDecorationsChangeAccessor, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
|
||||
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
|
||||
import { CellKind, NotebookCellMetadata, NotebookDocumentMetadata, IEditor, INotebookKernel, ICellRange, IOrderedMimeType, INotebookRendererInfo, ICellOutput, IOutputItemDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { CellKind, NotebookCellMetadata, NotebookDocumentMetadata, INotebookKernel, ICellRange, IOrderedMimeType, INotebookRendererInfo, ICellOutput, IOutputItemDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { Webview } from 'vs/workbench/contrib/webview/browser/webview';
|
||||
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
|
||||
import { IMenu } from 'vs/platform/actions/common/actions';
|
||||
|
@ -331,7 +331,18 @@ export const NOTEBOOK_EDITOR_ID = 'workbench.editor.notebook';
|
|||
|
||||
export const NOTEBOOK_DIFF_EDITOR_ID = 'workbench.editor.notebookTextDiffEditor';
|
||||
|
||||
export interface INotebookEditor extends IEditor, ICommonNotebookEditor {
|
||||
export interface INotebookEditor extends ICommonNotebookEditor {
|
||||
|
||||
// from the old IEditor
|
||||
readonly onDidChangeVisibleRanges: Event<void>;
|
||||
readonly onDidChangeSelection: Event<void>;
|
||||
getSelection(): ICellRange | undefined;
|
||||
getSelections(): ICellRange[];
|
||||
visibleRanges: ICellRange[];
|
||||
textModel?: NotebookTextModel;
|
||||
getId(): string;
|
||||
hasFocus(): boolean;
|
||||
|
||||
isEmbedded: boolean;
|
||||
|
||||
cursorNavigationMode: boolean;
|
||||
|
|
|
@ -26,7 +26,7 @@ import { IEditorGroup, IEditorGroupsService, GroupsOrder } from 'vs/workbench/se
|
|||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { NotebookEditorOptions, NOTEBOOK_EDITOR_ID } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
|
||||
import { IBorrowValue, INotebookEditorWidgetService } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidgetService';
|
||||
import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
|
||||
|
||||
const NOTEBOOK_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'NotebookEditorViewState';
|
||||
|
||||
|
@ -57,7 +57,7 @@ export class NotebookEditor extends EditorPane {
|
|||
@IEditorDropService private readonly _editorDropService: IEditorDropService,
|
||||
@INotificationService private readonly _notificationService: INotificationService,
|
||||
@INotebookService private readonly _notebookService: INotebookService,
|
||||
@INotebookEditorWidgetService private readonly _notebookWidgetService: INotebookEditorWidgetService,
|
||||
@INotebookEditorService private readonly _notebookWidgetService: INotebookEditorService,
|
||||
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
|
||||
) {
|
||||
super(NotebookEditor.ID, telemetryService, themeService, storageService);
|
||||
|
|
|
@ -7,15 +7,29 @@ import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/note
|
|||
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { createDecorator, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
|
||||
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
|
||||
export const INotebookEditorWidgetService = createDecorator<INotebookEditorWidgetService>('INotebookEditorWidgetService');
|
||||
export const INotebookEditorService = createDecorator<INotebookEditorService>('INotebookEditorWidgetService');
|
||||
|
||||
export interface IBorrowValue<T> {
|
||||
readonly value: T | undefined;
|
||||
}
|
||||
|
||||
export interface INotebookEditorWidgetService {
|
||||
export interface INotebookEditorService {
|
||||
_serviceBrand: undefined;
|
||||
widgets: NotebookEditorWidget[];
|
||||
|
||||
retrieveWidget(accessor: ServicesAccessor, group: IEditorGroup, input: NotebookEditorInput): IBorrowValue<NotebookEditorWidget>;
|
||||
|
||||
onDidAddNotebookEditor: Event<INotebookEditor>;
|
||||
onDidRemoveNotebookEditor: Event<INotebookEditor>;
|
||||
addNotebookEditor(editor: INotebookEditor): void;
|
||||
removeNotebookEditor(editor: INotebookEditor): void;
|
||||
getNotebookEditor(editorId: string): INotebookEditor | undefined;
|
||||
listNotebookEditors(): readonly INotebookEditor[];
|
||||
|
||||
registerEditorDecorationType(key: string, options: INotebookDecorationRenderOptions): void;
|
||||
removeEditorDecorationType(key: string): void;
|
||||
resolveEditorDecorationOptions(key: string): INotebookDecorationRenderOptions | undefined;
|
||||
}
|
|
@ -10,20 +10,27 @@ import { IEditorGroupsService, IEditorGroup, GroupChangeKind, OpenEditorContext
|
|||
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IBorrowValue, INotebookEditorWidgetService } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidgetService';
|
||||
import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
|
||||
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
|
||||
export class NotebookEditorWidgetService implements INotebookEditorWidgetService {
|
||||
export class NotebookEditorWidgetService implements INotebookEditorService {
|
||||
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
private _tokenPool = 1;
|
||||
|
||||
private readonly _notebookWidgets = new Map<number, ResourceMap<{ widget: NotebookEditorWidget, token: number | undefined }>>();
|
||||
private readonly _disposables = new DisposableStore();
|
||||
private readonly _notebookEditors = new Map<string, INotebookEditor>();
|
||||
private readonly _decorationOptionProviders = new Map<string, INotebookDecorationRenderOptions>();
|
||||
|
||||
get widgets() {
|
||||
return [...this._notebookWidgets.values()].map(val => [...val.values()].map(widget => widget.widget)).reduce((prev, curr) => { return [...prev, ...curr]; }, []);
|
||||
}
|
||||
private readonly _onNotebookEditorAdd = new Emitter<INotebookEditor>();
|
||||
private readonly _onNotebookEditorsRemove = new Emitter<INotebookEditor>();
|
||||
readonly onDidAddNotebookEditor = this._onNotebookEditorAdd.event;
|
||||
readonly onDidRemoveNotebookEditor = this._onNotebookEditorsRemove.event;
|
||||
|
||||
private readonly _borrowableEditors = new Map<number, ResourceMap<{ widget: NotebookEditorWidget, token: number | undefined }>>();
|
||||
|
||||
constructor(
|
||||
@IEditorGroupsService editorGroupService: IEditorGroupsService,
|
||||
|
@ -34,7 +41,7 @@ export class NotebookEditorWidgetService implements INotebookEditorWidgetService
|
|||
const onNewGroup = (group: IEditorGroup) => {
|
||||
const { id } = group;
|
||||
const listener = group.onDidGroupChange(e => {
|
||||
const widgets = this._notebookWidgets.get(group.id);
|
||||
const widgets = this._borrowableEditors.get(group.id);
|
||||
if (!widgets || e.kind !== GroupChangeKind.EDITOR_CLOSE || !(e.editor instanceof NotebookEditorInput)) {
|
||||
return;
|
||||
}
|
||||
|
@ -58,8 +65,8 @@ export class NotebookEditorWidgetService implements INotebookEditorWidgetService
|
|||
listener.dispose();
|
||||
groupListener.delete(group.id);
|
||||
}
|
||||
const widgets = this._notebookWidgets.get(group.id);
|
||||
this._notebookWidgets.delete(group.id);
|
||||
const widgets = this._borrowableEditors.get(group.id);
|
||||
this._borrowableEditors.delete(group.id);
|
||||
if (widgets) {
|
||||
for (const value of widgets.values()) {
|
||||
value.token = undefined;
|
||||
|
@ -83,6 +90,14 @@ export class NotebookEditorWidgetService implements INotebookEditorWidgetService
|
|||
}));
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._disposables.dispose();
|
||||
this._onNotebookEditorAdd.dispose();
|
||||
this._onNotebookEditorsRemove.dispose();
|
||||
}
|
||||
|
||||
// --- group-based editor borrowing...
|
||||
|
||||
private _disposeWidget(widget: NotebookEditorWidget): void {
|
||||
widget.onWillHide();
|
||||
const domNode = widget.getDomNode();
|
||||
|
@ -91,30 +106,30 @@ export class NotebookEditorWidgetService implements INotebookEditorWidgetService
|
|||
}
|
||||
|
||||
private _freeWidget(input: NotebookEditorInput, source: IEditorGroup, target: IEditorGroup): void {
|
||||
const targetWidget = this._notebookWidgets.get(target.id)?.get(input.resource);
|
||||
const targetWidget = this._borrowableEditors.get(target.id)?.get(input.resource);
|
||||
if (targetWidget) {
|
||||
// not needed
|
||||
return;
|
||||
}
|
||||
|
||||
const widget = this._notebookWidgets.get(source.id)?.get(input.resource);
|
||||
const widget = this._borrowableEditors.get(source.id)?.get(input.resource);
|
||||
if (!widget) {
|
||||
throw new Error('no widget at source group');
|
||||
}
|
||||
this._notebookWidgets.get(source.id)?.delete(input.resource);
|
||||
this._borrowableEditors.get(source.id)?.delete(input.resource);
|
||||
widget.token = undefined;
|
||||
|
||||
let targetMap = this._notebookWidgets.get(target.id);
|
||||
let targetMap = this._borrowableEditors.get(target.id);
|
||||
if (!targetMap) {
|
||||
targetMap = new ResourceMap();
|
||||
this._notebookWidgets.set(target.id, targetMap);
|
||||
this._borrowableEditors.set(target.id, targetMap);
|
||||
}
|
||||
targetMap.set(input.resource, widget);
|
||||
}
|
||||
|
||||
retrieveWidget(accessor: ServicesAccessor, group: IEditorGroup, input: NotebookEditorInput): IBorrowValue<NotebookEditorWidget> {
|
||||
|
||||
let value = this._notebookWidgets.get(group.id)?.get(input.resource);
|
||||
let value = this._borrowableEditors.get(group.id)?.get(input.resource);
|
||||
|
||||
if (!value) {
|
||||
// NEW widget
|
||||
|
@ -123,10 +138,10 @@ export class NotebookEditorWidgetService implements INotebookEditorWidgetService
|
|||
const token = this._tokenPool++;
|
||||
value = { widget, token };
|
||||
|
||||
let map = this._notebookWidgets.get(group.id);
|
||||
let map = this._borrowableEditors.get(group.id);
|
||||
if (!map) {
|
||||
map = new ResourceMap();
|
||||
this._notebookWidgets.set(group.id, map);
|
||||
this._borrowableEditors.set(group.id, map);
|
||||
}
|
||||
map.set(input.resource, value);
|
||||
|
||||
|
@ -146,4 +161,43 @@ export class NotebookEditorWidgetService implements INotebookEditorWidgetService
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
// --- editor management
|
||||
|
||||
addNotebookEditor(editor: INotebookEditor): void {
|
||||
this._notebookEditors.set(editor.getId(), editor);
|
||||
this._onNotebookEditorAdd.fire(editor);
|
||||
}
|
||||
|
||||
removeNotebookEditor(editor: INotebookEditor): void {
|
||||
if (this._notebookEditors.has(editor.getId())) {
|
||||
this._notebookEditors.delete(editor.getId());
|
||||
this._onNotebookEditorsRemove.fire(editor);
|
||||
}
|
||||
}
|
||||
|
||||
getNotebookEditor(editorId: string): INotebookEditor | undefined {
|
||||
return this._notebookEditors.get(editorId);
|
||||
}
|
||||
|
||||
listNotebookEditors(): readonly INotebookEditor[] {
|
||||
return [...this._notebookEditors].map(e => e[1]);
|
||||
}
|
||||
|
||||
// --- editor decorations
|
||||
|
||||
registerEditorDecorationType(key: string, options: INotebookDecorationRenderOptions): void {
|
||||
if (!this._decorationOptionProviders.has(key)) {
|
||||
this._decorationOptionProviders.set(key, options);
|
||||
}
|
||||
}
|
||||
|
||||
removeEditorDecorationType(key: string): void {
|
||||
this._decorationOptionProviders.delete(key);
|
||||
this.listNotebookEditors().forEach(editor => editor.removeEditorDecorations(key));
|
||||
}
|
||||
|
||||
resolveEditorDecorationOptions(key: string): INotebookDecorationRenderOptions | undefined {
|
||||
return this._decorationOptionProviders.get(key);
|
||||
}
|
||||
}
|
|
@ -46,6 +46,7 @@ import { CellEditState, CellFocusMode, IActiveNotebookEditor, ICellOutputViewMod
|
|||
import { NotebookDecorationCSSRules, NotebookRefCountedStyleSheet } from 'vs/workbench/contrib/notebook/browser/notebookEditorDecorations';
|
||||
import { NotebookEditorExtensionsRegistry } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
|
||||
import { IKernelManagerDelegate, NotebookEditorKernelManager } from 'vs/workbench/contrib/notebook/browser/notebookEditorKernelManager';
|
||||
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
|
||||
import { errorStateIcon, successStateIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons';
|
||||
import { NotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookCellList';
|
||||
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/output/outputRenderer';
|
||||
|
@ -196,6 +197,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
|
|||
@IInstantiationService instantiationService: IInstantiationService,
|
||||
@IStorageService storageService: IStorageService,
|
||||
@INotebookService private notebookService: INotebookService,
|
||||
@INotebookEditorService private readonly notebookEditorService: INotebookEditorService,
|
||||
@IConfigurationService private readonly configurationService: IConfigurationService,
|
||||
@IContextKeyService contextKeyService: IContextKeyService,
|
||||
@ILayoutService private readonly layoutService: ILayoutService,
|
||||
|
@ -246,7 +248,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
|
|||
}
|
||||
});
|
||||
|
||||
this.notebookService.addNotebookEditor(this);
|
||||
this.notebookEditorService.addNotebookEditor(this);
|
||||
|
||||
const id = generateUuid();
|
||||
this._overlayContainer.id = `notebook-${id}`;
|
||||
|
@ -1183,7 +1185,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
|
|||
private _decortionKeyToIds = new Map<string, string[]>();
|
||||
|
||||
private _registerDecorationType(key: string) {
|
||||
const options = this.notebookService.resolveEditorDecorationOptions(key);
|
||||
const options = this.notebookEditorService.resolveEditorDecorationOptions(key);
|
||||
|
||||
if (options) {
|
||||
const styleElement = DOM.createStyleSheet(this._body);
|
||||
|
@ -1828,7 +1830,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
|
|||
this._webview?.dispose();
|
||||
this._webview = null;
|
||||
|
||||
this.notebookService.removeNotebookEditor(this);
|
||||
this.notebookEditorService.removeNotebookEditor(this);
|
||||
dispose(this._contributions.values());
|
||||
this._contributions.clear();
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag
|
|||
import { NotebookExtensionDescription } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { Memento } from 'vs/workbench/common/memento';
|
||||
import { INotebookEditorContribution, notebookMarkdownRendererExtensionPoint, notebookProviderExtensionPoint, notebookRendererExtensionPoint } from 'vs/workbench/contrib/notebook/browser/extensionPoint';
|
||||
import { INotebookEditor, updateEditorTopPadding } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { updateEditorTopPadding } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { NotebookKernelProviderAssociationRegistry, NotebookViewTypesExtensionRegistry, updateNotebookKernelProvideAssociationSchema } from 'vs/workbench/contrib/notebook/browser/notebookKernelAssociation';
|
||||
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
|
||||
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
|
||||
import { ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, BUILTIN_RENDERER_ID, DisplayOrderKey, INotebookDecorationRenderOptions, INotebookKernel, INotebookKernelProvider, INotebookMarkdownRendererInfo, INotebookRendererInfo, INotebookTextModel, IOrderedMimeType, IOutputDto, mimeTypeIsAlwaysSecure, mimeTypeSupportedByCore, NotebookDataDto, notebookDocumentFilterMatch, NotebookEditorPriority, NOTEBOOK_DISPLAY_ORDER, RENDERER_NOT_AVAILABLE, sortMimeTypes, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, BUILTIN_RENDERER_ID, DisplayOrderKey, INotebookKernel, INotebookKernelProvider, INotebookMarkdownRendererInfo, INotebookRendererInfo, INotebookTextModel, IOrderedMimeType, IOutputDto, mimeTypeIsAlwaysSecure, mimeTypeSupportedByCore, NotebookDataDto, notebookDocumentFilterMatch, NotebookEditorPriority, NOTEBOOK_DISPLAY_ORDER, RENDERER_NOT_AVAILABLE, sortMimeTypes, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { NotebookMarkdownRendererInfo } from 'vs/workbench/contrib/notebook/common/notebookMarkdownRenderer';
|
||||
import { NotebookOutputRendererInfo } from 'vs/workbench/contrib/notebook/common/notebookOutputRenderer';
|
||||
import { NotebookEditorDescriptor, NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
|
||||
|
@ -248,11 +248,6 @@ export class NotebookService extends Disposable implements INotebookService, IEd
|
|||
private readonly _notebookKernelProviderInfoStore: NotebookKernelProviderInfoStore = new NotebookKernelProviderInfoStore();
|
||||
private readonly _models = new ResourceMap<ModelData>();
|
||||
|
||||
private readonly _onNotebookEditorAdd: Emitter<INotebookEditor> = this._register(new Emitter<INotebookEditor>());
|
||||
readonly onNotebookEditorAdd: Event<INotebookEditor> = this._onNotebookEditorAdd.event;
|
||||
private readonly _onNotebookEditorsRemove: Emitter<INotebookEditor[]> = this._register(new Emitter<INotebookEditor[]>());
|
||||
readonly onNotebookEditorsRemove: Event<INotebookEditor[]> = this._onNotebookEditorsRemove.event;
|
||||
|
||||
private readonly _onDidAddNotebookDocument = this._register(new Emitter<NotebookTextModel>());
|
||||
private readonly _onDidRemoveNotebookDocument = this._register(new Emitter<URI>());
|
||||
readonly onDidAddNotebookDocument = this._onDidAddNotebookDocument.event;
|
||||
|
@ -260,7 +255,6 @@ export class NotebookService extends Disposable implements INotebookService, IEd
|
|||
|
||||
private readonly _onNotebookDocumentSaved: Emitter<URI> = this._register(new Emitter<URI>());
|
||||
readonly onNotebookDocumentSaved: Event<URI> = this._onNotebookDocumentSaved.event;
|
||||
private readonly _notebookEditors = new Map<string, INotebookEditor>();
|
||||
|
||||
private readonly _onDidChangeEditorTypes = this._register(new Emitter<void>());
|
||||
onDidChangeEditorTypes: Event<void> = this._onDidChangeEditorTypes.event;
|
||||
|
@ -273,7 +267,6 @@ export class NotebookService extends Disposable implements INotebookService, IEd
|
|||
private _lastClipboardIsCopy: boolean = true;
|
||||
|
||||
private _displayOrder: { userOrder: string[], defaultOrder: string[]; } = Object.create(null);
|
||||
private readonly _decorationOptionProviders = new Map<string, INotebookDecorationRenderOptions>();
|
||||
|
||||
constructor(
|
||||
@IExtensionService private readonly _extensionService: IExtensionService,
|
||||
|
@ -409,23 +402,6 @@ export class NotebookService extends Disposable implements INotebookService, IEd
|
|||
}));
|
||||
}
|
||||
|
||||
registerEditorDecorationType(key: string, options: INotebookDecorationRenderOptions): void {
|
||||
if (this._decorationOptionProviders.has(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._decorationOptionProviders.set(key, options);
|
||||
}
|
||||
|
||||
removeEditorDecorationType(key: string): void {
|
||||
this._decorationOptionProviders.delete(key);
|
||||
|
||||
this.listNotebookEditors().forEach(editor => editor.removeEditorDecorations(key));
|
||||
}
|
||||
|
||||
resolveEditorDecorationOptions(key: string): INotebookDecorationRenderOptions | undefined {
|
||||
return this._decorationOptionProviders.get(key);
|
||||
}
|
||||
|
||||
getEditorTypes(): IEditorType[] {
|
||||
return [...this._notebookProviderInfoStore].map(info => ({
|
||||
|
@ -601,19 +577,8 @@ export class NotebookService extends Disposable implements INotebookService, IEd
|
|||
this._models.delete(model.uri);
|
||||
|
||||
if (modelData) {
|
||||
// delete editors and documents
|
||||
const willRemovedEditors: INotebookEditor[] = [];
|
||||
for (const editor of this._notebookEditors.values()) {
|
||||
if (editor.textModel === modelData.model) {
|
||||
willRemovedEditors.push(editor);
|
||||
}
|
||||
}
|
||||
|
||||
modelData.model.dispose();
|
||||
modelData.dispose();
|
||||
|
||||
willRemovedEditors.forEach(e => this._notebookEditors.delete(e.getId()));
|
||||
this._onNotebookEditorsRemove.fire(willRemovedEditors.map(e => e));
|
||||
this._onDidRemoveNotebookDocument.fire(modelData.model.uri);
|
||||
}
|
||||
}
|
||||
|
@ -716,28 +681,6 @@ export class NotebookService extends Disposable implements INotebookService, IEd
|
|||
}
|
||||
}
|
||||
|
||||
removeNotebookEditor(editor: INotebookEditor) {
|
||||
const editorCache = this._notebookEditors.get(editor.getId());
|
||||
|
||||
if (editorCache) {
|
||||
this._notebookEditors.delete(editor.getId());
|
||||
this._onNotebookEditorsRemove.fire([editor]);
|
||||
}
|
||||
}
|
||||
|
||||
addNotebookEditor(editor: INotebookEditor) {
|
||||
this._notebookEditors.set(editor.getId(), editor);
|
||||
this._onNotebookEditorAdd.fire(editor);
|
||||
}
|
||||
|
||||
getNotebookEditor(editorId: string) {
|
||||
return this._notebookEditors.get(editorId);
|
||||
}
|
||||
|
||||
listNotebookEditors(): INotebookEditor[] {
|
||||
return [...this._notebookEditors].map(e => e[1]);
|
||||
}
|
||||
|
||||
onDidReceiveMessage(viewType: string, editorId: string, rendererType: string | undefined, message: any): void {
|
||||
const provider = this._notebookProviders.get(viewType);
|
||||
|
||||
|
|
|
@ -660,19 +660,6 @@ export interface ICellRange {
|
|||
end: number;
|
||||
}
|
||||
|
||||
export interface IEditor extends editorCommon.ICompositeCodeEditor {
|
||||
readonly onDidChangeModel: Event<NotebookTextModel | undefined>;
|
||||
readonly onDidFocusEditorWidget: Event<void>;
|
||||
readonly onDidChangeVisibleRanges: Event<void>;
|
||||
readonly onDidChangeSelection: Event<void>;
|
||||
getSelection(): ICellRange | undefined;
|
||||
getSelections(): ICellRange[];
|
||||
visibleRanges: ICellRange[];
|
||||
textModel?: NotebookTextModel;
|
||||
getId(): string;
|
||||
hasFocus(): boolean;
|
||||
}
|
||||
|
||||
export enum NotebookEditorPriority {
|
||||
default = 'default',
|
||||
option = 'option',
|
||||
|
|
|
@ -8,7 +8,7 @@ import { URI } from 'vs/base/common/uri';
|
|||
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
|
||||
import { NotebookExtensionDescription } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { INotebookTextModel, INotebookRendererInfo, IEditor, INotebookKernelProvider, INotebookKernel, TransientMetadata, NotebookDataDto, TransientOptions, INotebookDecorationRenderOptions, INotebookExclusiveDocumentFilter, IOrderedMimeType, IOutputDto, INotebookMarkdownRendererInfo } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { INotebookTextModel, INotebookRendererInfo, INotebookKernelProvider, INotebookKernel, TransientMetadata, NotebookDataDto, TransientOptions, INotebookExclusiveDocumentFilter, IOrderedMimeType, IOutputDto, INotebookMarkdownRendererInfo } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
|
||||
|
@ -40,8 +40,6 @@ export interface INotebookService {
|
|||
readonly _serviceBrand: undefined;
|
||||
canResolve(viewType: string): Promise<boolean>;
|
||||
|
||||
onNotebookEditorAdd: Event<IEditor>;
|
||||
onNotebookEditorsRemove: Event<IEditor[]>;
|
||||
onDidRemoveNotebookDocument: Event<URI>;
|
||||
onDidAddNotebookDocument: Event<NotebookTextModel>;
|
||||
onNotebookDocumentSaved: Event<URI>;
|
||||
|
@ -80,12 +78,4 @@ export interface INotebookService {
|
|||
// editor events
|
||||
|
||||
resolveNotebookEditor(viewType: string, uri: URI, editorId: string): Promise<void>;
|
||||
|
||||
addNotebookEditor(editor: IEditor): void;
|
||||
removeNotebookEditor(editor: IEditor): void;
|
||||
getNotebookEditor(editorId: string): IEditor | undefined;
|
||||
listNotebookEditors(): readonly IEditor[];
|
||||
registerEditorDecorationType(key: string, options: INotebookDecorationRenderOptions): void;
|
||||
removeEditorDecorationType(key: string): void;
|
||||
resolveEditorDecorationOptions(key: string): INotebookDecorationRenderOptions | undefined;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue