From eebdf8174b087979ae6af103f6f2e2f6f9062056 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Thu, 11 Aug 2022 17:44:32 -0700 Subject: [PATCH] Organize notebook related services (#157966) --- .../mainThreadNotebookDocumentsAndEditors.ts | 2 +- .../api/browser/mainThreadNotebookEditors.ts | 2 +- .../api/browser/mainThreadNotebookKernels.ts | 2 +- .../interactive/browser/interactiveEditor.ts | 2 +- .../browser/controller/coreActions.ts | 2 +- .../notebook/browser/notebook.contribution.ts | 16 +-- .../notebook/browser/notebookEditor.ts | 2 +- .../notebook/browser/notebookEditorWidget.ts | 105 +----------------- .../notebookCellStatusBarServiceImpl.ts | 0 .../{ => services}/notebookEditorService.ts | 0 .../notebookEditorServiceImpl.ts | 2 +- .../notebookExecutionServiceImpl.ts | 0 .../notebookExecutionStateServiceImpl.ts | 0 .../notebookKernelServiceImpl.ts | 0 .../notebookRendererMessagingServiceImpl.ts | 0 .../{ => services}/notebookServiceImpl.ts | 0 .../browser/viewModel/cellEditorOptions.ts | 105 ++++++++++++++++++ .../browser/notebookExecutionService.test.ts | 4 +- .../notebookExecutionStateService.test.ts | 6 +- .../browser/notebookKernelService.test.ts | 2 +- .../notebookRendererMessagingService.test.ts | 2 +- .../test/browser/notebookServiceImpl.test.ts | 2 +- 22 files changed, 130 insertions(+), 126 deletions(-) rename src/vs/workbench/contrib/notebook/browser/{ => services}/notebookCellStatusBarServiceImpl.ts (100%) rename src/vs/workbench/contrib/notebook/browser/{ => services}/notebookEditorService.ts (100%) rename src/vs/workbench/contrib/notebook/browser/{ => services}/notebookEditorServiceImpl.ts (99%) rename src/vs/workbench/contrib/notebook/browser/{ => services}/notebookExecutionServiceImpl.ts (100%) rename src/vs/workbench/contrib/notebook/browser/{ => services}/notebookExecutionStateServiceImpl.ts (100%) rename src/vs/workbench/contrib/notebook/browser/{ => services}/notebookKernelServiceImpl.ts (100%) rename src/vs/workbench/contrib/notebook/browser/{ => services}/notebookRendererMessagingServiceImpl.ts (100%) rename src/vs/workbench/contrib/notebook/browser/{ => services}/notebookServiceImpl.ts (100%) create mode 100644 src/vs/workbench/contrib/notebook/browser/viewModel/cellEditorOptions.ts diff --git a/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts b/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts index 998bae8c5b5..1c649d6f669 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts @@ -13,7 +13,7 @@ import { MainThreadNotebookEditors } from 'vs/workbench/api/browser/mainThreadNo import { extHostCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers'; import { editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn'; import { getNotebookEditorFromEditorPane, IActiveNotebookEditor, INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; -import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService'; +import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; diff --git a/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts b/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts index 21d61097634..d1776c13db5 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookEditors.ts @@ -5,7 +5,7 @@ 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 { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService'; import { ExtHostContext, ExtHostNotebookEditorsShape, ICellEditOperationDto, INotebookDocumentShowOptions, INotebookEditorViewColumnInfo, MainThreadNotebookEditorsShape, NotebookEditorRevealType } from '../common/extHost.protocol'; import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange'; import { ILogService } from 'vs/platform/log/common/log'; diff --git a/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts b/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts index 7e02274edc9..136d77a68c0 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts @@ -13,7 +13,7 @@ import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto'; import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers'; import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; -import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService'; +import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService'; import { INotebookCellExecution, INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; import { INotebookKernel, INotebookKernelChangeEvent, INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService'; import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier'; diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index 167a0472f36..ea0da2a71b9 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -24,7 +24,7 @@ import { getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/ import { InteractiveEditorInput } from 'vs/workbench/contrib/interactive/browser/interactiveEditorInput'; import { ICellViewModel, INotebookEditorOptions, INotebookEditorViewState } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import { NotebookEditorExtensionsRegistry } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions'; -import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService'; +import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService'; import { cellEditorBackground, NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget'; import { GroupsOrder, IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { ExecutionStateCellStatusBarContrib, TimerCellStatusBarContrib } from 'vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController'; diff --git a/src/vs/workbench/contrib/notebook/browser/controller/coreActions.ts b/src/vs/workbench/contrib/notebook/browser/controller/coreActions.ts index 9a42a89b378..58953153733 100644 --- a/src/vs/workbench/contrib/notebook/browser/controller/coreActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/controller/coreActions.ts @@ -14,7 +14,7 @@ import { NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_IS_ACTIVE_E import { ICellRange, isICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorCommandsContext } from 'vs/workbench/common/editor'; -import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService'; +import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions'; import { TypeConstraint } from 'vs/base/common/types'; diff --git a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts index 33bf079467f..6bb9d954a2d 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -28,7 +28,7 @@ import { EditorInput } from 'vs/workbench/common/editor/editorInput'; import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor'; import { isCompositeNotebookEditorInput, NotebookEditorInput, NotebookEditorInputOptions } from 'vs/workbench/contrib/notebook/common/notebookEditorInput'; import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; -import { NotebookService } from 'vs/workbench/contrib/notebook/browser/notebookServiceImpl'; +import { NotebookService } from 'vs/workbench/contrib/notebook/browser/services/notebookServiceImpl'; import { CellKind, CellUri, IResolvedNotebookEditorModel, NotebookDocumentBackupData, NotebookWorkingCopyTypeIdentifier, NotebookSetting, ICellOutput, ICell } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo'; @@ -38,16 +38,16 @@ import { NotebookTextDiffEditor } from 'vs/workbench/contrib/notebook/browser/di import { INotebookEditorWorkerService } from 'vs/workbench/contrib/notebook/common/services/notebookWorkerService'; import { NotebookEditorWorkerServiceImpl } from 'vs/workbench/contrib/notebook/browser/services/notebookWorkerServiceImpl'; import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService'; -import { NotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/browser/notebookCellStatusBarServiceImpl'; -import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService'; -import { NotebookEditorWidgetService } from 'vs/workbench/contrib/notebook/browser/notebookEditorServiceImpl'; +import { NotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/browser/services/notebookCellStatusBarServiceImpl'; +import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService'; +import { NotebookEditorWidgetService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl'; import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema'; import { Event } from 'vs/base/common/event'; import { getFormattedMetadataJSON, getStreamOutputData } from 'vs/workbench/contrib/notebook/browser/diff/diffElementViewModel'; import { NotebookModelResolverServiceImpl } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl'; import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService'; -import { NotebookKernelService } from 'vs/workbench/contrib/notebook/browser/notebookKernelServiceImpl'; +import { NotebookKernelService } from 'vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl'; import { IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy'; import { IResourceEditorInput } from 'vs/platform/editor/common/editor'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; @@ -56,7 +56,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { ILabelService } from 'vs/platform/label/common/label'; import { IWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackup'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; -import { NotebookRendererMessagingService } from 'vs/workbench/contrib/notebook/browser/notebookRendererMessagingServiceImpl'; +import { NotebookRendererMessagingService } from 'vs/workbench/contrib/notebook/browser/services/notebookRendererMessagingServiceImpl'; import { INotebookRendererMessagingService } from 'vs/workbench/contrib/notebook/common/notebookRendererMessagingService'; // Editor Controller @@ -94,8 +94,8 @@ import 'vs/workbench/contrib/notebook/browser/diff/notebookDiffActions'; // Services import { editorOptionsRegistry } from 'vs/editor/common/config/editorOptions'; -import { NotebookExecutionStateService } from 'vs/workbench/contrib/notebook/browser/notebookExecutionStateServiceImpl'; -import { NotebookExecutionService } from 'vs/workbench/contrib/notebook/browser/notebookExecutionServiceImpl'; +import { NotebookExecutionStateService } from 'vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl'; +import { NotebookExecutionService } from 'vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl'; import { INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService'; import { INotebookKeymapService } from 'vs/workbench/contrib/notebook/common/notebookKeymapService'; import { NotebookKeymapService } from 'vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl'; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts index d82c4b964b9..a0f11ab57a4 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts @@ -27,7 +27,7 @@ import { DEFAULT_EDITOR_ASSOCIATION, EditorInputCapabilities, EditorPaneSelectio import { EditorInput } from 'vs/workbench/common/editor/editorInput'; import { SELECT_KERNEL_ID } from 'vs/workbench/contrib/notebook/browser/controller/coreActions'; import { INotebookEditorOptions, INotebookEditorViewState } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; -import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService'; +import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService'; import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget'; import { NotebooKernelActionViewItem } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookKernelActionViewItem'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index ff712964496..3208dcc9cf3 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -21,7 +21,6 @@ import { Color, RGBA } from 'vs/base/common/color'; import { onUnexpectedError } from 'vs/base/common/errors'; import { Emitter, Event } from 'vs/base/common/event'; import { combinedDisposable, Disposable, DisposableStore, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; -import { deepClone } from 'vs/base/common/objects'; import { setTimeout0 } from 'vs/base/common/platform'; import { extname, isEqual } from 'vs/base/common/resources'; import { URI } from 'vs/base/common/uri'; @@ -51,7 +50,7 @@ import { EDITOR_PANE_BACKGROUND, PANEL_BORDER, SIDE_BAR_BACKGROUND } from 'vs/wo 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'; import { NotebookEditorExtensionsRegistry } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions'; -import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService'; +import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService'; import { notebookDebug } from 'vs/workbench/contrib/notebook/browser/notebookLogger'; import { NotebookCellStateChangedEvent, NotebookLayoutChangedEvent, NotebookLayoutInfo } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents'; import { CellContextKeyManager } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellContextKeys'; @@ -85,102 +84,10 @@ import { IWebview } from 'vs/workbench/contrib/webview/browser/webview'; import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { NotebookPerfMarks } from 'vs/workbench/contrib/notebook/common/notebookPerformance'; +import { BaseCellEditorOptions } from 'vs/workbench/contrib/notebook/browser/viewModel/cellEditorOptions'; const $ = DOM.$; -export class BaseCellEditorOptions extends Disposable implements IBaseCellEditorOptions { - private static fixedEditorOptions: IEditorOptions = { - scrollBeyondLastLine: false, - scrollbar: { - verticalScrollbarSize: 14, - horizontal: 'auto', - useShadows: true, - verticalHasArrows: false, - horizontalHasArrows: false, - alwaysConsumeMouseWheel: false - }, - renderLineHighlightOnlyWhenFocus: true, - overviewRulerLanes: 0, - lineNumbers: 'off', - lineDecorationsWidth: 0, - folding: true, - fixedOverflowWidgets: true, - minimap: { enabled: false }, - renderValidationDecorations: 'on', - lineNumbersMinChars: 3 - }; - - private _localDisposableStore = this._register(new DisposableStore()); - private readonly _onDidChange = this._register(new Emitter()); - readonly onDidChange: Event = this._onDidChange.event; - private _value: IEditorOptions; - - get value(): Readonly { - return this._value; - } - - constructor(readonly notebookEditor: INotebookEditorDelegate, readonly notebookOptions: NotebookOptions, readonly configurationService: IConfigurationService, readonly language: string) { - super(); - this._register(configurationService.onDidChangeConfiguration(e => { - if (e.affectsConfiguration('editor') || e.affectsConfiguration('notebook')) { - this._recomputeOptions(); - } - })); - - this._register(notebookOptions.onDidChangeOptions(e => { - if (e.cellStatusBarVisibility || e.editorTopPadding || e.editorOptionsCustomizations) { - this._recomputeOptions(); - } - })); - - this._register(this.notebookEditor.onDidChangeModel(() => { - this._localDisposableStore.clear(); - - if (this.notebookEditor.hasModel()) { - this._localDisposableStore.add(this.notebookEditor.onDidChangeOptions(() => { - this._recomputeOptions(); - })); - - this._recomputeOptions(); - } - })); - - if (this.notebookEditor.hasModel()) { - this._localDisposableStore.add(this.notebookEditor.onDidChangeOptions(() => { - this._recomputeOptions(); - })); - } - - this._value = this._computeEditorOptions(); - } - - private _recomputeOptions(): void { - this._value = this._computeEditorOptions(); - this._onDidChange.fire(); - } - - private _computeEditorOptions() { - const editorOptions = deepClone(this.configurationService.getValue('editor', { overrideIdentifier: this.language })); - const layoutConfig = this.notebookOptions.getLayoutConfiguration(); - const editorOptionsOverrideRaw = layoutConfig.editorOptionsCustomizations ?? {}; - const editorOptionsOverride: { [key: string]: any } = {}; - for (const key in editorOptionsOverrideRaw) { - if (key.indexOf('editor.') === 0) { - editorOptionsOverride[key.substring(7)] = editorOptionsOverrideRaw[key]; - } - } - const computed = Object.freeze({ - ...editorOptions, - ...BaseCellEditorOptions.fixedEditorOptions, - ...editorOptionsOverride, - ...{ padding: { top: 12, bottom: 12 } }, - readOnly: this.notebookEditor.isReadOnly - }); - - return computed; - } -} - export function getDefaultNotebookCreationOptions(): INotebookEditorCreationOptions { // We inlined the id to avoid loading comment contrib in tests const skipContributions = ['editor.contrib.review']; @@ -2007,10 +1914,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD return this._list.getAbsoluteTopOfElement(cell); } - isScrolledToBottom() { - return this._listViewInfoAccessor.isScrolledToBottom(); - } - scrollToBottom() { this._listViewInfoAccessor.scrollToBottom(); } @@ -2111,10 +2014,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD return this._listViewInfoAccessor.getVisibleRangesPlusViewportAboveAndBelow(); } - setScrollTop(scrollTop: number) { - this._listViewInfoAccessor.setScrollTop(scrollTop); - } - //#endregion //#region Decorations diff --git a/src/vs/workbench/contrib/notebook/browser/notebookCellStatusBarServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookCellStatusBarServiceImpl.ts similarity index 100% rename from src/vs/workbench/contrib/notebook/browser/notebookCellStatusBarServiceImpl.ts rename to src/vs/workbench/contrib/notebook/browser/services/notebookCellStatusBarServiceImpl.ts diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorService.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookEditorService.ts similarity index 100% rename from src/vs/workbench/contrib/notebook/browser/notebookEditorService.ts rename to src/vs/workbench/contrib/notebook/browser/services/notebookEditorService.ts diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.ts similarity index 99% rename from src/vs/workbench/contrib/notebook/browser/notebookEditorServiceImpl.ts rename to src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.ts index b8e05ea5a02..19d44f350d6 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.ts @@ -9,7 +9,7 @@ import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle'; import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { isCompositeNotebookEditorInput, NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput'; -import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService'; +import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService'; import { INotebookEditor, INotebookEditorCreationOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import { Emitter } from 'vs/base/common/event'; import { GroupIdentifier } from 'vs/workbench/common/editor'; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookExecutionServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.ts similarity index 100% rename from src/vs/workbench/contrib/notebook/browser/notebookExecutionServiceImpl.ts rename to src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.ts diff --git a/src/vs/workbench/contrib/notebook/browser/notebookExecutionStateServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl.ts similarity index 100% rename from src/vs/workbench/contrib/notebook/browser/notebookExecutionStateServiceImpl.ts rename to src/vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl.ts diff --git a/src/vs/workbench/contrib/notebook/browser/notebookKernelServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.ts similarity index 100% rename from src/vs/workbench/contrib/notebook/browser/notebookKernelServiceImpl.ts rename to src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.ts diff --git a/src/vs/workbench/contrib/notebook/browser/notebookRendererMessagingServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookRendererMessagingServiceImpl.ts similarity index 100% rename from src/vs/workbench/contrib/notebook/browser/notebookRendererMessagingServiceImpl.ts rename to src/vs/workbench/contrib/notebook/browser/services/notebookRendererMessagingServiceImpl.ts diff --git a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.ts similarity index 100% rename from src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts rename to src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.ts diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/cellEditorOptions.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/cellEditorOptions.ts new file mode 100644 index 00000000000..e03d9004df9 --- /dev/null +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/cellEditorOptions.ts @@ -0,0 +1,105 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { Emitter, Event } from 'vs/base/common/event'; +import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; +import { deepClone } from 'vs/base/common/objects'; +import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { IBaseCellEditorOptions, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; +import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions'; + +export class BaseCellEditorOptions extends Disposable implements IBaseCellEditorOptions { + private static fixedEditorOptions: IEditorOptions = { + scrollBeyondLastLine: false, + scrollbar: { + verticalScrollbarSize: 14, + horizontal: 'auto', + useShadows: true, + verticalHasArrows: false, + horizontalHasArrows: false, + alwaysConsumeMouseWheel: false + }, + renderLineHighlightOnlyWhenFocus: true, + overviewRulerLanes: 0, + lineNumbers: 'off', + lineDecorationsWidth: 0, + folding: true, + fixedOverflowWidgets: true, + minimap: { enabled: false }, + renderValidationDecorations: 'on', + lineNumbersMinChars: 3 + }; + + private _localDisposableStore = this._register(new DisposableStore()); + private readonly _onDidChange = this._register(new Emitter()); + readonly onDidChange: Event = this._onDidChange.event; + private _value: IEditorOptions; + + get value(): Readonly { + return this._value; + } + + constructor(readonly notebookEditor: INotebookEditorDelegate, readonly notebookOptions: NotebookOptions, readonly configurationService: IConfigurationService, readonly language: string) { + super(); + this._register(configurationService.onDidChangeConfiguration(e => { + if (e.affectsConfiguration('editor') || e.affectsConfiguration('notebook')) { + this._recomputeOptions(); + } + })); + + this._register(notebookOptions.onDidChangeOptions(e => { + if (e.cellStatusBarVisibility || e.editorTopPadding || e.editorOptionsCustomizations) { + this._recomputeOptions(); + } + })); + + this._register(this.notebookEditor.onDidChangeModel(() => { + this._localDisposableStore.clear(); + + if (this.notebookEditor.hasModel()) { + this._localDisposableStore.add(this.notebookEditor.onDidChangeOptions(() => { + this._recomputeOptions(); + })); + + this._recomputeOptions(); + } + })); + + if (this.notebookEditor.hasModel()) { + this._localDisposableStore.add(this.notebookEditor.onDidChangeOptions(() => { + this._recomputeOptions(); + })); + } + + this._value = this._computeEditorOptions(); + } + + private _recomputeOptions(): void { + this._value = this._computeEditorOptions(); + this._onDidChange.fire(); + } + + private _computeEditorOptions() { + const editorOptions = deepClone(this.configurationService.getValue('editor', { overrideIdentifier: this.language })); + const layoutConfig = this.notebookOptions.getLayoutConfiguration(); + const editorOptionsOverrideRaw = layoutConfig.editorOptionsCustomizations ?? {}; + const editorOptionsOverride: { [key: string]: any } = {}; + for (const key in editorOptionsOverrideRaw) { + if (key.indexOf('editor.') === 0) { + editorOptionsOverride[key.substring(7)] = editorOptionsOverrideRaw[key]; + } + } + const computed = Object.freeze({ + ...editorOptions, + ...BaseCellEditorOptions.fixedEditorOptions, + ...editorOptionsOverride, + ...{ padding: { top: 12, bottom: 12 } }, + readOnly: this.notebookEditor.isReadOnly + }); + + return computed; + } +} diff --git a/src/vs/workbench/contrib/notebook/test/browser/notebookExecutionService.test.ts b/src/vs/workbench/contrib/notebook/test/browser/notebookExecutionService.test.ts index e249f73080a..09ebff6401b 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/notebookExecutionService.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/notebookExecutionService.test.ts @@ -15,8 +15,8 @@ import { IMenu, IMenuService } from 'vs/platform/actions/common/actions'; import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; import { insertCellAtIndex } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations'; -import { NotebookExecutionService } from 'vs/workbench/contrib/notebook/browser/notebookExecutionServiceImpl'; -import { NotebookKernelService } from 'vs/workbench/contrib/notebook/browser/notebookKernelServiceImpl'; +import { NotebookExecutionService } from 'vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl'; +import { NotebookKernelService } from 'vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl'; import { NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { CellKind, IOutputDto, NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon'; diff --git a/src/vs/workbench/contrib/notebook/test/browser/notebookExecutionStateService.test.ts b/src/vs/workbench/contrib/notebook/test/browser/notebookExecutionStateService.test.ts index e925ef9e011..c98e69f2589 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/notebookExecutionStateService.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/notebookExecutionStateService.test.ts @@ -14,9 +14,9 @@ import { IMenu, IMenuService } from 'vs/platform/actions/common/actions'; import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; import { insertCellAtIndex } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations'; -import { NotebookExecutionService } from 'vs/workbench/contrib/notebook/browser/notebookExecutionServiceImpl'; -import { NotebookExecutionStateService } from 'vs/workbench/contrib/notebook/browser/notebookExecutionStateServiceImpl'; -import { NotebookKernelService } from 'vs/workbench/contrib/notebook/browser/notebookKernelServiceImpl'; +import { NotebookExecutionService } from 'vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl'; +import { NotebookExecutionStateService } from 'vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl'; +import { NotebookKernelService } from 'vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl'; import { NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { CellEditType, CellKind, CellUri, IOutputDto, NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon'; diff --git a/src/vs/workbench/contrib/notebook/test/browser/notebookKernelService.test.ts b/src/vs/workbench/contrib/notebook/test/browser/notebookKernelService.test.ts index 1b03a84c623..f0aac326e94 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/notebookKernelService.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/notebookKernelService.test.ts @@ -9,7 +9,7 @@ import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; import { setupInstantiationService, withTestNotebook as _withTestNotebook } from 'vs/workbench/contrib/notebook/test/browser/testNotebookEditor'; import { Emitter, Event } from 'vs/base/common/event'; import { INotebookKernel, INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService'; -import { NotebookKernelService } from 'vs/workbench/contrib/notebook/browser/notebookKernelServiceImpl'; +import { NotebookKernelService } from 'vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl'; import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; import { mock } from 'vs/base/test/common/mock'; import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; diff --git a/src/vs/workbench/contrib/notebook/test/browser/notebookRendererMessagingService.test.ts b/src/vs/workbench/contrib/notebook/test/browser/notebookRendererMessagingService.test.ts index 715d65994cc..3aee4e1668b 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/notebookRendererMessagingService.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/notebookRendererMessagingService.test.ts @@ -5,7 +5,7 @@ import { NullExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { stub } from 'sinon'; -import { NotebookRendererMessagingService } from 'vs/workbench/contrib/notebook/browser/notebookRendererMessagingServiceImpl'; +import { NotebookRendererMessagingService } from 'vs/workbench/contrib/notebook/browser/services/notebookRendererMessagingServiceImpl'; import * as assert from 'assert'; import { timeout } from 'vs/base/common/async'; diff --git a/src/vs/workbench/contrib/notebook/test/browser/notebookServiceImpl.test.ts b/src/vs/workbench/contrib/notebook/test/browser/notebookServiceImpl.test.ts index 32e71906a47..225069a56d7 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/notebookServiceImpl.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/notebookServiceImpl.test.ts @@ -12,7 +12,7 @@ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessib import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; import { IFileService } from 'vs/platform/files/common/files'; import { IStorageService } from 'vs/platform/storage/common/storage'; -import { NotebookProviderInfoStore } from 'vs/workbench/contrib/notebook/browser/notebookServiceImpl'; +import { NotebookProviderInfoStore } from 'vs/workbench/contrib/notebook/browser/services/notebookServiceImpl'; import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService'; import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider'; import { EditorResolverService } from 'vs/workbench/services/editor/browser/editorResolverService';