From a322986bb566818b8b0be344b14814722fbaf869 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Fri, 14 Jul 2017 17:45:23 -0700 Subject: [PATCH] Get rid of searchPaths - cleanup for #27226 --- src/vs/platform/search/common/search.ts | 5 ++--- .../parts/search/common/searchQuery.ts | 15 +++++++------ .../services/search/node/ripgrepTextSearch.ts | 22 +++++++++---------- .../workbench/services/search/node/search.ts | 1 - .../services/search/node/searchService.ts | 3 +-- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/vs/platform/search/common/search.ts b/src/vs/platform/search/common/search.ts index 959bbfdbfd615..47c462577af96 100644 --- a/src/vs/platform/search/common/search.ts +++ b/src/vs/platform/search/common/search.ts @@ -26,7 +26,7 @@ export interface ISearchService { clearCache(cacheKey: string): TPromise; } -export interface IFolderQueryOptions { +export interface IFolderQuery { folder: uri; excludePattern?: IExpression; fileEncoding?: string; @@ -54,9 +54,8 @@ export interface ISearchQuery extends ICommonQueryOptions { excludePattern?: IExpression; includePattern?: IExpression; - searchPaths?: string[]; contentPattern?: IPatternInfo; - folderQueries?: IFolderQueryOptions[]; + folderQueries?: IFolderQuery[]; } export enum QueryType { diff --git a/src/vs/workbench/parts/search/common/searchQuery.ts b/src/vs/workbench/parts/search/common/searchQuery.ts index 364cbab9ec71d..b0a4ce06a508f 100644 --- a/src/vs/workbench/parts/search/common/searchQuery.ts +++ b/src/vs/workbench/parts/search/common/searchQuery.ts @@ -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 { @@ -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(undefined, { resource: folder }); - return { + return { folder, excludePattern: this.getExcludesForFolder(folderConfig, options), fileEncoding: folderConfig.files.encoding @@ -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 { @@ -61,8 +63,7 @@ export class QueryBuilder { contentPattern: contentPattern, useRipgrep, disregardIgnoreFiles: options.disregardIgnoreFiles, - disregardExcludeSettings: options.disregardExcludeSettings, - searchPaths + disregardExcludeSettings: options.disregardExcludeSettings }; } diff --git a/src/vs/workbench/services/search/node/ripgrepTextSearch.ts b/src/vs/workbench/services/search/node/ripgrepTextSearch.ts index 3f77a89338bb6..5502ae43f766c 100644 --- a/src/vs/workbench/services/search/node/ripgrepTextSearch.ts +++ b/src/vs/workbench/services/search/node/ripgrepTextSearch.ts @@ -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')) { @@ -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 }; diff --git a/src/vs/workbench/services/search/node/search.ts b/src/vs/workbench/services/search/node/search.ts index 4e949b425bcb3..ea94c3f843919 100644 --- a/src/vs/workbench/services/search/node/search.ts +++ b/src/vs/workbench/services/search/node/search.ts @@ -28,7 +28,6 @@ export interface IRawSearch { maxFilesize?: number; useRipgrep?: boolean; disregardIgnoreFiles?: boolean; - searchPaths?: string[]; } export interface IRawSearchService { diff --git a/src/vs/workbench/services/search/node/searchService.ts b/src/vs/workbench/services/search/node/searchService.ts index 7a3ce403a8695..7bd74b745fec8 100644 --- a/src/vs/workbench/services/search/node/searchService.ts +++ b/src/vs/workbench/services/search/node/searchService.ts @@ -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) {