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

import {PPromise} from 'vs/base/common/winjs.base';
import uri from 'vs/base/common/uri';
import glob = require('vs/base/common/glob');
import {IFilesConfiguration} from 'vs/platform/files/common/files';
11
import {createDecorator} from 'vs/platform/instantiation/common/instantiation';
E
Erich Gamma 已提交
12

B
Benjamin Pasero 已提交
13
export const ID = 'searchService';
E
Erich Gamma 已提交
14

B
Benjamin Pasero 已提交
15
export const ISearchService = createDecorator<ISearchService>(ID);
E
Erich Gamma 已提交
16 17 18 19
/**
 * A service that enables to search for files or with in files.
 */
export interface ISearchService {
20
	_serviceBrand: any;
E
Erich Gamma 已提交
21 22 23 24
	search(query: ISearchQuery): PPromise<ISearchComplete, ISearchProgressItem>;
}

export interface IQueryOptions {
25
	folderResources?: uri[];
26
	extraFileResources?: uri[];
27
	filePattern?: string;
E
Erich Gamma 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
	excludePattern?: glob.IExpression;
	includePattern?: glob.IExpression;
	maxResults?: number;
	fileEncoding?: string;
}

export interface ISearchQuery extends IQueryOptions {
	type: QueryType;
	contentPattern?: IPatternInfo;
}

export enum QueryType {
	File = 1,
	Text = 2
}

export interface IPatternInfo {
	pattern: string;
	isRegExp?: boolean;
	isWordMatch?: boolean;
	isCaseSensitive?: boolean;
}

export interface IFileMatch {
	resource?: uri;
	lineMatches?: ILineMatch[];
}

export interface ILineMatch {
	preview: string;
	lineNumber: number;
	offsetAndLengths: number[][];
}

export interface IProgress {
	total?: number;
	worked?: number;
}

export interface ISearchProgressItem extends IFileMatch, IProgress {
	// Marker interface to indicate the possible values for progress calls from the engine
}

export interface ISearchComplete {
	limitHit?: boolean;
	results: IFileMatch[];
C
chrmarti 已提交
74 75 76 77 78 79 80 81
	stats: ISearchStats;
}

export interface ISearchStats {
	fileWalkStartTime: number;
	fileWalkResultTime: number;
	directoriesWalked: number;
	filesWalked: number;
E
Erich Gamma 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
}


// ---- very simple implementation of the search model --------------------

export class FileMatch implements IFileMatch {
	public lineMatches: LineMatch[] = [];
	constructor(public resource: uri) {
		// empty
	}
}

export class LineMatch implements ILineMatch {
	constructor(public preview: string, public lineNumber: number, public offsetAndLengths: number[][]) {
		// empty
	}
}

export interface ISearchConfiguration extends IFilesConfiguration {
	search: {
		exclude: glob.IExpression;
B
Benjamin Pasero 已提交
103
	};
E
Erich Gamma 已提交
104
}