diff --git a/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts b/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts index 46ce92e8f15b78958944978751afc0ac910b76fb..464a0d8fe9994cde495806f180b0379c7570a455 100644 --- a/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts +++ b/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts @@ -14,6 +14,7 @@ import { URI } from 'vs/base/common/uri'; import { WebviewContentState } from 'vs/editor/common/modes'; import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { ILabelService } from 'vs/platform/label/common/label'; +import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle'; import { ConfirmResult, IEditorInput, Verbosity } from 'vs/workbench/common/editor'; import { WebviewEditorOverlay } from 'vs/workbench/contrib/webview/browser/webview'; import { IWebviewWorkbenchService, LazilyResolvedWebviewEditorInput } from 'vs/workbench/contrib/webview/browser/webviewWorkbenchService'; @@ -31,11 +32,12 @@ export class CustomFileEditorInput extends LazilyResolvedWebviewEditorInput { viewType: string, id: string, webview: Lazy>, + @ILifecycleService lifecycleService: ILifecycleService, @IWebviewWorkbenchService webviewWorkbenchService: IWebviewWorkbenchService, @IDialogService private readonly dialogService: IDialogService, @ILabelService private readonly labelService: ILabelService, ) { - super(id, viewType, '', webview, webviewWorkbenchService); + super(id, viewType, '', webview, webviewWorkbenchService, lifecycleService); this._editorResource = resource; } diff --git a/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts b/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts index 15ba05374e723a635e5f06c9c03b753c2704c22b..5efb65da40fc3fb8b7c919f6e0176c8194a36800 100644 --- a/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts +++ b/src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts @@ -9,6 +9,7 @@ import { Lazy } from 'vs/base/common/lazy'; import { UnownedDisposable as Unowned } from 'vs/base/common/lifecycle'; import { URI } from 'vs/base/common/uri'; import { IEditorModel } from 'vs/platform/editor/common/editor'; +import { ILifecycleService, LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; import { EditorInput, EditorModel, GroupIdentifier, IEditorInput, Verbosity } from 'vs/workbench/common/editor'; import { WebviewEditorOverlay } from 'vs/workbench/contrib/webview/browser/webview'; @@ -17,6 +18,7 @@ const WebviewPanelResourceScheme = 'webview-panel'; class WebviewIconsManager { private readonly _icons = new Map(); + @memoize private get _styleElement(): HTMLStyleElement { const element = dom.createStyleSheet(); @@ -26,7 +28,8 @@ class WebviewIconsManager { public setIcons( webviewId: string, - iconPath: { light: URI, dark: URI } | undefined + iconPath: { light: URI, dark: URI } | undefined, + lifecycleService: ILifecycleService, ) { if (iconPath) { this._icons.set(webviewId, iconPath); @@ -34,10 +37,11 @@ class WebviewIconsManager { this._icons.delete(webviewId); } - this.updateStyleSheet(); + this.updateStyleSheet(lifecycleService); } - private updateStyleSheet() { + private async updateStyleSheet(lifecycleService: ILifecycleService, ) { + await lifecycleService.when(LifecyclePhase.Starting); const cssRules: string[] = []; this._icons.forEach((value, key) => { const webviewSelector = `.show-file-icons .webview-${key}-name-file-icon::before`; @@ -67,7 +71,8 @@ export class WebviewInput extends EditorInput { public readonly id: string, public readonly viewType: string, name: string, - webview: Lazy> + webview: Lazy>, + @ILifecycleService private readonly lifecycleService: ILifecycleService, ) { super(); @@ -118,7 +123,7 @@ export class WebviewInput extends EditorInput { public set iconPath(value: { light: URI, dark: URI } | undefined) { this._iconPath = value; - WebviewInput.iconsManager.setIcons(this.id, value); + WebviewInput.iconsManager.setIcons(this.id, value, this.lifecycleService); } public matches(other: IEditorInput): boolean { diff --git a/src/vs/workbench/contrib/webview/browser/webviewWorkbenchService.ts b/src/vs/workbench/contrib/webview/browser/webviewWorkbenchService.ts index 0c7be3410384a3510f43b6f96229ebb3ad1147ac..ee635fbe60a3b9dd93c4cc1d00e9e79377ffbc11 100644 --- a/src/vs/workbench/contrib/webview/browser/webviewWorkbenchService.ts +++ b/src/vs/workbench/contrib/webview/browser/webviewWorkbenchService.ts @@ -5,19 +5,20 @@ import { equals } from 'vs/base/common/arrays'; import { memoize } from 'vs/base/common/decorators'; +import { Lazy } from 'vs/base/common/lazy'; import { IDisposable, toDisposable, UnownedDisposable } from 'vs/base/common/lifecycle'; import { values } from 'vs/base/common/map'; import { isEqual } from 'vs/base/common/resources'; import { URI } from 'vs/base/common/uri'; import { EditorActivation, IEditorModel } from 'vs/platform/editor/common/editor'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; -import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle'; import { GroupIdentifier } from 'vs/workbench/common/editor'; -import { IWebviewService, WebviewContentOptions, WebviewEditorOverlay, WebviewOptions, WebviewExtensionDescription } from 'vs/workbench/contrib/webview/browser/webview'; +import { IWebviewService, WebviewContentOptions, WebviewEditorOverlay, WebviewExtensionDescription, WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview'; import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { ACTIVE_GROUP_TYPE, IEditorService, SIDE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService'; import { WebviewInput } from './webviewEditorInput'; -import { Lazy } from 'vs/base/common/lazy'; export const IWebviewWorkbenchService = createDecorator('webviewEditorService'); @@ -109,8 +110,9 @@ export class LazilyResolvedWebviewEditorInput extends WebviewInput { name: string, webview: Lazy>, @IWebviewWorkbenchService private readonly _webviewWorkbenchService: IWebviewWorkbenchService, + @ILifecycleService lifeCycleService: ILifecycleService, ) { - super(id, viewType, name, webview); + super(id, viewType, name, webview, lifeCycleService); } @memoize @@ -145,8 +147,9 @@ export class WebviewEditorService implements IWebviewWorkbenchService { private readonly _revivalPool = new RevivalPool(); constructor( - @IEditorService private readonly _editorService: IEditorService, @IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService, + @IEditorService private readonly _editorService: IEditorService, + @IInstantiationService private readonly _instantiationService: IInstantiationService, @IWebviewService private readonly _webviewService: IWebviewService, ) { } @@ -159,7 +162,7 @@ export class WebviewEditorService implements IWebviewWorkbenchService { extension: WebviewExtensionDescription | undefined, ): WebviewInput { const webview = new Lazy(() => new UnownedDisposable(this.createWebiew(id, extension, options))); - const webviewInput = new WebviewInput(id, viewType, title, webview); + const webviewInput = this._instantiationService.createInstance(WebviewInput, id, viewType, title, webview); this._editorService.openEditor(webviewInput, { pinned: true, preserveFocus: showOptions.preserveFocus, @@ -206,7 +209,7 @@ export class WebviewEditorService implements IWebviewWorkbenchService { return new UnownedDisposable(webview); }); - const webviewInput = new LazilyResolvedWebviewEditorInput(id, viewType, title, webview, this); + const webviewInput = this._instantiationService.createInstance(LazilyResolvedWebviewEditorInput, id, viewType, title, webview); webviewInput.iconPath = iconPath; if (typeof group === 'number') {