Skip to content

Commit 2fc4843

Browse files
committed
Strict null check for simpleServices
1 parent 44bf931 commit 2fc4843

7 files changed

Lines changed: 47 additions & 38 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@
352352
"./vs/editor/standalone/browser/colorizer.ts",
353353
"./vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.ts",
354354
"./vs/editor/standalone/browser/inspectTokens/inspectTokens.ts",
355+
"./vs/editor/standalone/browser/simpleServices.ts",
355356
"./vs/editor/standalone/browser/standaloneCodeServiceImpl.ts",
356357
"./vs/editor/standalone/browser/standaloneThemeServiceImpl.ts",
357358
"./vs/editor/standalone/browser/toggleHighContrast/toggleHighContrast.ts",

src/vs/base/common/labels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { isLinux, isWindows, isMacintosh } from 'vs/base/common/platform';
1111
import { isEqual } from 'vs/base/common/resources';
1212

1313
export interface IWorkspaceFolderProvider {
14-
getWorkspaceFolder(resource: URI): { uri: URI, name?: string };
14+
getWorkspaceFolder(resource: URI): { uri: URI, name?: string } | null;
1515
getWorkspace(): {
1616
folders: { uri: URI, name?: string }[];
1717
};

src/vs/editor/standalone/browser/simpleServices.ts

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,13 @@ export class SimpleEditorModelResolverService implements ITextModelService {
9898
}
9999

100100
public createModelReference(resource: URI): Promise<IReference<ITextEditorModel>> {
101-
let model: ITextModel;
102-
103-
model = withTypedEditor(this.editor,
101+
let model: ITextModel | null = withTypedEditor(this.editor,
104102
(editor) => this.findModel(editor, resource),
105103
(diffEditor) => this.findModel(diffEditor.getOriginalEditor(), resource) || this.findModel(diffEditor.getModifiedEditor(), resource)
106104
);
107105

108106
if (!model) {
109-
return Promise.resolve(new ImmortalReference(null));
107+
return Promise.reject(new Error(`Model not found`));
110108
}
111109

112110
return Promise.resolve(new ImmortalReference(new SimpleModel(model)));
@@ -144,7 +142,7 @@ export class SimpleProgressService implements IProgressService {
144142
}
145143

146144
showWhile(promise: Thenable<any>, delay?: number): Thenable<void> {
147-
return null;
145+
return Promise.resolve(void 0);
148146
}
149147
}
150148

@@ -277,11 +275,16 @@ export class StandaloneKeybindingService extends AbstractKeybindingService {
277275
}));
278276
}
279277

280-
public addDynamicKeybinding(commandId: string, keybinding: number, handler: ICommandHandler, when: ContextKeyExpr | null): IDisposable {
278+
public addDynamicKeybinding(commandId: string, _keybinding: number, handler: ICommandHandler, when: ContextKeyExpr | null): IDisposable {
279+
const keybinding = createKeybinding(_keybinding, OS);
280+
if (!keybinding) {
281+
throw new Error(`Invalid keybinding`);
282+
}
283+
281284
let toDispose: IDisposable[] = [];
282285

283286
this._dynamicKeybindings.push({
284-
keybinding: createKeybinding(keybinding, OS),
287+
keybinding: keybinding,
285288
command: commandId,
286289
when: when,
287290
weight1: 1000,
@@ -426,10 +429,10 @@ export class SimpleConfigurationService implements IConfigurationService {
426429
}
427430

428431
public reloadConfiguration(): Promise<void> {
429-
return Promise.resolve(null);
432+
return Promise.resolve(void 0);
430433
}
431434

432-
public getConfigurationData(): IConfigurationData {
435+
public getConfigurationData(): IConfigurationData | null {
433436
return null;
434437
}
435438
}
@@ -450,8 +453,11 @@ export class SimpleResourceConfigurationService implements ITextResourceConfigur
450453
getValue<T>(resource: URI, section?: string): T;
451454
getValue<T>(resource: URI, position?: IPosition, section?: string): T;
452455
getValue<T>(resource: any, arg2?: any, arg3?: any) {
453-
const position: IPosition = Pos.isIPosition(arg2) ? arg2 : null;
454-
const section: string = position ? (typeof arg3 === 'string' ? arg3 : void 0) : (typeof arg2 === 'string' ? arg2 : void 0);
456+
const position: IPosition | null = Pos.isIPosition(arg2) ? arg2 : null;
457+
const section: string | undefined = position ? (typeof arg3 === 'string' ? arg3 : void 0) : (typeof arg2 === 'string' ? arg2 : void 0);
458+
if (typeof section === 'undefined') {
459+
return this.configurationService.getValue<T>();
460+
}
455461
return this.configurationService.getValue<T>(section);
456462
}
457463
}
@@ -482,11 +488,11 @@ export class StandaloneTelemetryService implements ITelemetryService {
482488
public isOptedIn = false;
483489

484490
public publicLog(eventName: string, data?: any): Promise<void> {
485-
return Promise.resolve(null);
491+
return Promise.resolve(void 0);
486492
}
487493

488494
public getTelemetryInfo(): Promise<ITelemetryInfo> {
489-
return null;
495+
throw new Error(`Not available`);
490496
}
491497
}
492498

@@ -526,8 +532,8 @@ export class SimpleWorkspaceContextService implements IWorkspaceContextService {
526532
return WorkbenchState.EMPTY;
527533
}
528534

529-
public getWorkspaceFolder(resource: URI): IWorkspaceFolder {
530-
return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME ? this.workspace.folders[0] : void 0;
535+
public getWorkspaceFolder(resource: URI): IWorkspaceFolder | null {
536+
return resource && resource.scheme === SimpleWorkspaceContextService.SCHEME ? this.workspace.folders[0] : null;
531537
}
532538

533539
public isInsideWorkspace(resource: URI): boolean {
@@ -567,19 +573,21 @@ export class SimpleBulkEditService implements IBulkEditService {
567573

568574
let edits = new Map<ITextModel, TextEdit[]>();
569575

570-
for (let edit of workspaceEdit.edits) {
571-
if (!isResourceTextEdit(edit)) {
572-
return Promise.reject(new Error('bad edit - only text edits are supported'));
573-
}
574-
let model = this._modelService.getModel(edit.resource);
575-
if (!model) {
576-
return Promise.reject(new Error('bad edit - model not found'));
577-
}
578-
let array = edits.get(model);
579-
if (!array) {
580-
array = [];
576+
if (workspaceEdit.edits) {
577+
for (let edit of workspaceEdit.edits) {
578+
if (!isResourceTextEdit(edit)) {
579+
return Promise.reject(new Error('bad edit - only text edits are supported'));
580+
}
581+
let model = this._modelService.getModel(edit.resource);
582+
if (!model) {
583+
return Promise.reject(new Error('bad edit - model not found'));
584+
}
585+
let array = edits.get(model);
586+
if (!array) {
587+
array = [];
588+
}
589+
edits.set(model, array.concat(edit.edits));
581590
}
582-
edits.set(model, array.concat(edit.edits));
583591
}
584592

585593
let totalEdits = 0;

src/vs/platform/configuration/common/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface IConfigurationService {
6363

6464
onDidChangeConfiguration: Event<IConfigurationChangeEvent>;
6565

66-
getConfigurationData(): IConfigurationData;
66+
getConfigurationData(): IConfigurationData | null;
6767

6868
/**
6969
* Fetches the value of the section for the given overrides.

src/vs/platform/configuration/common/configurationModels.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class ConfigurationModel implements IConfigurationModel {
3636
return this.checkAndFreeze(this._keys);
3737
}
3838

39-
getValue<V>(section: string): V {
39+
getValue<V>(section: string | undefined): V {
4040
return section ? getConfigurationValue<any>(this.contents, section) : this.contents;
4141
}
4242

@@ -289,7 +289,7 @@ export class Configuration {
289289
private _freeze: boolean = true) {
290290
}
291291

292-
getValue(section: string, overrides: IConfigurationOverrides, workspace: Workspace): any {
292+
getValue(section: string | undefined, overrides: IConfigurationOverrides, workspace: Workspace | null): any {
293293
const consolidateConfigurationModel = this.getConsolidateConfigurationModel(overrides, workspace);
294294
return consolidateConfigurationModel.getValue(section);
295295
}
@@ -317,7 +317,7 @@ export class Configuration {
317317
}
318318
}
319319

320-
inspect<C>(key: string, overrides: IConfigurationOverrides, workspace: Workspace): {
320+
inspect<C>(key: string, overrides: IConfigurationOverrides, workspace: Workspace | null): {
321321
default: C,
322322
user: C,
323323
workspace?: C,
@@ -338,7 +338,7 @@ export class Configuration {
338338
};
339339
}
340340

341-
keys(workspace: Workspace): {
341+
keys(workspace: Workspace | null): {
342342
default: string[];
343343
user: string[];
344344
workspace: string[];
@@ -397,12 +397,12 @@ export class Configuration {
397397
return this._folderConfigurations;
398398
}
399399

400-
private getConsolidateConfigurationModel(overrides: IConfigurationOverrides, workspace: Workspace): ConfigurationModel {
400+
private getConsolidateConfigurationModel(overrides: IConfigurationOverrides, workspace: Workspace | null): ConfigurationModel {
401401
let configurationModel = this.getConsolidatedConfigurationModelForResource(overrides, workspace);
402402
return overrides.overrideIdentifier ? configurationModel.override(overrides.overrideIdentifier) : configurationModel;
403403
}
404404

405-
private getConsolidatedConfigurationModelForResource({ resource }: IConfigurationOverrides, workspace: Workspace): ConfigurationModel {
405+
private getConsolidatedConfigurationModelForResource({ resource }: IConfigurationOverrides, workspace: Workspace | null): ConfigurationModel {
406406
let consolidateConfiguration = this.getWorkspaceConsolidatedConfiguration();
407407

408408
if (workspace && resource) {
@@ -447,7 +447,7 @@ export class Configuration {
447447
return folderConsolidatedConfiguration;
448448
}
449449

450-
private getFolderConfigurationModelForResource(resource: URI | undefined, workspace: Workspace): ConfigurationModel | null {
450+
private getFolderConfigurationModelForResource(resource: URI | undefined, workspace: Workspace | null): ConfigurationModel | null {
451451
if (workspace && resource) {
452452
const root = workspace.getFolder(resource);
453453
if (root) {

src/vs/platform/workspace/common/workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface IWorkspaceContextService {
6363
* Returns the folder for the given resource from the workspace.
6464
* Can be null if there is no workspace or the resource is not inside the workspace.
6565
*/
66-
getWorkspaceFolder(resource: URI): IWorkspaceFolder;
66+
getWorkspaceFolder(resource: URI): IWorkspaceFolder | null;
6767

6868
/**
6969
* Return `true` if the current workspace has the given identifier otherwise `false`.

src/vs/workbench/parts/search/common/queryBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ export class QueryBuilder {
334334

335335
private getFolderQueryForSearchPath(searchPath: ISearchPathPattern, options: ICommonQueryBuilderOptions): IFolderQuery {
336336
const searchPathWorkspaceFolder = this.workspaceContextService.getWorkspaceFolder(searchPath.searchPath);
337-
const searchPathRelativePath = searchPathWorkspaceFolder && searchPath.searchPath.path.substr(searchPathWorkspaceFolder.uri.path.length + 1);
338337

339338
const rootConfig = this.getFolderQueryForRoot(searchPath.searchPath, options);
340339
let resolvedExcludes: glob.IExpression = {};
341340
if (searchPathWorkspaceFolder && rootConfig.excludePattern) {
341+
const searchPathRelativePath = searchPath.searchPath.path.substr(searchPathWorkspaceFolder.uri.path.length + 1);
342342
// Resolve excludes relative to the search path
343343
for (let excludePattern in rootConfig.excludePattern) {
344344
const { pathPortion, globPortion } = splitSimpleGlob(excludePattern);

0 commit comments

Comments
 (0)