提交 824a3e92 编写于 作者: R Rob Lourens

Search provider - remove absolute path checks from extHostSearch to match fileSearch.ts

上级 fdf27274
...@@ -113,10 +113,6 @@ export class CachedSearchProvider { ...@@ -113,10 +113,6 @@ export class CachedSearchProvider {
} }
private getResultsFromCache(cache: Cache, searchValue: string, onResult: (results: IInternalFileMatch) => void): Promise<[IInternalFileMatch[], CacheStats]> { 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 // Find cache entries by prefix of search value
const hasPathSep = searchValue.indexOf(path.sep) >= 0; const hasPathSep = searchValue.indexOf(path.sep) >= 0;
let cached: CacheEntry<IInternalFileMatch>; let cached: CacheEntry<IInternalFileMatch>;
......
...@@ -540,52 +540,36 @@ class FileSearchEngine { ...@@ -540,52 +540,36 @@ class FileSearchEngine {
}; };
// Support that the file pattern is a full path to a file that exists // Support that the file pattern is a full path to a file that exists
this.checkFilePatternAbsoluteMatch().then(({ exists, size }) => { if (this.isCanceled) {
if (this.isCanceled) { return resolve({ isLimitHit: this.isLimitHit });
return resolve({ isLimitHit: this.isLimitHit }); }
}
// Report result from file pattern if matching // For each extra file
if (exists) { if (this.config.extraFileResources) {
onResult({ this.config.extraFileResources
base: URI.file(this.filePattern), .forEach(extraFile => {
basename: path.basename(this.filePattern), const extraFileStr = extraFile.toString(); // ?
size 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 // For each root folder
// continue walking the entire root paths array for other matches because PPromise.join(folderQueries.map(fq => {
// it is very unlikely that another file would match on the full absolute path return this.searchInFolder(fq).then(null, null, onResult);
return resolve({ isLimitHit: this.isLimitHit }); })).then(() => {
} resolve({ isLimitHit: this.isLimitHit });
}, (errs: Error[]) => {
// For each extra file const errMsg = errs
if (this.config.extraFileResources) { .map(err => toErrorMessage(err))
this.config.extraFileResources .filter(msg => !!msg)[0];
.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 reject(new Error(errMsg));
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));
});
}); });
}); });
} }
...@@ -745,28 +729,6 @@ class FileSearchEngine { ...@@ -745,28 +729,6 @@ class FileSearchEngine {
matchDirectory(rootEntries); 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 }> { private checkFilePatternRelativeMatch(base: URI): TPromise<{ exists: boolean, size?: number }> {
if (!this.filePattern || path.isAbsolute(this.filePattern) || base.scheme !== 'file') { if (!this.filePattern || path.isAbsolute(this.filePattern) || base.scheme !== 'file') {
return TPromise.wrap({ exists: false }); return TPromise.wrap({ exists: false });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册