Skip to content

Commit

Permalink
Fix #65933
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Jan 3, 2019
1 parent 8700c2e commit 7805023
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/tsconfig.strictNullChecks.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@
"./vs/vscode.d.ts",
"./vs/vscode.proposed.d.ts",
"./vs/workbench/api/node/extHostExtensionActivator.ts",
"./vs/workbench/api/node/extHostSearch.fileIndex.ts",
"./vs/workbench/api/node/extHostTypes.ts",
"./vs/workbench/api/shared/editor.ts",
"./vs/workbench/api/shared/tasks.ts",
Expand Down
52 changes: 26 additions & 26 deletions src/vs/workbench/api/node/extHostSearch.fileIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ interface IInternalSearchComplete<T = IFileSearchStats> {
}

export class FileIndexSearchEngine {
private filePattern: string;
private filePattern?: string;
private normalizedFilePatternLowercase: string;
private includePattern: glob.ParsedExpression;
private maxResults: number;
private includePattern?: glob.ParsedExpression;
private maxResults: number | null;
private exists: boolean;
private isLimitHit: boolean;
private resultCount: number;
Expand All @@ -40,13 +40,13 @@ export class FileIndexSearchEngine {

private activeCancellationTokens: Set<CancellationTokenSource>;

private globalExcludePattern: glob.ParsedExpression;
private globalExcludePattern?: glob.ParsedExpression;

constructor(private config: IFileQuery, private provider: vscode.FileIndexProvider) {
this.filePattern = config.filePattern;
this.includePattern = config.includePattern && glob.parse(config.includePattern);
this.maxResults = config.maxResults || null;
this.exists = config.exists;
this.exists = !!config.exists;
this.resultCount = 0;
this.isLimitHit = false;
this.activeCancellationTokens = new Set<CancellationTokenSource>();
Expand Down Expand Up @@ -159,7 +159,7 @@ export class FileIndexSearchEngine {
return null;
}

results.forEach(onProviderResult);
results!.forEach(onProviderResult);

this.matchDirectoryTree(tree, queryTester, onResult);
fileWalkTime = postProcessSW.elapsed();
Expand Down Expand Up @@ -268,7 +268,7 @@ export class FileIndexSearchEngine {
}

private matchFile(onResult: (result: IInternalFileMatch) => void, candidate: IInternalFileMatch): void {
if (this.isFilePatternMatch(candidate.relativePath) && (!this.includePattern || this.includePattern(candidate.relativePath, candidate.basename))) {
if (this.isFilePatternMatch(candidate.relativePath!) && (!this.includePattern || this.includePattern(candidate.relativePath!, candidate.basename))) {
if (this.exists || (this.maxResults && this.resultCount >= this.maxResults)) {
this.isLimitHit = true;
this.cancel();
Expand Down Expand Up @@ -314,7 +314,7 @@ export class FileIndexSearchManager {
} :
config;

const engine = new FileIndexSearchEngine(engineConfig, provider);
const engine = new FileIndexSearchEngine(<any>engineConfig, provider);
sortedSearch = this.doSortedSearch(engine, config, token);
}

Expand Down Expand Up @@ -343,18 +343,18 @@ export class FileIndexSearchManager {
private getFolderCacheKey(config: IFileQuery): string {
const uri = config.folderQueries[0].folder.toString();
const folderCacheKey = config.cacheKey && `${uri}_${config.cacheKey}`;
if (!this.folderCacheKeys.get(config.cacheKey)) {
this.folderCacheKeys.set(config.cacheKey, new Set());
if (!this.folderCacheKeys.get(config.cacheKey!)) {
this.folderCacheKeys.set(config.cacheKey!, new Set());
}

this.folderCacheKeys.get(config.cacheKey).add(folderCacheKey);
this.folderCacheKeys.get(config.cacheKey!).add(folderCacheKey!);

return folderCacheKey;
return folderCacheKey!;
}

private rawMatchToSearchItem(match: IInternalFileMatch): IFileMatch {
return {
resource: match.original || resources.joinPath(match.base, match.relativePath)
resource: match.original || resources.joinPath(match.base, match.relativePath!)
};
}

Expand All @@ -371,11 +371,11 @@ export class FileIndexSearchManager {
promise: allResultsPromise,
resolved: false
};
cache.resultsToSearchCache[config.filePattern] = cacheRow;
cache.resultsToSearchCache[config.filePattern!] = cacheRow;
allResultsPromise.then(() => {
cacheRow.resolved = true;
}, err => {
delete cache.resultsToSearchCache[config.filePattern];
delete cache.resultsToSearchCache[config.filePattern!];
});
allResultsPromise = this.preventCancellation(allResultsPromise);
}
Expand Down Expand Up @@ -412,14 +412,14 @@ export class FileIndexSearchManager {
return this.caches[cacheKey] = new Cache();
}

private trySortedSearchFromCache(config: IFileQuery, token: CancellationToken): Promise<IInternalSearchComplete> {
private trySortedSearchFromCache(config: IFileQuery, token: CancellationToken): Promise<IInternalSearchComplete> | undefined {
const folderCacheKey = this.getFolderCacheKey(config);
const cache = folderCacheKey && this.caches[folderCacheKey];
if (!cache) {
return undefined;
}

const cached = this.getResultsFromCache(cache, config.filePattern, token);
const cached = this.getResultsFromCache(cache, config.filePattern!, token);
if (cached) {
return cached.then(complete => {
const sortSW = StopWatch.create();
Expand Down Expand Up @@ -451,10 +451,10 @@ export class FileIndexSearchManager {
// this is very important because we are also limiting the number of results by config.maxResults
// and as such we want the top items to be included in this result set if the number of items
// exceeds config.maxResults.
const query = prepareQuery(config.filePattern);
const query = prepareQuery(config.filePattern!);
const compare = (matchA: IInternalFileMatch, matchB: IInternalFileMatch) => compareItemsByScore(matchA, matchB, query, true, FileMatchItemAccessor, scorerCache);

return arrays.topAsync(results, compare, config.maxResults, 10000, token);
return arrays.topAsync(results, compare, config.maxResults!, 10000, token);
}

private sendAsBatches(rawMatches: IInternalFileMatch[], onBatch: (batch: IFileMatch[]) => void, batchSize: number) {
Expand All @@ -468,7 +468,7 @@ export class FileIndexSearchManager {
}
}

private getResultsFromCache(cache: Cache, searchValue: string, token: CancellationToken): Promise<IInternalSearchComplete<ICachedSearchStats>> {
private getResultsFromCache(cache: Cache, searchValue: string, token: CancellationToken): Promise<IInternalSearchComplete<ICachedSearchStats>> | null {
const cacheLookupSW = StopWatch.create();

if (path.isAbsolute(searchValue)) {
Expand All @@ -477,7 +477,7 @@ export class FileIndexSearchManager {

// Find cache entries by prefix of search value
const hasPathSep = searchValue.indexOf(path.sep) >= 0;
let cacheRow: ICacheRow;
let cacheRow: ICacheRow | undefined;
for (let previousSearch in cache.resultsToSearchCache) {

// If we narrow down, we might be able to reuse the cached results
Expand Down Expand Up @@ -505,7 +505,7 @@ export class FileIndexSearchManager {
return new Promise<IInternalSearchComplete<ICachedSearchStats>>((c, e) => {
token.onCancellationRequested(() => e(canceled()));

cacheRow.promise.then(complete => {
cacheRow!.promise.then(complete => {
if (token && token.isCancellationRequested) {
e(canceled());
}
Expand All @@ -517,7 +517,7 @@ export class FileIndexSearchManager {
let entry = complete.results[i];

// Check if this entry is a match for the search value
if (!strings.fuzzyContains(entry.relativePath, normalizedSearchValueLowercase)) {
if (!strings.fuzzyContains(entry.relativePath!, normalizedSearchValueLowercase)) {
continue;
}

Expand All @@ -528,7 +528,7 @@ export class FileIndexSearchManager {
limitHit: complete.limitHit,
results,
stats: {
cacheWasResolved: cacheRow.resolved,
cacheWasResolved: cacheRow!.resolved,
cacheLookupTime,
cacheFilterTime: cacheFilterSW.elapsed(),
cacheEntryCount: complete.results.length
Expand Down Expand Up @@ -599,10 +599,10 @@ const FileMatchItemAccessor = new class implements IItemAccessor<IInternalFileMa
}

public getItemDescription(match: IInternalFileMatch): string {
return match.relativePath.substr(0, match.relativePath.length - match.basename.length - 1); // e.g. some/path/to/file
return match.relativePath!.substr(0, match.relativePath!.length - match.basename.length - 1); // e.g. some/path/to/file
}

public getItemPath(match: IInternalFileMatch): string {
return match.relativePath; // e.g. some/path/to/file/myFile.txt
return match.relativePath!; // e.g. some/path/to/file/myFile.txt
}
};

0 comments on commit 7805023

Please sign in to comment.