Skip to content

Commit 4ef037d

Browse files
committed
Strict null checks
1 parent d98b92f commit 4ef037d

8 files changed

Lines changed: 24 additions & 20 deletions

File tree

src/tsconfig.strictNullChecks.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@
624624
"./vs/workbench/parts/welcome/walkThrough/node/walkThroughUtils.ts",
625625
"./vs/workbench/services/activity/common/activity.ts",
626626
"./vs/workbench/services/backup/common/backup.ts",
627+
"./vs/workbench/services/backup/node/backupFileService.ts",
627628
"./vs/workbench/services/commands/common/commandService.ts",
628629
"./vs/workbench/services/configuration/common/configuration.ts",
629630
"./vs/workbench/services/configuration/common/configurationExtensionPoint.ts",
@@ -665,19 +666,22 @@
665666
"./vs/workbench/services/notification/common/notificationService.ts",
666667
"./vs/workbench/services/panel/common/panelService.ts",
667668
"./vs/workbench/services/part/common/partService.ts",
669+
"./vs/workbench/services/remote/electron-browser/remoteAgentServiceImpl.ts",
668670
"./vs/workbench/services/remote/node/remoteAgentEnvironmentChannel.ts",
669671
"./vs/workbench/services/remote/node/remoteAgentService.ts",
670672
"./vs/workbench/services/scm/common/scm.ts",
671673
"./vs/workbench/services/scm/common/scmService.ts",
672674
"./vs/workbench/services/search/common/searchHelpers.ts",
673675
"./vs/workbench/services/search/node/fileSearchManager.ts",
674676
"./vs/workbench/services/search/node/legacy/search.ts",
677+
"./vs/workbench/services/search/node/ripgrepFileSearch.ts",
675678
"./vs/workbench/services/search/node/ripgrepSearchProvider.ts",
676679
"./vs/workbench/services/search/node/ripgrepSearchUtils.ts",
677680
"./vs/workbench/services/search/node/ripgrepTextSearchEngine.ts",
678681
"./vs/workbench/services/search/node/search.ts",
679682
"./vs/workbench/services/search/node/searchHistoryService.ts",
680683
"./vs/workbench/services/search/node/searchIpc.ts",
684+
"./vs/workbench/services/search/node/textSearchAdapter.ts",
681685
"./vs/workbench/services/search/node/textSearchManager.ts",
682686
"./vs/workbench/services/search/test/node/ripgrepTextSearchEngine.test.ts",
683687
"./vs/workbench/services/search/test/node/textSearchManager.test.ts",

src/vs/workbench/services/backup/common/backup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface IBackupFileService {
3131
* @param resource The resource that is backed up.
3232
* @return The backup resource if any.
3333
*/
34-
loadBackupResource(resource: Uri): TPromise<Uri>;
34+
loadBackupResource(resource: Uri): TPromise<Uri | undefined>;
3535

3636
/**
3737
* Given a resource, returns the associated backup resource.
@@ -63,7 +63,7 @@ export interface IBackupFileService {
6363
* @param value The contents from a backup resource as stream.
6464
* @return The backup file's backed up content as text buffer factory.
6565
*/
66-
resolveBackupContent(backup: Uri): TPromise<ITextBufferFactory>;
66+
resolveBackupContent(backup: Uri): TPromise<ITextBufferFactory | undefined>;
6767

6868
/**
6969
* Discards the backup associated with a resource if it exists..

src/vs/workbench/services/backup/node/backupFileService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class BackupSnapshot implements ITextSnapshot {
3232

3333
constructor(private snapshot: ITextSnapshot, private preamble: string) { }
3434

35-
read(): string {
35+
read(): string | null {
3636
let value = this.snapshot.read();
3737
if (!this.preambleHandled) {
3838
this.preambleHandled = true;
@@ -145,7 +145,7 @@ export class BackupFileService implements IBackupFileService {
145145
});
146146
}
147147

148-
loadBackupResource(resource: Uri): TPromise<Uri> {
148+
loadBackupResource(resource: Uri): TPromise<Uri | undefined> {
149149
return this.ready.then(model => {
150150

151151
// Return directly if we have a known backup with that resource
@@ -252,7 +252,7 @@ export class InMemoryBackupFileService implements IBackupFileService {
252252
return TPromise.as(this.backups.size > 0);
253253
}
254254

255-
loadBackupResource(resource: Uri): TPromise<Uri> {
255+
loadBackupResource(resource: Uri): TPromise<Uri | undefined> {
256256
const backupResource = this.toBackupResource(resource);
257257
if (this.backups.has(backupResource.toString())) {
258258
return TPromise.as(backupResource);
@@ -268,7 +268,7 @@ export class InMemoryBackupFileService implements IBackupFileService {
268268
return TPromise.as(void 0);
269269
}
270270

271-
resolveBackupContent(backupResource: Uri): TPromise<ITextBufferFactory> {
271+
resolveBackupContent(backupResource: Uri): TPromise<ITextBufferFactory | undefined> {
272272
const snapshot = this.backups.get(backupResource.toString());
273273
if (snapshot) {
274274
return TPromise.as(createTextBufferFactoryFromSnapshot(snapshot));

src/vs/workbench/services/remote/electron-browser/remoteAgentServiceImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class RemoteAgentConnection extends Disposable implements IRemoteAgentConnection
4242

4343
readonly remoteAuthority: string;
4444
private _connection: TPromise<Client> | null;
45-
private _environment: TPromise<IRemoteAgentEnvironment> | null;
45+
private _environment: TPromise<IRemoteAgentEnvironment | null> | null;
4646

4747
constructor(
4848
remoteAuthority: string,
@@ -56,7 +56,7 @@ class RemoteAgentConnection extends Disposable implements IRemoteAgentConnection
5656
this._environment = null;
5757
}
5858

59-
getEnvironment(): TPromise<IRemoteAgentEnvironment> {
59+
getEnvironment(): TPromise<IRemoteAgentEnvironment | null> {
6060
if (!this._environment) {
6161
const client = new RemoteExtensionEnvironmentChannelClient(this.getChannel('remoteextensionsenvironment'));
6262

src/vs/workbench/services/remote/node/remoteAgentService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface IRemoteAgentService {
3434
export interface IRemoteAgentConnection {
3535
readonly remoteAuthority: string;
3636

37-
getEnvironment(): TPromise<IRemoteAgentEnvironment>;
37+
getEnvironment(): TPromise<IRemoteAgentEnvironment | null>;
3838

3939
getChannel<T extends IChannel>(channelName: string): T;
4040
registerChannel<T extends IChannel>(channelName: string, channel: T);

src/vs/workbench/services/search/node/ripgrepFileSearch.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function getRgArgs(config: IFileQuery, folderQuery: IFolderQuery, includePattern
4444
}
4545
});
4646

47-
let siblingClauses: glob.IExpression;
47+
let siblingClauses: glob.IExpression | null;
4848

4949
const rgGlobs = foldersToRgExcludeGlobs([folderQuery], excludePattern, undefined, false);
5050
rgGlobs.globArgs.forEach(globArg => {
@@ -85,15 +85,15 @@ function getRgArgs(config: IFileQuery, folderQuery: IFolderQuery, includePattern
8585

8686
export interface IRgGlobResult {
8787
globArgs: string[];
88-
siblingClauses: glob.IExpression;
88+
siblingClauses: glob.IExpression | null;
8989
}
9090

9191
export function foldersToRgExcludeGlobs(folderQueries: IFolderQuery[], globalExclude: glob.IExpression, excludesToSkip?: Set<string>, absoluteGlobs = true): IRgGlobResult {
9292
const globArgs: string[] = [];
9393
let siblingClauses: glob.IExpression = {};
9494
folderQueries.forEach(folderQuery => {
9595
const totalExcludePattern = objects.assign({}, folderQuery.excludePattern || {}, globalExclude || {});
96-
const result = globExprsToRgGlobs(totalExcludePattern, absoluteGlobs && folderQuery.folder.fsPath, excludesToSkip);
96+
const result = globExprsToRgGlobs(totalExcludePattern, absoluteGlobs ? folderQuery.folder.fsPath : undefined, excludesToSkip);
9797
globArgs.push(...result.globArgs);
9898
if (result.siblingClauses) {
9999
siblingClauses = objects.assign(siblingClauses, result.siblingClauses);
@@ -107,7 +107,7 @@ export function foldersToIncludeGlobs(folderQueries: IFolderQuery[], globalInclu
107107
const globArgs: string[] = [];
108108
folderQueries.forEach(folderQuery => {
109109
const totalIncludePattern = objects.assign({}, globalInclude || {}, folderQuery.includePattern || {});
110-
const result = globExprsToRgGlobs(totalIncludePattern, absoluteGlobs && folderQuery.folder.fsPath);
110+
const result = globExprsToRgGlobs(totalIncludePattern, absoluteGlobs ? folderQuery.folder.fsPath : undefined);
111111
globArgs.push(...result.globArgs);
112112
});
113113

@@ -116,7 +116,7 @@ export function foldersToIncludeGlobs(folderQueries: IFolderQuery[], globalInclu
116116

117117
function globExprsToRgGlobs(patterns: glob.IExpression, folder?: string, excludesToSkip?: Set<string>): IRgGlobResult {
118118
const globArgs: string[] = [];
119-
let siblingClauses: glob.IExpression = null;
119+
let siblingClauses: glob.IExpression | null = null;
120120
Object.keys(patterns)
121121
.forEach(key => {
122122
if (excludesToSkip && excludesToSkip.has(key)) {

src/vs/workbench/services/search/node/search.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface ISearchEngine<T> {
3434
export interface ISerializedSearchSuccess {
3535
type: 'success';
3636
limitHit: boolean;
37-
stats: IFileSearchStats | ITextSearchStats;
37+
stats: IFileSearchStats | ITextSearchStats | null;
3838
}
3939

4040
export interface ISearchEngineSuccess {
@@ -71,7 +71,7 @@ export function isSerializedFileMatch(arg: ISerializedSearchProgressItem): arg i
7171
}
7272

7373
export interface ISerializedFileMatch {
74-
path: string;
74+
path?: string;
7575
results?: ITextSearchResult[];
7676
numMatches?: number;
7777
}

src/vs/workbench/services/search/node/textSearchAdapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class TextSearchEngineAdapter {
1616
}
1717

1818
search(token: CancellationToken, onResult: (matches: ISerializedFileMatch[]) => void, onMessage: (message: IProgress) => void): Promise<ISerializedSearchSuccess> {
19-
if (!this.query.folderQueries.length && !this.query.extraFileResources.length) {
19+
if ((!this.query.folderQueries || !this.query.folderQueries.length) && (!this.query.extraFileResources || !this.query.extraFileResources.length)) {
2020
return Promise.resolve(<ISerializedSearchSuccess>{
2121
type: 'success',
2222
limitHit: false,
@@ -40,17 +40,17 @@ export class TextSearchEngineAdapter {
4040
},
4141
token)
4242
.then(
43-
c => resolve({ limitHit: c.limitHit, stats: null, type: 'success' }),
43+
c => resolve({ limitHit: c.limitHit, stats: null, type: 'success' } as ISerializedSearchSuccess),
4444
reject);
4545
});
4646
}
4747
}
4848

4949
function fileMatchToSerialized(match: IFileMatch): ISerializedFileMatch {
5050
return {
51-
path: match.resource.fsPath,
51+
path: match.resource ? match.resource.fsPath : undefined,
5252
results: match.results,
53-
numMatches: match.results.reduce((sum, r) => {
53+
numMatches: (match.results || []).reduce((sum, r) => {
5454
if (!!(<ITextSearchMatch>r).ranges) {
5555
const m = <ITextSearchMatch>r;
5656
return sum + (Array.isArray(m.ranges) ? m.ranges.length : 1);

0 commit comments

Comments
 (0)