Skip to content

Commit 3586808

Browse files
committed
More work strict null checking workbenchTestService
1 parent 3e24672 commit 3586808

7 files changed

Lines changed: 32 additions & 26 deletions

File tree

src/vs/workbench/browser/actions/navigationActions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ abstract class BaseNavigationAction extends Action {
7878
return Promise.resolve(false);
7979
}
8080

81-
const activeViewletId = this.viewletService.getActiveViewlet().getId();
81+
const activeViewlet = this.viewletService.getActiveViewlet();
82+
if (!activeViewlet) {
83+
return Promise.resolve(false);
84+
}
85+
const activeViewletId = activeViewlet.getId();
8286

8387
return this.viewletService.openViewlet(activeViewletId, true)
8488
.then(value => value === null ? false : value);

src/vs/workbench/browser/parts/editor/editorCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function moveActiveEditorToGroup(args: ActiveEditorMoveArguments, control: IEdit
146146
const configurationService = accessor.get(IConfigurationService);
147147

148148
const sourceGroup = control.group;
149-
let targetGroup: IEditorGroup;
149+
let targetGroup: IEditorGroup | undefined;
150150

151151
switch (args.to) {
152152
case 'left':

src/vs/workbench/parts/performance/electron-browser/startupTimings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ export class StartupTimings implements IWorkbenchContribution {
9595
this._logService.info('no standard startup: not just one window');
9696
return false;
9797
}
98-
if (!this._viewletService.getActiveViewlet() || this._viewletService.getActiveViewlet().getId() !== files.VIEWLET_ID) {
98+
const activeViewlet = this._viewletService.getActiveViewlet();
99+
if (!activeViewlet || activeViewlet.getId() !== files.VIEWLET_ID) {
99100
this._logService.info('no standard startup: not the explorer viewlet');
100101
return false;
101102
}

src/vs/workbench/services/progress/test/progressService.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class TestViewletService implements IViewletService {
5252
return 'workbench.view.explorer';
5353
}
5454

55-
public getViewlet(id: string): ViewletDescriptor {
56-
return null!;
55+
public getViewlet(id: string): ViewletDescriptor | undefined {
56+
return undefined;
5757
}
5858

5959
public getProgressIndicator(id: string) {

src/vs/workbench/services/timer/electron-browser/timerService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ class TimerService implements ITimerService {
377377
// ignore, be on the safe side with these hardware method calls
378378
}
379379

380+
const activeViewlet = this._viewletService.getActiveViewlet();
380381
return {
381382
version: 2,
382383
ellapsed: perf.getDuration(startMark, 'didStartWorkbench'),
@@ -386,7 +387,7 @@ class TimerService implements ITimerService {
386387
didUseCachedData: didUseCachedData(),
387388
windowKind: this._lifecycleService.startupKind,
388389
windowCount: await this._windowsService.getWindowCount(),
389-
viewletId: this._viewletService.getActiveViewlet() ? this._viewletService.getActiveViewlet().getId() : undefined,
390+
viewletId: activeViewlet ? activeViewlet.getId() : undefined,
390391
editorIds: this._editorService.visibleEditors.map(input => input.getTypeId()),
391392
panelId: this._panelService.getActivePanel() ? this._panelService.getActivePanel().getId() : undefined,
392393

src/vs/workbench/services/viewlet/browser/viewlet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface IViewletService {
2727
/**
2828
* Returns the current active viewlet or null if none.
2929
*/
30-
getActiveViewlet(): IViewlet;
30+
getActiveViewlet(): IViewlet | null;
3131

3232
/**
3333
* Returns the id of the default viewlet.
@@ -37,7 +37,7 @@ export interface IViewletService {
3737
/**
3838
* Returns the viewlet by id.
3939
*/
40-
getViewlet(id: string): ViewletDescriptor;
40+
getViewlet(id: string): ViewletDescriptor | undefined;
4141

4242
/**
4343
* Returns all enabled viewlets

src/vs/workbench/test/workbenchTestServices.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,15 @@ export class TestPartService implements IPartService {
471471
return false;
472472
}
473473

474-
public setEditorHidden(_hidden: boolean): Promise<void> { return Promise.resolve(null); }
474+
public setEditorHidden(_hidden: boolean): Promise<void> { return Promise.resolve(); }
475475

476-
public setSideBarHidden(_hidden: boolean): Promise<void> { return Promise.resolve(null); }
476+
public setSideBarHidden(_hidden: boolean): Promise<void> { return Promise.resolve(); }
477477

478478
public isPanelHidden(): boolean {
479479
return false;
480480
}
481481

482-
public setPanelHidden(_hidden: boolean): Promise<void> { return Promise.resolve(null); }
482+
public setPanelHidden(_hidden: boolean): Promise<void> { return Promise.resolve(); }
483483

484484
public toggleMaximizedPanel(): void { }
485485

@@ -500,7 +500,7 @@ export class TestPartService implements IPartService {
500500
}
501501

502502
public setPanelPosition(_position: PartPosition): Promise<void> {
503-
return Promise.resolve(null);
503+
return Promise.resolve();
504504
}
505505

506506
public addClass(_clazz: string): void { }
@@ -972,14 +972,14 @@ export class TestCodeEditorService implements ICodeEditorService {
972972
addDiffEditor(_editor: IDiffEditor): void { }
973973
removeDiffEditor(_editor: IDiffEditor): void { }
974974
listDiffEditors(): IDiffEditor[] { return []; }
975-
getFocusedCodeEditor(): ICodeEditor { return null; }
975+
getFocusedCodeEditor(): ICodeEditor | null { return null; }
976976
registerDecorationType(_key: string, _options: IDecorationRenderOptions, _parentTypeKey?: string): void { }
977977
removeDecorationType(_key: string): void { }
978978
resolveDecorationOptions(_typeKey: string, _writable: boolean): IModelDecorationOptions { return Object.create(null); }
979979
setTransientModelProperty(_model: ITextModel, _key: string, _value: any): void { }
980980
getTransientModelProperty(_model: ITextModel, _key: string) { }
981-
getActiveCodeEditor(): ICodeEditor { return null; }
982-
openCodeEditor(_input: IResourceInput, _source: ICodeEditor, _sideBySide?: boolean): Promise<ICodeEditor> { return Promise.resolve(undefined); }
981+
getActiveCodeEditor(): ICodeEditor | null { return null; }
982+
openCodeEditor(_input: IResourceInput, _source: ICodeEditor, _sideBySide?: boolean): Promise<ICodeEditor | null> { return Promise.resolve(null); }
983983
}
984984

985985
export class TestWindowService implements IWindowService {
@@ -1200,7 +1200,7 @@ export class TestWindowsService implements IWindowsService {
12001200
return Promise.resolve();
12011201
}
12021202

1203-
enterWorkspace(_windowId: number, _path: URI): Promise<IEnterWorkspaceResult> {
1203+
enterWorkspace(_windowId: number, _path: URI): Promise<IEnterWorkspaceResult | undefined> {
12041204
return Promise.resolve(undefined);
12051205
}
12061206

@@ -1237,7 +1237,7 @@ export class TestWindowsService implements IWindowsService {
12371237
}
12381238

12391239
isMaximized(_windowId: number): Promise<boolean> {
1240-
return Promise.resolve(undefined);
1240+
return Promise.resolve(false);
12411241
}
12421242

12431243
maximizeWindow(_windowId: number): Promise<void> {
@@ -1381,8 +1381,8 @@ export class TestTextResourceConfigurationService implements ITextResourceConfig
13811381
}
13821382

13831383
getValue<T>(resource: URI, arg2?: any, arg3?: any): T {
1384-
const position: IPosition = EditorPosition.isIPosition(arg2) ? arg2 : null;
1385-
const section: string = position ? (typeof arg3 === 'string' ? arg3 : undefined) : (typeof arg2 === 'string' ? arg2 : undefined);
1384+
const position: IPosition | null = EditorPosition.isIPosition(arg2) ? arg2 : null;
1385+
const section: string | undefined = position ? (typeof arg3 === 'string' ? arg3 : undefined) : (typeof arg2 === 'string' ? arg2 : undefined);
13861386
return this.configurationService.getValue(section, { resource });
13871387
}
13881388
}
@@ -1425,19 +1425,19 @@ export class TestViewletService implements IViewletService {
14251425
onDidViewletOpen: Event<IViewlet> = new Emitter<IViewlet>().event;
14261426
onDidViewletClose: Event<IViewlet> = new Emitter<IViewlet>().event;
14271427

1428-
openViewlet(_id: string, _focus?: boolean): Promise<IViewlet> { return null; }
1428+
openViewlet(_id: string, _focus?: boolean): Promise<IViewlet | null> { return Promise.resolve(null); }
14291429

1430-
getActiveViewlet(): IViewlet { return null; }
1430+
getActiveViewlet(): IViewlet | null { return null; }
14311431

1432-
getDefaultViewletId(): string { return null; }
1432+
getDefaultViewletId(): string { return ''; }
14331433

1434-
getViewlet(_id: string): ViewletDescriptor { return null; }
1434+
getViewlet(_id: string): ViewletDescriptor | undefined { return undefined; }
14351435

1436-
getAllViewlets(): ViewletDescriptor[] { return null; }
1436+
getAllViewlets(): ViewletDescriptor[] { return []; }
14371437

1438-
getViewlets(): ViewletDescriptor[] { return null; }
1438+
getViewlets(): ViewletDescriptor[] { return []; }
14391439

1440-
getProgressIndicator(_id: string): IProgressService { return null; }
1440+
getProgressIndicator(_id: string): IProgressService | null { return null; }
14411441

14421442
}
14431443

0 commit comments

Comments
 (0)