search.contribution.ts 22.6 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';
13
import * as nls from '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, ShowPreviousSearchIncludeAction, ShowNextSearchIncludeAction, 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),
133 134
	primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.Enter,
	secondary: [KeyMod.Shift | KeyMod.CtrlCmd | KeyCode.KEY_1],
S
Sandeep Somavarapu 已提交
135
	handler: (accessor, args: any) => {
136
		const searchView = getSearchView(accessor.get(IViewletService), accessor.get(IPanelService));
137
		const tree: ITree = searchView.getControl();
138
		accessor.get(IInstantiationService).createInstance(ReplaceAction, tree, tree.getFocus(), searchView).run();
S
Sandeep Somavarapu 已提交
139 140 141 142 143 144
	}
});

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

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

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

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

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

I
isidor 已提交
196 197 198 199 200 201
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);
202
		const panelService = accessor.get(IPanelService);
I
isidor 已提交
203
		const fileService = accessor.get(IFileService);
204
		const resources = getMultiSelectedResources(resource, listService, accessor.get(IWorkbenchEditorService));
I
isidor 已提交
205

206
		return openSearchView(viewletService, panelService, true).then(searchView => {
207 208 209 210 211 212 213 214 215 216
			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));
						}
					});

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

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

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

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

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


257
class ShowAllSymbolsAction extends Action {
258 259 260
	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 已提交
261

262 263 264 265 266 267 268 269 270 271
	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> {

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

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

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

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

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

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

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

I
isidor 已提交
311 312
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"));
313
registry.registerWorkbenchAction(new SyncActionDescriptor(FindInFilesAction, Constants.FindInFilesActionId, nls.localize('findInFiles', "Find in Files"), { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F },
R
Rob Lourens 已提交
314
	Constants.SearchInputBoxFocusedKey.toNegated()), 'Find in Files', category);
S
Sandeep Somavarapu 已提交
315

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

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

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

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

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

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

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

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

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

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

S
Sandeep Somavarapu 已提交
361

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

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

E
Erich Gamma 已提交
389
// Configuration
B
Benjamin Pasero 已提交
390
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
E
Erich Gamma 已提交
391
configurationRegistry.registerConfiguration({
392 393 394 395 396
	id: 'search',
	order: 13,
	title: nls.localize('searchConfigurationTitle', "Search"),
	type: 'object',
	properties: {
E
Erich Gamma 已提交
397
		'search.exclude': {
398 399 400 401 402
			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 已提交
403
					{
404 405
						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 已提交
406 407
					},
					{
408 409 410 411 412 413 414
						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 已提交
415 416 417 418
							}
						}
					}
				]
S
Sandeep Somavarapu 已提交
419
			},
420
			scope: ConfigurationScope.RESOURCE
421
		},
422
		'search.useRipgrep': {
423 424 425
			type: 'boolean',
			description: nls.localize('useRipgrep', "Controls whether to use ripgrep in text and file search"),
			default: true
426
		},
427
		'search.useIgnoreFiles': {
428 429 430 431
			type: 'boolean',
			description: nls.localize('useIgnoreFiles', "Controls whether to use .gitignore and .ignore files when searching for files."),
			default: true,
			scope: ConfigurationScope.RESOURCE
432
		},
433
		'search.quickOpen.includeSymbols': {
434 435 436
			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
437 438
		},
		'search.followSymlinks': {
439 440 441
			type: 'boolean',
			description: nls.localize('search.followSymlinks', "Controls whether to follow symlinks while searching."),
			default: true
442 443
		},
		'search.smartCase': {
444 445 446
			type: 'boolean',
			description: nls.localize('search.smartCase', "Searches case-insensitively if the pattern is all lowercase, otherwise, searches case-sensitively"),
			default: false
447 448
		},
		'search.globalFindClipboard': {
449 450
			type: 'boolean',
			default: false,
B
Benjamin Pasero 已提交
451
			description: nls.localize('search.globalFindClipboard', "Controls if the search view should read or modify the shared find clipboard on macOS"),
452 453 454 455 456
			included: platform.isMacintosh
		},
		'search.location': {
			enum: ['sidebar', 'panel'],
			default: 'sidebar',
457
			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."),
458
		},
E
Erich Gamma 已提交
459
	}
J
Johannes Rieken 已提交
460
});
461

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