Skip to content

Commit

Permalink
Remove notebook editor decoration type (#151574)
Browse files Browse the repository at this point in the history
* Remove the notebookEditorDecorationType API proposal

Fixes #146838

* Remove all the infastructure around the now removed notebookEditorDecorationType api
  • Loading branch information
mjbvz authored Jun 13, 2022
1 parent 32ba8bc commit 8b0b3ee
Show file tree
Hide file tree
Showing 17 changed files with 4 additions and 427 deletions.
1 change: 0 additions & 1 deletion extensions/vscode-api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"notebookControllerKind",
"notebookDebugOptions",
"notebookDeprecated",
"notebookEditorDecorationType",
"notebookEditorEdit",
"notebookLiveShare",
"notebookMessaging",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ suite('vscode', function () {
assertNoRpcFromEntry([item, 'TreeView']);
});

test('no rpc, createNotebookEditorDecorationType(...)', function () {
const item = vscode.notebooks.createNotebookEditorDecorationType({ top: {} });
dispo.push(item);
assertNoRpcFromEntry([item, 'NotebookEditorDecorationType']);
});

test('no rpc, createNotebookController(...)', function () {
const ctrl = vscode.notebooks.createNotebookController('foo', 'bar', '');
Expand Down
1 change: 0 additions & 1 deletion extensions/vscode-notebook-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"notebookControllerKind",
"notebookDebugOptions",
"notebookDeprecated",
"notebookEditorDecorationType",
"notebookLiveShare",
"notebookMessaging",
"notebookMime"
Expand Down
17 changes: 0 additions & 17 deletions src/vs/workbench/api/browser/mainThreadNotebookEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { DisposableStore, dispose } from 'vs/base/common/lifecycle';
import { getNotebookEditorFromEditorPane, INotebookEditor, INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
import { ExtHostContext, ExtHostNotebookEditorsShape, ICellEditOperationDto, INotebookDocumentShowOptions, INotebookEditorViewColumnInfo, MainThreadNotebookEditorsShape, NotebookEditorRevealType } from '../common/extHost.protocol';
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { ILogService } from 'vs/platform/log/common/log';
import { URI, UriComponents } from 'vs/base/common/uri';
Expand Down Expand Up @@ -165,22 +164,6 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape
}
}

$registerNotebookEditorDecorationType(key: string, options: INotebookDecorationRenderOptions): void {
this._notebookEditorService.registerEditorDecorationType(key, options);
}

$removeNotebookEditorDecorationType(key: string): void {
this._notebookEditorService.removeEditorDecorationType(key);
}

$trySetDecorations(id: string, range: ICellRange, key: string): void {
const editor = this._notebookEditorService.getNotebookEditor(id);
if (editor) {
const notebookEditor = editor as INotebookEditor;
notebookEditor.setEditorDecorations(key, range);
}
}

$trySetSelections(id: string, ranges: ICellRange[]): void {
const editor = this._notebookEditorService.getNotebookEditor(id);
if (!editor) {
Expand Down
6 changes: 1 addition & 5 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
const extHostDocumentSaveParticipant = rpcProtocol.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostLogService, extHostDocuments, rpcProtocol.getProxy(MainContext.MainThreadBulkEdits)));
const extHostNotebook = rpcProtocol.set(ExtHostContext.ExtHostNotebook, new ExtHostNotebookController(rpcProtocol, extHostCommands, extHostDocumentsAndEditors, extHostDocuments, extensionStoragePaths));
const extHostNotebookDocuments = rpcProtocol.set(ExtHostContext.ExtHostNotebookDocuments, new ExtHostNotebookDocuments(extHostNotebook));
const extHostNotebookEditors = rpcProtocol.set(ExtHostContext.ExtHostNotebookEditors, new ExtHostNotebookEditors(extHostLogService, rpcProtocol, extHostNotebook));
const extHostNotebookEditors = rpcProtocol.set(ExtHostContext.ExtHostNotebookEditors, new ExtHostNotebookEditors(extHostLogService, extHostNotebook));
const extHostNotebookKernels = rpcProtocol.set(ExtHostContext.ExtHostNotebookKernels, new ExtHostNotebookKernels(rpcProtocol, initData, extHostNotebook, extHostCommands, extHostLogService));
const extHostNotebookRenderers = rpcProtocol.set(ExtHostContext.ExtHostNotebookRenderers, new ExtHostNotebookRenderers(rpcProtocol, extHostNotebook));
const extHostEditors = rpcProtocol.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(rpcProtocol, extHostDocumentsAndEditors));
Expand Down Expand Up @@ -1146,10 +1146,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
registerNotebookCellStatusBarItemProvider: (notebookType: string, provider: vscode.NotebookCellStatusBarItemProvider) => {
return extHostNotebook.registerNotebookCellStatusBarItemProvider(extension, notebookType, provider);
},
createNotebookEditorDecorationType(options: vscode.NotebookDecorationRenderOptions): vscode.NotebookEditorDecorationType {
checkProposedApiEnabled(extension, 'notebookEditorDecorationType');
return extHostNotebookEditors.createNotebookEditorDecorationType(options);
},
createRendererMessaging(rendererId) {
return extHostNotebookRenderers.createRendererMessaging(extension, rendererId);
},
Expand Down
3 changes: 0 additions & 3 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,10 +959,7 @@ export interface MainThreadNotebookShape extends IDisposable {
export interface MainThreadNotebookEditorsShape extends IDisposable {
$tryShowNotebookDocument(uriComponents: UriComponents, viewType: string, options: INotebookDocumentShowOptions): Promise<string>;
$tryRevealRange(id: string, range: ICellRange, revealType: NotebookEditorRevealType): Promise<void>;
$registerNotebookEditorDecorationType(key: string, options: notebookCommon.INotebookDecorationRenderOptions): void;
$removeNotebookEditorDecorationType(key: string): void;
$trySetSelections(id: string, range: ICellRange[]): void;
$trySetDecorations(id: string, range: ICellRange, decorationKey: string): void;
$tryApplyEdits(editorId: string, modelVersionId: number, cellEdits: ICellEditOperationDto[]): Promise<boolean>;
}

Expand Down
22 changes: 0 additions & 22 deletions src/vs/workbench/api/common/extHostNotebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class ExtHostNotebookEditor {
private _viewColumn?: vscode.ViewColumn;

private _visible: boolean = false;
private readonly _hasDecorationsForKey = new Set<string>();

private _editor?: vscode.NotebookEditor;

Expand Down Expand Up @@ -142,9 +141,6 @@ export class ExtHostNotebookEditor {
callback(edit);
return that._applyEdit(edit.finalize());
},
setDecorations(decorationType, range) {
return that.setDecorations(decorationType, range);
}
};

ExtHostNotebookEditor.apiEditorsToExtHost.set(this._editor, this);
Expand Down Expand Up @@ -211,22 +207,4 @@ export class ExtHostNotebookEditor {

return this._proxy.$tryApplyEdits(this.id, editData.documentVersionId, compressedEdits);
}

setDecorations(decorationType: vscode.NotebookEditorDecorationType, range: vscode.NotebookRange): void {
if (range.isEmpty && !this._hasDecorationsForKey.has(decorationType.key)) {
// avoid no-op call to the renderer
return;
}
if (range.isEmpty) {
this._hasDecorationsForKey.delete(decorationType.key);
} else {
this._hasDecorationsForKey.add(decorationType.key);
}

return this._proxy.$trySetDecorations(
this.id,
extHostConverter.NotebookRange.from(range),
decorationType.key
);
}
}
33 changes: 2 additions & 31 deletions src/vs/workbench/api/common/extHostNotebookEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,12 @@
*--------------------------------------------------------------------------------------------*/

import { Emitter } from 'vs/base/common/event';
import { IdGenerator } from 'vs/base/common/idGenerator';
import { ILogService } from 'vs/platform/log/common/log';
import { ExtHostNotebookEditorsShape, INotebookEditorPropertiesChangeData, INotebookEditorViewColumnInfo, MainContext, MainThreadNotebookEditorsShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostNotebookEditorsShape, INotebookEditorPropertiesChangeData, INotebookEditorViewColumnInfo } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import type * as vscode from 'vscode';

class NotebookEditorDecorationType {

private static readonly _Keys = new IdGenerator('NotebookEditorDecorationType');

readonly value: vscode.NotebookEditorDecorationType;

constructor(proxy: MainThreadNotebookEditorsShape, options: vscode.NotebookDecorationRenderOptions) {
const key = NotebookEditorDecorationType._Keys.nextId();
proxy.$registerNotebookEditorDecorationType(key, typeConverters.NotebookDecorationRenderOptions.from(options));

this.value = {
key,
dispose() {
proxy.$removeNotebookEditorDecorationType(key);
}
};
}
}


export class ExtHostNotebookEditors implements ExtHostNotebookEditorsShape {

Expand All @@ -42,16 +21,8 @@ export class ExtHostNotebookEditors implements ExtHostNotebookEditorsShape {

constructor(
@ILogService private readonly _logService: ILogService,
@IExtHostRpcService private readonly _extHostRpc: IExtHostRpcService,
private readonly _notebooksAndEditors: ExtHostNotebookController,
) {

}


createNotebookEditorDecorationType(options: vscode.NotebookDecorationRenderOptions): vscode.NotebookEditorDecorationType {
return new NotebookEditorDecorationType(this._extHostRpc.getProxy(MainContext.MainThreadNotebookEditors), options).value;
}
) { }

$acceptEditorPropertiesChanged(id: string, data: INotebookEditorPropertiesChangeData): void {
this._logService.debug('ExtHostNotebook#$acceptEditorPropertiesChanged', id, data);
Expand Down
10 changes: 0 additions & 10 deletions src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1675,16 +1675,6 @@ export namespace NotebookExclusiveDocumentPattern {
}
}

export namespace NotebookDecorationRenderOptions {
export function from(options: vscode.NotebookDecorationRenderOptions): notebooks.INotebookDecorationRenderOptions {
return {
backgroundColor: <string | types.ThemeColor>options.backgroundColor,
borderColor: <string | types.ThemeColor>options.borderColor,
top: options.top ? ThemableDecorationAttachmentRenderOptions.from(options.top) : undefined
};
}
}

export namespace NotebookStatusBarItem {
export function from(item: vscode.NotebookCellStatusBarItem, commandsConverter: Command.ICommandsConverter, disposables: DisposableStore): notebooks.INotebookCellStatusBarItem {
const command = typeof item.command === 'string' ? { title: '', command: item.command } : item.command;
Expand Down
10 changes: 0 additions & 10 deletions src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,16 +591,6 @@ export interface INotebookEditor {
*/
changeModelDecorations<T>(callback: (changeAccessor: IModelDecorationsChangeAccessor) => T): T | null;

/**
* Set decoration key on cells in the range
*/
setEditorDecorations(key: string, range: ICellRange): void;

/**
* Remove decoration key from the notebook editor
*/
removeEditorDecorations(key: string): void;

/**
* Get a contribution of this editor.
* @id Unique identifier of the contribution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { createDecorator, ServicesAccessor } from 'vs/platform/instantiation/com
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { INotebookEditor, INotebookEditorCreationOptions } 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 INotebookEditorService = createDecorator<INotebookEditorService>('INotebookEditorWidgetService');

Expand All @@ -27,8 +26,4 @@ export interface INotebookEditorService {
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { isCompositeNotebookEditorInput, NotebookEditorInput } from 'vs/workbenc
import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
import { INotebookEditor, INotebookEditorCreationOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { Emitter } from 'vs/base/common/event';
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { GroupIdentifier } from 'vs/workbench/common/editor';

export class NotebookEditorWidgetService implements INotebookEditorService {
Expand All @@ -23,7 +22,6 @@ export class NotebookEditorWidgetService implements INotebookEditorService {

private readonly _disposables = new DisposableStore();
private readonly _notebookEditors = new Map<string, INotebookEditor>();
private readonly _decorationOptionProviders = new Map<string, INotebookDecorationRenderOptions>();

private readonly _onNotebookEditorAdd = new Emitter<INotebookEditor>();
private readonly _onNotebookEditorsRemove = new Emitter<INotebookEditor>();
Expand Down Expand Up @@ -185,21 +183,4 @@ export class NotebookEditorWidgetService implements INotebookEditorService {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { registerZIndex, ZIndex } from 'vs/platform/layout/browser/zIndexRegistr
import { IEditorProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { contrastBorder, diffInserted, diffRemoved, editorBackground, errorForeground, focusBorder, foreground, iconForeground, listInactiveSelectionBackground, registerColor, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, textBlockQuoteBackground, textBlockQuoteBorder, textLinkActiveForeground, textLinkForeground, textPreformatForeground, toolbarHoverBackground, transparent } from 'vs/platform/theme/common/colorRegistry';
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { PANEL_BORDER, SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
import { debugIconStartForeground } from 'vs/workbench/contrib/debug/browser/debugColors';
import { CellEditState, CellFindMatchWithIndex, CellFocusMode, CellLayoutContext, CellRevealType, IActiveNotebookEditorDelegate, IBaseCellEditorOptions, ICellOutputViewModel, ICellViewModel, ICommonCellInfo, IDisplayOutputLayoutUpdateRequest, IFocusNotebookCellOptions, IInsetRenderOutput, IModelDecorationsChangeAccessor, INotebookDeltaDecoration, INotebookEditor, INotebookEditorContribution, INotebookEditorContributionDescription, INotebookEditorCreationOptions, INotebookEditorDelegate, INotebookEditorMouseEvent, INotebookEditorOptions, INotebookEditorViewState, INotebookViewCellsUpdateEvent, INotebookWebviewMessage, RenderOutputType } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
Expand All @@ -66,7 +66,6 @@ import { NotebookEventDispatcher } from 'vs/workbench/contrib/notebook/browser/v
import { MarkupCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markupCellViewModel';
import { CellViewModel, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl';
import { ViewContext } from 'vs/workbench/contrib/notebook/browser/viewModel/viewContext';
import { NotebookDecorationCSSRules, NotebookRefCountedStyleSheet } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookEditorDecorations';
import { NotebookEditorToolbar } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookEditorToolbar';
import { NotebookEditorContextKeys } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys';
import { NotebookOverviewRuler } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookOverviewRuler';
Expand Down Expand Up @@ -346,7 +345,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
@ILayoutService private readonly layoutService: ILayoutService,
@IContextMenuService private readonly contextMenuService: IContextMenuService,
@IMenuService private readonly menuService: IMenuService,
@IThemeService private readonly themeService: IThemeService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@INotebookExecutionService private readonly notebookExecutionService: INotebookExecutionService,
@INotebookExecutionStateService notebookExecutionStateService: INotebookExecutionStateService,
Expand Down Expand Up @@ -2078,61 +2076,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
//#endregion

//#region Decorations
private _editorStyleSheets = new Map<string, NotebookRefCountedStyleSheet>();
private _decorationRules = new Map<string, NotebookDecorationCSSRules>();
private _decortionKeyToIds = new Map<string, string[]>();

private _registerDecorationType(key: string) {
const options = this.notebookEditorService.resolveEditorDecorationOptions(key);

if (options) {
const styleElement = DOM.createStyleSheet(this._body);
const styleSheet = new NotebookRefCountedStyleSheet({
removeEditorStyleSheets: (key) => {
this._editorStyleSheets.delete(key);
}
}, key, styleElement);
this._editorStyleSheets.set(key, styleSheet);
this._decorationRules.set(key, new NotebookDecorationCSSRules(this.themeService, styleSheet, {
key,
options,
styleSheet
}));
}
}

setEditorDecorations(key: string, range: ICellRange): void {
if (!this.viewModel) {
return;
}

// create css style for the decoration
if (!this._editorStyleSheets.has(key)) {
this._registerDecorationType(key);
}

const decorationRule = this._decorationRules.get(key);
if (!decorationRule) {
return;
}

const existingDecorations = this._decortionKeyToIds.get(key) || [];
const newDecorations = this.viewModel.getCellsInRange(range).map(cell => ({
handle: cell.handle,
options: { className: decorationRule.className, outputClassName: decorationRule.className, topClassName: decorationRule.topClassName }
}));

this._decortionKeyToIds.set(key, this.deltaCellDecorations(existingDecorations, newDecorations));
}

removeEditorDecorations(key: string): void {
if (this._decorationRules.has(key)) {
this._decorationRules.get(key)?.dispose();
}

const cellDecorations = this._decortionKeyToIds.get(key);
this.deltaCellDecorations(cellDecorations || [], []);
}

deltaCellDecorations(oldDecorations: string[], newDecorations: INotebookDeltaDecoration[]): string[] {
const ret = this.viewModel?.deltaCellDecorations(oldDecorations, newDecorations) || [];
Expand Down
Loading

0 comments on commit 8b0b3ee

Please sign in to comment.