From 824a3e9298e4bb73f3fe4e2fa7c6446573026050 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Tue, 3 Jul 2018 16:03:43 -0700 Subject: [PATCH] Search provider - remove absolute path checks from extHostSearch to match fileSearch.ts --- .../search-rg/src/cachedSearchProvider.ts | 4 - src/vs/workbench/api/node/extHostSearch.ts | 90 ++++++------------- 2 files changed, 26 insertions(+), 68 deletions(-) diff --git a/extensions/search-rg/src/cachedSearchProvider.ts b/extensions/search-rg/src/cachedSearchProvider.ts index a1a924d56a0..85012b70552 100644 --- a/extensions/search-rg/src/cachedSearchProvider.ts +++ b/extensions/search-rg/src/cachedSearchProvider.ts @@ -113,10 +113,6 @@ export class CachedSearchProvider { } private getResultsFromCache(cache: Cache, searchValue: string, onResult: (results: IInternalFileMatch) => void): Promise<[IInternalFileMatch[], CacheStats]> { - if (path.isAbsolute(searchValue)) { - return null; // bypass cache if user looks up an absolute path where matching goes directly on disk - } - // Find cache entries by prefix of search value const hasPathSep = searchValue.indexOf(path.sep) >= 0; let cached: CacheEntry; diff --git a/src/vs/workbench/api/node/extHostSearch.ts b/src/vs/workbench/api/node/extHostSearch.ts index 4f9c48ed0eb..7fe3e6eca15 100644 --- a/src/vs/workbench/api/node/extHostSearch.ts +++ b/src/vs/workbench/api/node/extHostSearch.ts @@ -540,52 +540,36 @@ class FileSearchEngine { }; // Support that the file pattern is a full path to a file that exists - this.checkFilePatternAbsoluteMatch().then(({ exists, size }) => { - if (this.isCanceled) { - return resolve({ isLimitHit: this.isLimitHit }); - } + if (this.isCanceled) { + return resolve({ isLimitHit: this.isLimitHit }); + } - // Report result from file pattern if matching - if (exists) { - onResult({ - base: URI.file(this.filePattern), - basename: path.basename(this.filePattern), - size + // For each extra file + if (this.config.extraFileResources) { + this.config.extraFileResources + .forEach(extraFile => { + const extraFileStr = extraFile.toString(); // ? + const basename = path.basename(extraFileStr); + if (this.globalExcludePattern && this.globalExcludePattern(extraFileStr, basename)) { + return; // excluded + } + + // File: Check for match on file pattern and include pattern + this.matchFile(onResult, { base: extraFile, basename }); }); + } - // Optimization: a match on an absolute path is a good result and we do not - // continue walking the entire root paths array for other matches because - // it is very unlikely that another file would match on the full absolute path - return resolve({ isLimitHit: this.isLimitHit }); - } - - // For each extra file - if (this.config.extraFileResources) { - this.config.extraFileResources - .forEach(extraFile => { - const extraFileStr = extraFile.toString(); // ? - const basename = path.basename(extraFileStr); - if (this.globalExcludePattern && this.globalExcludePattern(extraFileStr, basename)) { - return; // excluded - } - - // File: Check for match on file pattern and include pattern - this.matchFile(onResult, { base: extraFile, basename }); - }); - } + // For each root folder + PPromise.join(folderQueries.map(fq => { + return this.searchInFolder(fq).then(null, null, onResult); + })).then(() => { + resolve({ isLimitHit: this.isLimitHit }); + }, (errs: Error[]) => { + const errMsg = errs + .map(err => toErrorMessage(err)) + .filter(msg => !!msg)[0]; - // For each root folder - PPromise.join(folderQueries.map(fq => { - return this.searchInFolder(fq).then(null, null, onResult); - })).then(() => { - resolve({ isLimitHit: this.isLimitHit }); - }, (errs: Error[]) => { - const errMsg = errs - .map(err => toErrorMessage(err)) - .filter(msg => !!msg)[0]; - - reject(new Error(errMsg)); - }); + reject(new Error(errMsg)); }); }); } @@ -745,28 +729,6 @@ class FileSearchEngine { matchDirectory(rootEntries); } - /** - * Return whether the file pattern is an absolute path to a file that exists. - * TODO@roblou delete to match fileSearch.ts - */ - private checkFilePatternAbsoluteMatch(): TPromise<{ exists: boolean, size?: number }> { - if (!this.filePattern || !path.isAbsolute(this.filePattern)) { - return TPromise.wrap({ exists: false }); - } - - return this._pfs.stat(this.filePattern) - .then(stat => { - return { - exists: !stat.isDirectory(), - size: stat.size - }; - }, err => { - return { - exists: false - }; - }); - } - private checkFilePatternRelativeMatch(base: URI): TPromise<{ exists: boolean, size?: number }> { if (!this.filePattern || path.isAbsolute(this.filePattern) || base.scheme !== 'file') { return TPromise.wrap({ exists: false }); -- GitLab