提交 e30008eb 编写于 作者: M Matt Bierner

Leave determining which webviews a reviver supports entirely up to that reviver

Don't  key off of `viewType` first, let the reviver decide
上级 f62d1f25
...@@ -62,7 +62,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv ...@@ -62,7 +62,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
_editorService.onDidActiveEditorChange(this.onActiveEditorChanged, this, this._toDispose); _editorService.onDidActiveEditorChange(this.onActiveEditorChanged, this, this._toDispose);
_editorService.onDidVisibleEditorsChange(this.onVisibleEditorsChanged, this, this._toDispose); _editorService.onDidVisibleEditorsChange(this.onVisibleEditorsChanged, this, this._toDispose);
this._toDispose.push(_webviewService.registerReviver(MainThreadWebviews.viewType, this)); this._toDispose.push(_webviewService.registerReviver(this));
lifecycleService.onBeforeShutdown(e => { lifecycleService.onBeforeShutdown(e => {
e.veto(this._onBeforeShutdown()); e.veto(this._onBeforeShutdown());
...@@ -242,7 +242,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv ...@@ -242,7 +242,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
} }
public canRevive(webview: WebviewEditorInput): boolean { public canRevive(webview: WebviewEditorInput): boolean {
if (webview.isDisposed() || !webview.state) { if (webview.isDisposed() || !webview.state || webview.viewType !== MainThreadWebviews.viewType) {
return false; return false;
} }
......
...@@ -49,7 +49,6 @@ export interface IWebviewEditorService { ...@@ -49,7 +49,6 @@ export interface IWebviewEditorService {
): void; ): void;
registerReviver( registerReviver(
viewType: string,
reviver: WebviewReviver reviver: WebviewReviver
): IDisposable; ): IDisposable;
...@@ -90,7 +89,7 @@ export function areWebviewInputOptionsEqual(a: WebviewInputOptions, b: WebviewIn ...@@ -90,7 +89,7 @@ export function areWebviewInputOptionsEqual(a: WebviewInputOptions, b: WebviewIn
export class WebviewEditorService implements IWebviewEditorService { export class WebviewEditorService implements IWebviewEditorService {
_serviceBrand: any; _serviceBrand: any;
private readonly _revivers = new Map<string, WebviewReviver[]>(); private readonly _revivers = new Set<WebviewReviver>();
private _awaitingRevival: { input: WebviewEditorInput, resolve: (x: any) => void }[] = []; private _awaitingRevival: { input: WebviewEditorInput, resolve: (x: any) => void }[] = [];
constructor( constructor(
...@@ -135,7 +134,7 @@ export class WebviewEditorService implements IWebviewEditorService { ...@@ -135,7 +134,7 @@ export class WebviewEditorService implements IWebviewEditorService {
): WebviewEditorInput { ): WebviewEditorInput {
const webviewInput = this._instantiationService.createInstance(WebviewEditorInput, viewType, id, title, options, state, {}, extensionLocation, { const webviewInput = this._instantiationService.createInstance(WebviewEditorInput, viewType, id, title, options, state, {}, extensionLocation, {
canRevive: (_webview) => { canRevive: (_webview) => {
return true; return _webview === webviewInput;
}, },
reviveWebview: (webview: WebviewEditorInput): Promise<void> => { reviveWebview: (webview: WebviewEditorInput): Promise<void> => {
return this.tryRevive(webview).then(didRevive => { return this.tryRevive(webview).then(didRevive => {
...@@ -156,47 +155,38 @@ export class WebviewEditorService implements IWebviewEditorService { ...@@ -156,47 +155,38 @@ export class WebviewEditorService implements IWebviewEditorService {
} }
registerReviver( registerReviver(
viewType: string,
reviver: WebviewReviver reviver: WebviewReviver
): IDisposable { ): IDisposable {
const currentRevivers = this._revivers.get(viewType); this._revivers.add(reviver);
if (currentRevivers) {
currentRevivers.push(reviver);
} else {
this._revivers.set(viewType, [reviver]);
}
// Resolve any pending views // Resolve any pending views
const toRevive = this._awaitingRevival.filter(x => x.input.viewType === viewType); const toRevive = this._awaitingRevival.filter(x => reviver.canRevive(x.input));
this._awaitingRevival = this._awaitingRevival.filter(x => x.input.viewType !== viewType); this._awaitingRevival = this._awaitingRevival.filter(x => !reviver.canRevive(x.input));
for (const input of toRevive) { for (const input of toRevive) {
reviver.reviveWebview(input.input).then(() => input.resolve(undefined)); reviver.reviveWebview(input.input).then(() => input.resolve(undefined));
} }
return toDisposable(() => { return toDisposable(() => {
this._revivers.delete(viewType); this._revivers.delete(reviver);
}); });
} }
canRevive( canRevive(
webview: WebviewEditorInput webview: WebviewEditorInput
): boolean { ): boolean {
const viewType = webview.viewType; for (const reviver of this._revivers) {
const revivers = this._revivers.get(viewType); if (reviver.canRevive(webview)) {
return !!revivers && revivers.some(reviver => reviver.canRevive(webview)); return true;
}
}
return false;
} }
private async tryRevive( private async tryRevive(
webview: WebviewEditorInput webview: WebviewEditorInput
): Promise<boolean> { ): Promise<boolean> {
const revivers = this._revivers.get(webview.viewType); for (const reviver of this._revivers) {
if (!revivers) {
return false;
}
for (const reviver of revivers) {
if (reviver.canRevive(webview)) { if (reviver.canRevive(webview)) {
await reviver.reviveWebview(webview); await reviver.reviveWebview(webview);
return true; return true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册