search.contribution.ts 23.0 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------------------------
 *  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 'vs/css!./media/search.contribution';
9
import { Registry } from 'vs/platform/registry/common/platform';
S
Sandeep Somavarapu 已提交
10
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
11
import { ViewletRegistry, Extensions as ViewletExtensions, ViewletDescriptor } from 'vs/workbench/browser/viewlet';
S
Sandeep Somavarapu 已提交
12
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
E
Erich Gamma 已提交
13
import nls = require('vs/nls');
14
import { TPromise } from 'vs/base/common/winjs.base';
I
isidor 已提交
15
import { Action } from 'vs/base/common/actions';
R
Rob Lourens 已提交
16
import * as objects from 'vs/base/common/objects';
17
import * as platform from 'vs/base/common/platform';
I
isidor 已提交
18
import { ExplorerFolderContext, ExplorerRootContext } from 'vs/workbench/parts/files/common/files';
I
isidor 已提交
19
import { SyncActionDescriptor, MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
B
Benjamin Pasero 已提交
20
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
O
Oleg Mihailik 已提交
21
import { QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions as QuickOpenExtensions } from 'vs/workbench/browser/quickopen';
J
Johannes Rieken 已提交
22 23
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
J
Johannes Rieken 已提交
24
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
25
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
26
import { getSelectionSearchString } from 'vs/editor/contrib/find/findController';
B
Benjamin Pasero 已提交
27
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
J
Johannes Rieken 已提交
28
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
S
Sandeep Somavarapu 已提交
29
import { ITree } from 'vs/base/parts/tree/browser/tree';
30
import * as Constants from 'vs/workbench/parts/search/common/constants';
31 32
import { registerContributions as replaceContributions } from 'vs/workbench/parts/search/browser/replaceContributions';
import { registerContributions as searchWidgetContributions } from 'vs/workbench/parts/search/browser/searchWidget';
33
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
34
import { ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding, ShowPreviousFindTermKeybinding, ShowNextFindTermKeybinding } from 'vs/editor/contrib/find/findModel';
S
Sandeep Somavarapu 已提交
35
import { ISearchWorkbenchService, SearchWorkbenchService } from 'vs/workbench/parts/search/common/searchModel';
36
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
I
isidor 已提交
37
import { SearchView } from 'vs/workbench/parts/search/browser/searchView';
B
Benjamin Pasero 已提交
38
import { defaultQuickOpenContextKey } from 'vs/workbench/browser/parts/quickopen/quickopen';
39 40
import { OpenSymbolHandler } from 'vs/workbench/parts/search/browser/openSymbolHandler';
import { OpenAnythingHandler } from 'vs/workbench/parts/search/browser/openAnythingHandler';
41
import { registerLanguageCommand } from 'vs/editor/browser/editorExtensions';
42
import { getWorkspaceSymbols } from 'vs/workbench/parts/search/common/search';
I
isidor 已提交
43
import { illegalArgument } from 'vs/base/common/errors';
I
isidor 已提交
44 45 46 47 48
import { WorkbenchListFocusContextKey, IListService } from 'vs/platform/list/browser/listService';
import URI from 'vs/base/common/uri';
import { relative } from 'path';
import { dirname } from 'vs/base/common/resources';
import { ResourceContextKey } from 'vs/workbench/common/resources';
I
isidor 已提交
49 50
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IFileService } from 'vs/platform/files/common/files';
51
import { distinct } from 'vs/base/common/arrays';
52
import { getMultiSelectedResources } from 'vs/workbench/parts/files/browser/files';
53
import { Schemas } from 'vs/base/common/network';
I
isidor 已提交
54
import { PanelRegistry, Extensions as PanelExtensions, PanelDescriptor } from 'vs/workbench/browser/panel';
55
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
56
import { openSearchView, getSearchView, ReplaceAllInFolderAction, ReplaceAllAction, CloseReplaceAction, FocusNextInputAction, FocusPreviousInputAction, FocusNextSearchResultAction, FocusPreviousSearchResultAction, ReplaceInFilesAction, FindInFilesAction, FocusActiveEditorCommand, toggleCaseSensitiveCommand, ShowNextSearchTermAction, ShowPreviousSearchTermAction, toggleRegexCommand, ShowNextSearchExcludeAction, ShowPreviousSearchIncludeAction, ShowNextSearchIncludeAction, ShowPreviousSearchExcludeAction, CollapseDeepestExpandedLevelAction, toggleWholeWordCommand, RemoveAction, ReplaceAction } from 'vs/workbench/parts/search/browser/searchActions';
57
import { VIEW_ID } from 'vs/platform/search/common/search';
58 59 60
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { SearchViewLocationUpdater } from 'vs/workbench/parts/search/browser/searchViewLocationUpdater';
61

S
Sandeep Somavarapu 已提交
62
registerSingleton(ISearchWorkbenchService, SearchWorkbenchService);
63 64
replaceContributions();
searchWidgetContributions();
E
Erich Gamma 已提交
65

A
Alex Dima 已提交
66
KeybindingsRegistry.registerCommandAndKeybindingRule({
E
Erich Gamma 已提交
67 68
	id: 'workbench.action.search.toggleQueryDetails',
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
69
	when: Constants.SearchViewVisibleKey,
E
Erich Gamma 已提交
70
	primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_J,
71
	handler: accessor => {
72 73
		openSearchView(accessor.get(IViewletService), accessor.get(IPanelService), true)
			.then(view => view.toggleQueryDetails());
E
Erich Gamma 已提交
74 75 76
	}
});

S
Sandeep Somavarapu 已提交
77 78 79
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.FocusSearchFromResults,
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
80
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.FirstMatchFocusKey),
S
Sandeep Somavarapu 已提交
81 82
	primary: KeyCode.UpArrow,
	handler: (accessor, args: any) => {
83
		const searchView = getSearchView(accessor.get(IViewletService), accessor.get(IPanelService));
84
		searchView.focusPreviousInputBox();
S
Sandeep Somavarapu 已提交
85 86 87 88 89 90
	}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.OpenMatchToSide,
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
91
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.FileMatchOrMatchFocusKey),
S
Sandeep Somavarapu 已提交
92 93 94 95 96
	primary: KeyMod.CtrlCmd | KeyCode.Enter,
	mac: {
		primary: KeyMod.WinCtrl | KeyCode.Enter
	},
	handler: (accessor, args: any) => {
97
		const searchView = getSearchView(accessor.get(IViewletService), accessor.get(IPanelService));
98 99
		const tree: ITree = searchView.getControl();
		searchView.open(tree.getFocus(), false, true, true);
S
Sandeep Somavarapu 已提交
100 101 102 103 104 105
	}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.CancelActionId,
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
106
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, WorkbenchListFocusContextKey),
S
Sandeep Somavarapu 已提交
107 108
	primary: KeyCode.Escape,
	handler: (accessor, args: any) => {
109
		const searchView = getSearchView(accessor.get(IViewletService), accessor.get(IPanelService));
110
		searchView.cancelSearch();
S
Sandeep Somavarapu 已提交
111 112 113 114 115 116
	}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.RemoveActionId,
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
117
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.FileMatchOrMatchFocusKey),
S
Sandeep Somavarapu 已提交
118 119 120 121 122
	primary: KeyCode.Delete,
	mac: {
		primary: KeyMod.CtrlCmd | KeyCode.Backspace,
	},
	handler: (accessor, args: any) => {
123
		const searchView = getSearchView(accessor.get(IViewletService), accessor.get(IPanelService));
124
		const tree: ITree = searchView.getControl();
125
		accessor.get(IInstantiationService).createInstance(RemoveAction, tree, tree.getFocus(), searchView).run();
S
Sandeep Somavarapu 已提交
126 127 128 129 130 131
	}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.ReplaceActionId,
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
132
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.ReplaceActiveKey, Constants.MatchFocusKey),
S
Sandeep Somavarapu 已提交
133 134
	primary: KeyMod.Shift | KeyMod.CtrlCmd | KeyCode.KEY_1,
	handler: (accessor, args: any) => {
135
		const searchView = getSearchView(accessor.get(IViewletService), accessor.get(IPanelService));
136
		const tree: ITree = searchView.getControl();
137
		accessor.get(IInstantiationService).createInstance(ReplaceAction, tree, tree.getFocus(), searchView).run();
S
Sandeep Somavarapu 已提交
138 139 140 141 142 143
	}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.ReplaceAllInFileActionId,
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
144
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.ReplaceActiveKey, Constants.FileFocusKey),
S
Sandeep Somavarapu 已提交
145 146
	primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.Enter,
	handler: (accessor, args: any) => {
147
		const searchView = getSearchView(accessor.get(IViewletService), accessor.get(IPanelService));
148
		const tree: ITree = searchView.getControl();
149
		accessor.get(IInstantiationService).createInstance(ReplaceAllAction, tree, tree.getFocus(), searchView).run();
S
Sandeep Somavarapu 已提交
150 151 152
	}
});

153 154 155
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.ReplaceAllInFolderActionId,
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
156
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.ReplaceActiveKey, Constants.FolderFocusKey),
157 158
	primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.Enter,
	handler: (accessor, args: any) => {
159
		const searchView = getSearchView(accessor.get(IViewletService), accessor.get(IPanelService));
160
		const tree: ITree = searchView.getControl();
161
		accessor.get(IInstantiationService).createInstance(ReplaceAllInFolderAction, tree, tree.getFocus()).run();
162 163 164
	}
});

S
Sandeep Somavarapu 已提交
165 166 167
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.CloseReplaceWidgetActionId,
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
168
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.ReplaceInputBoxFocusedKey),
S
Sandeep Somavarapu 已提交
169 170
	primary: KeyCode.Escape,
	handler: (accessor, args: any) => {
171
		accessor.get(IInstantiationService).createInstance(CloseReplaceAction, Constants.CloseReplaceWidgetActionId, '').run();
S
Sandeep Somavarapu 已提交
172 173 174 175
	}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
176
	id: FocusNextInputAction.ID,
S
Sandeep Somavarapu 已提交
177
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
178
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.InputBoxFocusedKey),
S
Sandeep Somavarapu 已提交
179 180
	primary: KeyCode.DownArrow,
	handler: (accessor, args: any) => {
181
		accessor.get(IInstantiationService).createInstance(FocusNextInputAction, FocusNextInputAction.ID, '').run();
S
Sandeep Somavarapu 已提交
182 183 184 185
	}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
186
	id: FocusPreviousInputAction.ID,
S
Sandeep Somavarapu 已提交
187
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
188
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.InputBoxFocusedKey, Constants.SearchInputBoxFocusedKey.toNegated()),
S
Sandeep Somavarapu 已提交
189 190
	primary: KeyCode.UpArrow,
	handler: (accessor, args: any) => {
191
		accessor.get(IInstantiationService).createInstance(FocusPreviousInputAction, FocusPreviousInputAction.ID, '').run();
S
Sandeep Somavarapu 已提交
192 193 194
	}
});

I
isidor 已提交
195 196 197 198 199 200
const FIND_IN_FOLDER_ID = 'filesExplorer.findInFolder';
CommandsRegistry.registerCommand({
	id: FIND_IN_FOLDER_ID,
	handler: (accessor, resource?: URI) => {
		const listService = accessor.get(IListService);
		const viewletService = accessor.get(IViewletService);
201
		const panelService = accessor.get(IPanelService);
I
isidor 已提交
202
		const fileService = accessor.get(IFileService);
203
		const resources = getMultiSelectedResources(resource, listService, accessor.get(IWorkbenchEditorService));
I
isidor 已提交
204

205
		return openSearchView(viewletService, panelService, true).then(searchView => {
206 207 208 209 210 211 212 213 214 215
			if (resources && resources.length) {
				return fileService.resolveFiles(resources.map(resource => ({ resource }))).then(results => {
					const folders: URI[] = [];

					results.forEach(result => {
						if (result.success) {
							folders.push(result.stat.isDirectory ? result.stat.resource : dirname(result.stat.resource));
						}
					});

216
					searchView.searchInFolders(distinct(folders, folder => folder.toString()), (from, to) => relative(from, to));
217
				});
218
			}
219 220

			return void 0;
I
isidor 已提交
221
		});
I
isidor 已提交
222 223
	}
});
E
Erich Gamma 已提交
224

I
isidor 已提交
225 226 227
const FIND_IN_WORKSPACE_ID = 'filesExplorer.findInWorkspace';
CommandsRegistry.registerCommand({
	id: FIND_IN_WORKSPACE_ID,
I
isidor 已提交
228
	handler: (accessor) => {
229 230
		return openSearchView(accessor.get(IViewletService), accessor.get(IPanelService), true).then(searchView => {
			searchView.searchInFolders(null, (from, to) => relative(from, to));
I
isidor 已提交
231 232 233
		});
	}
});
E
Erich Gamma 已提交
234

I
isidor 已提交
235
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
236 237
	group: '4_search',
	order: 10,
I
isidor 已提交
238 239 240 241
	command: {
		id: FIND_IN_FOLDER_ID,
		title: nls.localize('findInFolder', "Find in Folder...")
	},
242
	when: ContextKeyExpr.and(ExplorerFolderContext, ResourceContextKey.Scheme.isEqualTo(Schemas.file)) // todo@remote
I
isidor 已提交
243
});
E
Erich Gamma 已提交
244

I
isidor 已提交
245
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
246 247
	group: '4_search',
	order: 10,
I
isidor 已提交
248 249 250 251 252 253
	command: {
		id: FIND_IN_WORKSPACE_ID,
		title: nls.localize('findInWorkspace', "Find in Workspace...")
	},
	when: ContextKeyExpr.and(ExplorerRootContext, ExplorerFolderContext.toNegated())
});
E
Erich Gamma 已提交
254 255


256
class ShowAllSymbolsAction extends Action {
257 258 259
	static readonly ID = 'workbench.action.showAllSymbols';
	static readonly LABEL = nls.localize('showTriggerActions', "Go to Symbol in Workspace...");
	static readonly ALL_SYMBOLS_PREFIX = '#';
E
Erich Gamma 已提交
260

261 262 263 264 265 266 267 268 269 270
	constructor(
		actionId: string, actionLabel: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
		@ICodeEditorService private editorService: ICodeEditorService) {
		super(actionId, actionLabel);
		this.enabled = !!this.quickOpenService;
	}

	public run(context?: any): TPromise<void> {

271
		let prefix = ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX;
272
		let inputSelection: { start: number; end: number; } = void 0;
273 274
		let editor = this.editorService.getFocusedCodeEditor();
		const word = editor && getSelectionSearchString(editor);
275 276 277 278
		if (word) {
			prefix = prefix + word;
			inputSelection = { start: 1, end: word.length + 1 };
		}
E
Erich Gamma 已提交
279

280 281 282
		this.quickOpenService.show(prefix, { inputSelection });

		return TPromise.as(null);
E
Erich Gamma 已提交
283 284 285
	}
}

286
// Register View in Viewlet and Panel area
287 288
Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets).registerViewlet(new ViewletDescriptor(
	SearchView,
289
	VIEW_ID,
290 291 292 293
	nls.localize('name', "Search"),
	'search',
	10
));
I
isidor 已提交
294 295

Registry.as<PanelRegistry>(PanelExtensions.Panels).registerPanel(new PanelDescriptor(
296
	SearchView,
297
	VIEW_ID,
E
Erich Gamma 已提交
298 299 300 301 302
	nls.localize('name', "Search"),
	'search',
	10
));

303 304 305
// Register view location updater
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(SearchViewLocationUpdater, LifecyclePhase.Running);

S
Sandeep Somavarapu 已提交
306
// Actions
B
Benjamin Pasero 已提交
307
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
B
Benjamin Pasero 已提交
308
const category = nls.localize('search', "Search");
E
Erich Gamma 已提交
309

I
isidor 已提交
310 311
registry.registerWorkbenchAction(new SyncActionDescriptor(FindInFilesAction, VIEW_ID, nls.localize('showSearchViewl', "Show Search"), { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F },
	Constants.SearchViewVisibleKey.toNegated()), 'View: Show Search', nls.localize('view', "View"));
312
registry.registerWorkbenchAction(new SyncActionDescriptor(FindInFilesAction, Constants.FindInFilesActionId, nls.localize('findInFiles', "Find in Files"), { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F },
R
Rob Lourens 已提交
313
	Constants.SearchInputBoxFocusedKey.toNegated()), 'Find in Files', category);
S
Sandeep Somavarapu 已提交
314

315 316 317
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.FocusActiveEditorCommandId,
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
318
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.SearchInputBoxFocusedKey),
319
	handler: FocusActiveEditorCommand,
320 321 322
	primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F
});

323 324
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusNextSearchResultAction, FocusNextSearchResultAction.ID, FocusNextSearchResultAction.LABEL, { primary: KeyCode.F4 }), 'Focus Next Search Result', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusPreviousSearchResultAction, FocusPreviousSearchResultAction.ID, FocusPreviousSearchResultAction.LABEL, { primary: KeyMod.Shift | KeyCode.F4 }), 'Focus Previous Search Result', category);
325

326
registry.registerWorkbenchAction(new SyncActionDescriptor(ReplaceInFilesAction, ReplaceInFilesAction.ID, ReplaceInFilesAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_H }), 'Replace in Files', category);
S
Sandeep Somavarapu 已提交
327

R
Rob Lourens 已提交
328
KeybindingsRegistry.registerCommandAndKeybindingRule(objects.assign({
R
Rob Lourens 已提交
329
	id: Constants.ToggleCaseSensitiveCommandId,
R
Rob Lourens 已提交
330
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
331
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.SearchInputBoxFocusedKey),
332
	handler: toggleCaseSensitiveCommand
R
Rob Lourens 已提交
333 334 335
}, ToggleCaseSensitiveKeybinding));

KeybindingsRegistry.registerCommandAndKeybindingRule(objects.assign({
R
Rob Lourens 已提交
336
	id: Constants.ToggleWholeWordCommandId,
R
Rob Lourens 已提交
337
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
338
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.SearchInputBoxFocusedKey),
339
	handler: toggleWholeWordCommand
R
Rob Lourens 已提交
340 341 342
}, ToggleWholeWordKeybinding));

KeybindingsRegistry.registerCommandAndKeybindingRule(objects.assign({
R
Rob Lourens 已提交
343
	id: Constants.ToggleRegexCommandId,
R
Rob Lourens 已提交
344
	weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
I
isidor 已提交
345
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.SearchInputBoxFocusedKey),
346
	handler: toggleRegexCommand
R
Rob Lourens 已提交
347
}, ToggleRegexKeybinding));
S
Sandeep Somavarapu 已提交
348

S
Sandeep Somavarapu 已提交
349
// Terms navigation actions
350 351
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowNextSearchTermAction, ShowNextSearchTermAction.ID, ShowNextSearchTermAction.LABEL, ShowNextFindTermKeybinding, ShowNextSearchTermAction.CONTEXT_KEY_EXPRESSION), 'Search: Show Next Search Term', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowPreviousSearchTermAction, ShowPreviousSearchTermAction.ID, ShowPreviousSearchTermAction.LABEL, ShowPreviousFindTermKeybinding, ShowPreviousSearchTermAction.CONTEXT_KEY_EXPRESSION), 'Search: Show Previous Search Term', category);
S
Sandeep Somavarapu 已提交
352

353 354
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowNextSearchIncludeAction, ShowNextSearchIncludeAction.ID, ShowNextSearchIncludeAction.LABEL, ShowNextFindTermKeybinding, ShowNextSearchIncludeAction.CONTEXT_KEY_EXPRESSION), 'Search: Show Next Search Include Pattern', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowPreviousSearchIncludeAction, ShowPreviousSearchIncludeAction.ID, ShowPreviousSearchIncludeAction.LABEL, ShowPreviousFindTermKeybinding, ShowPreviousSearchIncludeAction.CONTEXT_KEY_EXPRESSION), 'Search: Show Previous Search Include Pattern', category);
S
Sandeep Somavarapu 已提交
355

356 357
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowNextSearchExcludeAction, ShowNextSearchExcludeAction.ID, ShowNextSearchExcludeAction.LABEL, ShowNextFindTermKeybinding, ShowNextSearchExcludeAction.CONTEXT_KEY_EXPRESSION), 'Search: Show Next Search Exclude Pattern', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowPreviousSearchExcludeAction, ShowPreviousSearchExcludeAction.ID, ShowPreviousSearchExcludeAction.LABEL, ShowPreviousFindTermKeybinding, ShowPreviousSearchExcludeAction.CONTEXT_KEY_EXPRESSION), 'Search: Show Previous Search Exclude Pattern', category);
S
Sandeep Somavarapu 已提交
358

359
registry.registerWorkbenchAction(new SyncActionDescriptor(CollapseDeepestExpandedLevelAction, CollapseDeepestExpandedLevelAction.ID, CollapseDeepestExpandedLevelAction.LABEL), 'Search: Collapse All', category);
360 361 362

registry.registerWorkbenchAction(new SyncActionDescriptor(ShowAllSymbolsAction, ShowAllSymbolsAction.ID, ShowAllSymbolsAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_T }), 'Go to Symbol in Workspace...');

S
Sandeep Somavarapu 已提交
363

E
Erich Gamma 已提交
364
// Register Quick Open Handler
B
Benjamin Pasero 已提交
365
Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerDefaultQuickOpenHandler(
E
Erich Gamma 已提交
366
	new QuickOpenHandlerDescriptor(
367 368
		OpenAnythingHandler,
		OpenAnythingHandler.ID,
E
Erich Gamma 已提交
369
		'',
370
		defaultQuickOpenContextKey,
B
Benjamin Pasero 已提交
371
		nls.localize('openAnythingHandlerDescription', "Go to File")
E
Erich Gamma 已提交
372 373 374
	)
);

B
Benjamin Pasero 已提交
375
Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpenHandler(
376
	new QuickOpenHandlerDescriptor(
377 378
		OpenSymbolHandler,
		OpenSymbolHandler.ID,
379
		ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX,
380
		'inWorkspaceSymbolsPicker',
381 382
		[
			{
383
				prefix: ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX,
384
				needsEditor: false,
B
Benjamin Pasero 已提交
385
				description: nls.localize('openSymbolDescriptionNormal', "Go to Symbol in Workspace")
386 387 388 389 390
			}
		]
	)
);

E
Erich Gamma 已提交
391
// Configuration
B
Benjamin Pasero 已提交
392
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
E
Erich Gamma 已提交
393
configurationRegistry.registerConfiguration({
394 395 396 397 398
	id: 'search',
	order: 13,
	title: nls.localize('searchConfigurationTitle', "Search"),
	type: 'object',
	properties: {
E
Erich Gamma 已提交
399
		'search.exclude': {
400 401 402 403 404
			type: 'object',
			description: nls.localize('exclude', "Configure glob patterns for excluding files and folders in searches. Inherits all glob patterns from the files.exclude setting."),
			default: { '**/node_modules': true, '**/bower_components': true },
			additionalProperties: {
				anyOf: [
E
Erich Gamma 已提交
405
					{
406 407
						type: 'boolean',
						description: nls.localize('exclude.boolean', "The glob pattern to match file paths against. Set to true or false to enable or disable the pattern."),
E
Erich Gamma 已提交
408 409
					},
					{
410 411 412 413 414 415 416
						type: 'object',
						properties: {
							when: {
								type: 'string', // expression ({ "**/*.js": { "when": "$(basename).js" } })
								pattern: '\\w*\\$\\(basename\\)\\w*',
								default: '$(basename).ext',
								description: nls.localize('exclude.when', 'Additional check on the siblings of a matching file. Use $(basename) as variable for the matching file name.')
E
Erich Gamma 已提交
417 418 419 420
							}
						}
					}
				]
S
Sandeep Somavarapu 已提交
421
			},
422
			scope: ConfigurationScope.RESOURCE
423
		},
424
		'search.useRipgrep': {
425 426 427
			type: 'boolean',
			description: nls.localize('useRipgrep', "Controls whether to use ripgrep in text and file search"),
			default: true
428
		},
429
		'search.useIgnoreFiles': {
430 431 432 433
			type: 'boolean',
			description: nls.localize('useIgnoreFiles', "Controls whether to use .gitignore and .ignore files when searching for files."),
			default: true,
			scope: ConfigurationScope.RESOURCE
434
		},
435
		'search.quickOpen.includeSymbols': {
436 437 438
			type: 'boolean',
			description: nls.localize('search.quickOpen.includeSymbols', "Configure to include results from a global symbol search in the file results for Quick Open."),
			default: false
439 440
		},
		'search.followSymlinks': {
441 442 443
			type: 'boolean',
			description: nls.localize('search.followSymlinks', "Controls whether to follow symlinks while searching."),
			default: true
444 445
		},
		'search.smartCase': {
446 447 448
			type: 'boolean',
			description: nls.localize('search.smartCase', "Searches case-insensitively if the pattern is all lowercase, otherwise, searches case-sensitively"),
			default: false
449 450
		},
		'search.globalFindClipboard': {
451 452 453 454 455 456 457 458
			type: 'boolean',
			default: false,
			description: nls.localize('search.globalFindClipboard', "Controls if the Search Viewlet should read or modify the shared find clipboard on macOS"),
			included: platform.isMacintosh
		},
		'search.location': {
			enum: ['sidebar', 'panel'],
			default: 'sidebar',
459
			description: nls.localize('search.location', "Preview: controls if the search will be shown as a view in the sidebar or as a panel in the panel area for more horizontal space. Next release search in panel will have improved horizontal layout and this will no longer be a preview."),
460
		},
E
Erich Gamma 已提交
461
	}
J
Johannes Rieken 已提交
462
});
463

464
registerLanguageCommand('_executeWorkspaceSymbolProvider', function (accessor, args: { query: string; }) {
465 466 467 468 469 470
	let { query } = args;
	if (typeof query !== 'string') {
		throw illegalArgument();
	}
	return getWorkspaceSymbols(query);
});