searchQuery.ts 1.8 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

B
Benjamin Pasero 已提交
7 8
import { mixin } from 'vs/base/common/objects';
import { IPatternInfo, IQueryOptions, ISearchQuery, QueryType, ISearchConfiguration, getExcludes } from 'vs/platform/search/common/search';
J
Johannes Rieken 已提交
9
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
E
Erich Gamma 已提交
10 11 12 13 14 15

export class QueryBuilder {

	constructor( @IConfigurationService private configurationService: IConfigurationService) {
	}

B
Benjamin Pasero 已提交
16 17
	public text(contentPattern: IPatternInfo, options?: IQueryOptions): ISearchQuery {
		return this.query(QueryType.Text, contentPattern, options);
E
Erich Gamma 已提交
18 19
	}

B
Benjamin Pasero 已提交
20 21
	public file(options?: IQueryOptions): ISearchQuery {
		return this.query(QueryType.File, null, options);
E
Erich Gamma 已提交
22 23
	}

B
Benjamin Pasero 已提交
24 25
	private query(type: QueryType, contentPattern: IPatternInfo, options: IQueryOptions = {}): ISearchQuery {
		const configuration = this.configurationService.getConfiguration<ISearchConfiguration>();
E
Erich Gamma 已提交
26

B
Benjamin Pasero 已提交
27
		const excludePattern = getExcludes(configuration);
28 29 30
		if (!options.excludePattern) {
			options.excludePattern = excludePattern;
		} else {
B
Benjamin Pasero 已提交
31
			mixin(options.excludePattern, excludePattern, false /* no overwrite */);
32 33 34 35 36 37 38 39 40 41
		}

		return {
			type: type,
			folderResources: options.folderResources,
			extraFileResources: options.extraFileResources,
			filePattern: options.filePattern,
			excludePattern: options.excludePattern,
			includePattern: options.includePattern,
			maxResults: options.maxResults,
42 43
			sortByScore: options.sortByScore,
			cacheKey: options.cacheKey,
44 45 46
			fileEncoding: options.fileEncoding,
			contentPattern: contentPattern
		};
E
Erich Gamma 已提交
47 48
	}
}