From abae48aa4296bf8c24218b46038ddb5c379c23a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Mon, 11 Dec 2023 21:11:24 +0100 Subject: [PATCH] fix: add empty implementation to prevent crashes --- src/missing-services.ts | 73 ++++++++++++++++++++++++++-------- src/service-override/editor.ts | 66 ++++++++++++++++++++++++------ 2 files changed, 111 insertions(+), 28 deletions(-) diff --git a/src/missing-services.ts b/src/missing-services.ts index e32e52f6..cd82a8e3 100644 --- a/src/missing-services.ts +++ b/src/missing-services.ts @@ -5,7 +5,7 @@ import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/b import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity' import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles' import { IFileService } from 'vs/platform/files/common/files' -import { GroupOrientation, IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService' +import { GroupOrientation, IEditorGroup, IEditorGroupsService, IEditorPart } from 'vs/workbench/services/editor/common/editorGroupsService' import { IWorkingCopyFileService, WorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService' import { IPathService } from 'vs/workbench/services/path/common/pathService' import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions' @@ -161,7 +161,7 @@ import { IChatVariablesService } from 'vs/workbench/contrib/chat/common/chatVari import { IAiRelatedInformationService } from 'vs/workbench/services/aiRelatedInformation/common/aiRelatedInformation' import { IAiEmbeddingVectorService } from 'vs/workbench/services/aiEmbeddingVector/common/aiEmbeddingVectorService' import { ResourceSet } from 'vs/base/common/map' -import { IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor' +import { DEFAULT_EDITOR_PART_OPTIONS, IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor' import { IMessage, ISignService } from 'vs/platform/sign/common/sign' import { BrowserHostService } from 'vs/workbench/services/host/browser/browserHostService' import { IBannerService } from 'vs/workbench/services/banner/browser/bannerService' @@ -376,26 +376,67 @@ class EmptyEditorGroup implements IEditorGroup, IEditorGroupView { } const fakeActiveGroup = new EmptyEditorGroup() -class EmptyEditorGroupsService implements IEditorGroupsService { - onDidCreateAuxiliaryEditorPart = Event.None - parts = [] - get activePart () { - return this - } +class EmptyEditorPart implements IEditorPart { + onDidLayout = Event.None + onDidScroll = Event.None + get contentDimension (): never { return unsupported() } + isReady = true + whenReady = Promise.resolve() + whenRestored = Promise.resolve() + hasRestorableState = false + centerLayout = unsupported + isLayoutCentered = unsupported + enforcePartOptions = unsupported + onDidChangeActiveGroup = Event.None + onDidAddGroup = Event.None + onDidRemoveGroup = Event.None + onDidMoveGroup = Event.None + onDidActivateGroup = Event.None + onDidChangeGroupIndex = Event.None + onDidChangeGroupLocked = Event.None + onDidChangeGroupMaximized = Event.None + activeGroup = fakeActiveGroup + get sideGroup (): never { return unsupported() } + groups = [fakeActiveGroup] + count = 0 + orientation = GroupOrientation.HORIZONTAL + getGroups = () => [] + getGroup = () => undefined + activateGroup = unsupported + getSize = unsupported + setSize = unsupported + arrangeGroups = unsupported + toggleMaximizeGroup = unsupported + toggleExpandGroup = unsupported + applyLayout = unsupported + getLayout = unsupported + setGroupOrientation = unsupported + findGroup = () => undefined + addGroup = unsupported + removeGroup = unsupported + moveGroup = unsupported + mergeGroup = unsupported + mergeAllGroups = unsupported + copyGroup = unsupported + partOptions = DEFAULT_EDITOR_PART_OPTIONS - get mainPart () { - return this - } + onDidChangeEditorPartOptions = Event.None + createEditorDropTarget = unsupported +} + +class EmptyEditorGroupsService implements IEditorGroupsService { + onDidCreateAuxiliaryEditorPart = Event.None + mainPart = new EmptyEditorPart() + activePart = this.mainPart + parts = [this.mainPart] getPart = unsupported createAuxiliaryEditorPart = unsupported onDidChangeGroupMaximized = Event.None toggleMaximizeGroup = unsupported toggleExpandGroup = unsupported - get partOptions () { - return unsupported() - } + partOptions = DEFAULT_EDITOR_PART_OPTIONS createEditorDropTarget = unsupported readonly _serviceBrand = undefined @@ -1888,8 +1929,8 @@ registerSingleton(ICustomEditorService, class CustomEditorService implements ICu getAllCustomEditors = unsupported getContributedCustomEditors = unsupported getUserConfiguredCustomEditors = unsupported - registerCustomEditorCapabilities = unsupported - getCustomEditorCapabilities = unsupported + registerCustomEditorCapabilities = () => Disposable.None + getCustomEditorCapabilities = () => undefined }, InstantiationType.Delayed) registerSingleton(IWebviewService, class WebviewService implements IWebviewService { diff --git a/src/service-override/editor.ts b/src/service-override/editor.ts index 027774be..037d13fe 100644 --- a/src/service-override/editor.ts +++ b/src/service-override/editor.ts @@ -11,10 +11,10 @@ import { IReference } from 'vs/base/common/lifecycle' import { ITextEditorService, TextEditorService } from 'vs/workbench/services/textfile/common/textEditorService' import { Registry } from 'vs/platform/registry/common/platform' import { FILE_EDITOR_INPUT_ID } from 'vs/workbench/contrib/files/common/files' -import { GroupOrientation, IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService' +import { GroupOrientation, IEditorGroup, IEditorGroupsService, IEditorPart } from 'vs/workbench/services/editor/common/editorGroupsService' import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' -import { IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor' +import { DEFAULT_EDITOR_PART_OPTIONS, IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor' import { MonacoDelegateEditorGroupsService, MonacoEditorService, OpenEditor } from './tools/editor' import { unsupported } from '../tools' import 'vs/workbench/browser/parts/editor/editor.contribution' @@ -103,25 +103,67 @@ class EmptyEditorGroup implements IEditorGroup, IEditorGroupView { const fakeActiveGroup = new EmptyEditorGroup() +class EmptyEditorPart implements IEditorPart { + onDidLayout = Event.None + onDidScroll = Event.None + get contentDimension (): never { return unsupported() } + isReady = true + whenReady = Promise.resolve() + whenRestored = Promise.resolve() + hasRestorableState = false + centerLayout = unsupported + isLayoutCentered = unsupported + enforcePartOptions = unsupported + onDidChangeActiveGroup = Event.None + onDidAddGroup = Event.None + onDidRemoveGroup = Event.None + onDidMoveGroup = Event.None + onDidActivateGroup = Event.None + onDidChangeGroupIndex = Event.None + onDidChangeGroupLocked = Event.None + onDidChangeGroupMaximized = Event.None + activeGroup = fakeActiveGroup + get sideGroup (): never { return unsupported() } + groups = [fakeActiveGroup] + count = 0 + orientation = GroupOrientation.HORIZONTAL + getGroups = () => [] + getGroup = () => undefined + activateGroup = unsupported + getSize = unsupported + setSize = unsupported + arrangeGroups = unsupported + toggleMaximizeGroup = unsupported + toggleExpandGroup = unsupported + applyLayout = unsupported + getLayout = unsupported + setGroupOrientation = unsupported + findGroup = () => undefined + addGroup = unsupported + removeGroup = unsupported + moveGroup = unsupported + mergeGroup = unsupported + mergeAllGroups = unsupported + copyGroup = unsupported + partOptions = DEFAULT_EDITOR_PART_OPTIONS + + onDidChangeEditorPartOptions = Event.None + createEditorDropTarget = unsupported +} + class EmptyEditorGroupsService implements IEditorGroupsService { onDidCreateAuxiliaryEditorPart = Event.None - parts = [] - get activePart () { - return unsupported() - } - get mainPart () { - return unsupported() - } + mainPart = new EmptyEditorPart() + activePart = this.mainPart + parts = [this.mainPart] getPart = unsupported createAuxiliaryEditorPart = unsupported onDidChangeGroupMaximized = Event.None toggleMaximizeGroup = unsupported toggleExpandGroup = unsupported - get partOptions () { - return unsupported() - } + partOptions = DEFAULT_EDITOR_PART_OPTIONS createEditorDropTarget = unsupported readonly _serviceBrand = undefined