Skip to content

Commit c533c84

Browse files
committed
Strict null check work in webview
1 parent 5219659 commit c533c84

4 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/vs/workbench/contrib/webview/electron-browser/webviewEditorInput.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ export class WebviewEditorInput extends EditorInput {
228228
if (!this._container) {
229229
this._container = document.createElement('div');
230230
this._container.id = `webview-${this._id}`;
231-
this._partService.getContainer(Parts.EDITOR_PART).appendChild(this._container);
231+
const part = this._partService.getContainer(Parts.EDITOR_PART);
232+
if (part) {
233+
part.appendChild(this._container);
234+
}
232235
}
233236
return this._container;
234237
}

src/vs/workbench/contrib/webview/electron-browser/webviewEditorInputFactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface SerializedWebview {
1919
readonly id: number;
2020
readonly title: string;
2121
readonly options: WebviewInputOptions;
22-
readonly extensionLocation: string | UriComponents;
22+
readonly extensionLocation: string | UriComponents | undefined;
2323
readonly state: any;
2424
readonly iconPath: SerializedIconPath | undefined;
2525
}
@@ -34,7 +34,7 @@ export class WebviewEditorInputFactory implements IEditorInputFactory {
3434

3535
public serialize(
3636
input: WebviewEditorInput
37-
): string {
37+
): string | null {
3838
// Has no state, don't revive
3939
if (!input.state) {
4040
return null;

src/vs/workbench/contrib/webview/electron-browser/webviewEditorService.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface IWebviewEditorService {
3939
iconPath: { light: URI, dark: URI } | undefined,
4040
state: any,
4141
options: WebviewInputOptions,
42-
extensionLocation: URI
42+
extensionLocation: URI | undefined,
4343
): WebviewEditorInput;
4444

4545
revealWebview(
@@ -120,7 +120,7 @@ export class WebviewEditorService implements IWebviewEditorService {
120120
if (webview.group === group.id) {
121121
this._editorService.openEditor(webview, { preserveFocus }, webview.group);
122122
} else {
123-
this._editorGroupService.getGroup(webview.group).moveEditor(webview, group, { preserveFocus });
123+
this._editorGroupService.getGroup(webview.group!).moveEditor(webview, group, { preserveFocus });
124124
}
125125
}
126126

@@ -146,7 +146,7 @@ export class WebviewEditorService implements IWebviewEditorService {
146146
// A reviver may not be registered yet. Put into queue and resolve promise when we can revive
147147
let resolve: (value: void) => void;
148148
const promise = new Promise<void>(r => { resolve = r; });
149-
this._awaitingRevival.push({ input: webview, resolve });
149+
this._awaitingRevival.push({ input: webview, resolve: resolve! });
150150
return promise;
151151
});
152152
}
@@ -159,8 +159,9 @@ export class WebviewEditorService implements IWebviewEditorService {
159159
viewType: string,
160160
reviver: WebviewReviver
161161
): IDisposable {
162-
if (this._revivers.has(viewType)) {
163-
this._revivers.get(viewType).push(reviver);
162+
const currentRevivers = this._revivers.get(viewType);
163+
if (currentRevivers) {
164+
currentRevivers.push(reviver);
164165
} else {
165166
this._revivers.set(viewType, [reviver]);
166167
}
@@ -183,7 +184,8 @@ export class WebviewEditorService implements IWebviewEditorService {
183184
webview: WebviewEditorInput
184185
): boolean {
185186
const viewType = webview.viewType;
186-
return this._revivers.has(viewType) && this._revivers.get(viewType).some(reviver => reviver.canRevive(webview));
187+
const revivers = this._revivers.get(viewType);
188+
return !!revivers && revivers.some(reviver => reviver.canRevive(webview));
187189
}
188190

189191
private async tryRevive(

src/vs/workbench/contrib/webview/electron-browser/webviewElement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ export class WebviewElement extends Disposable {
370370
}
371371
}
372372

373-
this._webview = undefined;
374-
this._webviewFindWidget = undefined;
373+
this._webview = undefined!;
374+
this._webviewFindWidget = undefined!;
375375
super.dispose();
376376
}
377377

0 commit comments

Comments
 (0)