Skip to content

Commit

Permalink
Get rid of searchPaths - cleanup for #27226
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Jul 17, 2017
1 parent a8cc22b commit a322986
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
5 changes: 2 additions & 3 deletions src/vs/platform/search/common/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ISearchService {
clearCache(cacheKey: string): TPromise<void>;
}

export interface IFolderQueryOptions {
export interface IFolderQuery {
folder: uri;
excludePattern?: IExpression;
fileEncoding?: string;
Expand Down Expand Up @@ -54,9 +54,8 @@ export interface ISearchQuery extends ICommonQueryOptions {

excludePattern?: IExpression;
includePattern?: IExpression;
searchPaths?: string[];
contentPattern?: IPatternInfo;
folderQueries?: IFolderQueryOptions[];
folderQueries?: IFolderQuery[];
}

export enum QueryType {
Expand Down
15 changes: 8 additions & 7 deletions src/vs/workbench/parts/search/common/searchQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as paths from 'vs/base/common/paths';
import * as strings from 'vs/base/common/strings';
import uri from 'vs/base/common/uri';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IPatternInfo, IQueryOptions, IFolderQueryOptions, ISearchQuery, QueryType, ISearchConfiguration, getExcludes } from 'vs/platform/search/common/search';
import { IPatternInfo, IQueryOptions, IFolderQuery, ISearchQuery, QueryType, ISearchConfiguration, getExcludes } from 'vs/platform/search/common/search';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';

export class QueryBuilder {
Expand All @@ -30,9 +30,13 @@ export class QueryBuilder {
}

private query(type: QueryType, contentPattern: IPatternInfo, folderResources?: uri[], options: IQueryOptions = {}): ISearchQuery {
const folderQueries = folderResources && folderResources.map(folder => {
const { searchPaths, includePattern } = this.getSearchPaths(options.includePattern);

// Build folderQueries from searchPaths, if given, otherwise folderResources
const folderQueryUris = searchPaths.length ? searchPaths.map(searchPath => uri.parse(searchPath)) : folderResources;
const folderQueries = folderQueryUris && folderQueryUris.map(folder => {
const folderConfig = this.configurationService.getConfiguration<ISearchConfiguration>(undefined, { resource: folder });
return <IFolderQueryOptions>{
return <IFolderQuery>{
folder,
excludePattern: this.getExcludesForFolder(folderConfig, options),
fileEncoding: folderConfig.files.encoding
Expand All @@ -44,8 +48,6 @@ export class QueryBuilder {
return folderConfig.search.useRipgrep;
});

const { searchPaths, includePattern } = this.getSearchPaths(options.includePattern);

const excludePattern = patternListToIExpression(splitGlobPattern(options.excludePattern));

return {
Expand All @@ -61,8 +63,7 @@ export class QueryBuilder {
contentPattern: contentPattern,
useRipgrep,
disregardIgnoreFiles: options.disregardIgnoreFiles,
disregardExcludeSettings: options.disregardExcludeSettings,
searchPaths
disregardExcludeSettings: options.disregardExcludeSettings
};
}

Expand Down
22 changes: 10 additions & 12 deletions src/vs/workbench/services/search/node/ripgrepTextSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,21 @@ export class RipgrepEngine {
*/
private rgErrorMsgForDisplay(msg: string): string | undefined {
const firstLine = msg.split('\n')[0];
if (firstLine.match(/^No files were searched, which means ripgrep/)) {
// Not really a useful message to show in the UI
return undefined;
}

// The error "No such file or directory" is returned for broken symlinks and also for bad search paths.
// Only show it if it's from a search path.
const reg = /^(\.\/.*): No such file or directory \(os error 2\)/;
const reg = /^\.\/(.*): No such file or directory \(os error 2\)/;
const noSuchFileMatch = firstLine.match(reg);
if (noSuchFileMatch) {
const errorPath = noSuchFileMatch[1];
return this.config.searchPaths && this.config.searchPaths.indexOf(errorPath) >= 0 ? firstLine : undefined;
const matchingPathSegmentReg = new RegExp('[\\/]' + errorPath);
const matchesFolderQuery = this.config.folderQueries
.map(q => q.folder)
.some(folder => !!folder.match(matchingPathSegmentReg));

return matchesFolderQuery ?
firstLine :
undefined;
}

if (strings.startsWith(firstLine, 'Error parsing regex')) {
Expand Down Expand Up @@ -507,12 +510,7 @@ function getRgArgs(config: IRawSearch): IRgGlobResult {
args.push(searchPatternAfterDoubleDashes);
}

if (config.searchPaths && config.searchPaths.length) {
args.push(...config.searchPaths);
} else {
args.push(...config.folderQueries.map(q => q.folder));
}

args.push(...config.folderQueries.map(q => q.folder));
args.push(...config.extraFiles);

return { globArgs: args, siblingClauses };
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/services/search/node/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export interface IRawSearch {
maxFilesize?: number;
useRipgrep?: boolean;
disregardIgnoreFiles?: boolean;
searchPaths?: string[];
}

export interface IRawSearchService {
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/services/search/node/searchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ export class DiskSearch {
sortByScore: query.sortByScore,
cacheKey: query.cacheKey,
useRipgrep: query.useRipgrep,
disregardIgnoreFiles: query.disregardIgnoreFiles,
searchPaths: query.searchPaths
disregardIgnoreFiles: query.disregardIgnoreFiles
};

if (query.type === QueryType.Text) {
Expand Down

0 comments on commit a322986

Please sign in to comment.