search.contribution.ts 29.9 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.
 *--------------------------------------------------------------------------------------------*/

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

60
registerSingleton(ISearchWorkbenchService, SearchWorkbenchService, true);
61 62
replaceContributions();
searchWidgetContributions();
E
Erich Gamma 已提交
63

64 65
const category = nls.localize('search', "Search");

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

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

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

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

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

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

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

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

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

179 180
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: FocusNextInputAction.ID,
181
	weight: KeybindingWeight.WorkbenchContrib,
182
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.InputBoxFocusedKey),
183
	primary: KeyMod.CtrlCmd | KeyCode.DownArrow,
184 185 186 187 188 189 190
	handler: (accessor, args: any) => {
		accessor.get(IInstantiationService).createInstance(FocusNextInputAction, FocusNextInputAction.ID, '').run();
	}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: FocusPreviousInputAction.ID,
191
	weight: KeybindingWeight.WorkbenchContrib,
192
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.InputBoxFocusedKey, Constants.SearchInputBoxFocusedKey.toNegated()),
193
	primary: KeyMod.CtrlCmd | KeyCode.UpArrow,
194 195 196 197 198
	handler: (accessor, args: any) => {
		accessor.get(IInstantiationService).createInstance(FocusPreviousInputAction, FocusPreviousInputAction.ID, '').run();
	}
});

R
Rob Lourens 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
MenuRegistry.appendMenuItem(MenuId.SearchContext, {
	command: {
		id: Constants.ReplaceActionId,
		title: ReplaceAction.LABEL
	},
	when: ContextKeyExpr.and(Constants.ReplaceActiveKey, Constants.MatchFocusKey),
	group: 'search',
	order: 1
});

MenuRegistry.appendMenuItem(MenuId.SearchContext, {
	command: {
		id: Constants.ReplaceAllInFolderActionId,
		title: ReplaceAllInFolderAction.LABEL
	},
	when: ContextKeyExpr.and(Constants.ReplaceActiveKey, Constants.FolderFocusKey),
	group: 'search',
	order: 1
});

MenuRegistry.appendMenuItem(MenuId.SearchContext, {
	command: {
		id: Constants.ReplaceAllInFileActionId,
		title: ReplaceAllAction.LABEL
	},
	when: ContextKeyExpr.and(Constants.ReplaceActiveKey, Constants.FileFocusKey),
	group: 'search',
	order: 1
});

MenuRegistry.appendMenuItem(MenuId.SearchContext, {
	command: {
		id: Constants.RemoveActionId,
		title: RemoveAction.LABEL
	},
	when: Constants.FileMatchOrMatchFocusKey,
	group: 'search',
	order: 2
});

R
Rob Lourens 已提交
239 240
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.CopyMatchCommandId,
241
	weight: KeybindingWeight.WorkbenchContrib,
R
Rob Lourens 已提交
242 243 244 245 246 247 248 249 250 251 252 253
	when: Constants.FileMatchOrMatchFocusKey,
	primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
	handler: copyMatchCommand
});

MenuRegistry.appendMenuItem(MenuId.SearchContext, {
	command: {
		id: Constants.CopyMatchCommandId,
		title: nls.localize('copyMatchLabel', "Copy")
	},
	when: Constants.FileMatchOrMatchFocusKey,
	group: 'search_2',
R
Rob Lourens 已提交
254
	order: 1
R
Rob Lourens 已提交
255 256
});

257 258
KeybindingsRegistry.registerCommandAndKeybindingRule({
	id: Constants.CopyPathCommandId,
259
	weight: KeybindingWeight.WorkbenchContrib,
260
	when: Constants.FileMatchOrFolderMatchFocusKey,
261 262 263 264 265 266 267 268 269 270 271 272
	primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_C,
	win: {
		primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_C
	},
	handler: copyPathCommand
});

MenuRegistry.appendMenuItem(MenuId.SearchContext, {
	command: {
		id: Constants.CopyPathCommandId,
		title: nls.localize('copyPathLabel', "Copy Path")
	},
273
	when: Constants.FileMatchOrFolderMatchFocusKey,
R
Rob Lourens 已提交
274
	group: 'search_2',
R
Rob Lourens 已提交
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
	order: 2
});

MenuRegistry.appendMenuItem(MenuId.SearchContext, {
	command: {
		id: Constants.CopyAllCommandId,
		title: nls.localize('copyAllLabel', "Copy All")
	},
	when: Constants.HasSearchResults,
	group: 'search_2',
	order: 3
});

CommandsRegistry.registerCommand({
	id: Constants.CopyAllCommandId,
	handler: copyAllCommand
291 292
});

293 294 295 296 297 298 299 300 301 302 303 304 305
CommandsRegistry.registerCommand({
	id: Constants.ClearSearchHistoryCommandId,
	handler: clearHistoryCommand
});

const clearSearchHistoryLabel = nls.localize('clearSearchHistoryLabel', "Clear Search History");
const ClearSearchHistoryCommand: ICommandAction = {
	id: Constants.ClearSearchHistoryCommandId,
	title: clearSearchHistoryLabel,
	category
};
MenuRegistry.addCommand(ClearSearchHistoryCommand);

306 307 308 309 310 311 312 313 314 315 316 317
CommandsRegistry.registerCommand({
	id: Constants.ToggleSearchViewPositionCommandId,
	handler: (accessor) => {
		const configurationService = accessor.get(IConfigurationService);
		const currentValue = configurationService.getValue<ISearchConfigurationProperties>('search').location;
		const toggleValue = currentValue === 'sidebar' ? 'panel' : 'sidebar';

		configurationService.updateValue('search.location', toggleValue);
	}
});

const toggleSearchViewPositionLabel = nls.localize('toggleSearchViewPositionLabel', "Toggle Search View Position");
318 319 320 321 322 323
const ToggleSearchViewPositionCommand: ICommandAction = {
	id: Constants.ToggleSearchViewPositionCommandId,
	title: toggleSearchViewPositionLabel,
	category
};
MenuRegistry.addCommand(ToggleSearchViewPositionCommand);
324
MenuRegistry.appendMenuItem(MenuId.SearchContext, {
325
	command: ToggleSearchViewPositionCommand,
326
	when: Constants.SearchViewVisibleKey,
R
Rob Lourens 已提交
327
	group: 'search_9',
328
	order: 1
329 330
});

Y
Yogesh 已提交
331 332 333 334 335 336 337 338 339 340 341 342 343
CommandsRegistry.registerCommand({
	id: Constants.FocusSearchListCommandID,
	handler: focusSearchListCommand
});

const focusSearchListCommandLabel = nls.localize('focusSearchListCommandLabel', "Focus List");
const FocusSearchListCommand: ICommandAction = {
	id: Constants.FocusSearchListCommandID,
	title: focusSearchListCommandLabel,
	category
};
MenuRegistry.addCommand(FocusSearchListCommand);

I
isidor 已提交
344 345 346 347 348 349
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);
350
		const panelService = accessor.get(IPanelService);
I
isidor 已提交
351
		const fileService = accessor.get(IFileService);
352
		const resources = getMultiSelectedResources(resource, listService, accessor.get(IEditorService));
I
isidor 已提交
353

354
		return openSearchView(viewletService, panelService, true).then(searchView => {
355 356 357 358 359 360 361 362 363 364
			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));
						}
					});

365
					searchView.searchInFolders(distinct(folders, folder => folder.toString()), (from, to) => relative(from, to));
366
				});
367
			}
368 369

			return void 0;
I
isidor 已提交
370
		});
I
isidor 已提交
371 372
	}
});
E
Erich Gamma 已提交
373

R
Rob Lourens 已提交
374 375 376 377 378 379 380
CommandsRegistry.registerCommand({
	id: ClearSearchResultsAction.ID,
	handler: (accessor, args: any) => {
		accessor.get(IInstantiationService).createInstance(ClearSearchResultsAction, ClearSearchResultsAction.ID, '').run();
	}
});

381 382 383 384 385 386 387
CommandsRegistry.registerCommand({
	id: RefreshAction.ID,
	handler: (accessor, args: any) => {
		accessor.get(IInstantiationService).createInstance(RefreshAction, RefreshAction.ID, '').run();
	}
});

I
isidor 已提交
388 389 390
const FIND_IN_WORKSPACE_ID = 'filesExplorer.findInWorkspace';
CommandsRegistry.registerCommand({
	id: FIND_IN_WORKSPACE_ID,
I
isidor 已提交
391
	handler: (accessor) => {
392 393
		return openSearchView(accessor.get(IViewletService), accessor.get(IPanelService), true).then(searchView => {
			searchView.searchInFolders(null, (from, to) => relative(from, to));
I
isidor 已提交
394 395 396
		});
	}
});
E
Erich Gamma 已提交
397

I
isidor 已提交
398
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
399 400
	group: '4_search',
	order: 10,
I
isidor 已提交
401 402 403 404
	command: {
		id: FIND_IN_FOLDER_ID,
		title: nls.localize('findInFolder', "Find in Folder...")
	},
405
	when: ContextKeyExpr.and(ExplorerFolderContext, ResourceContextKey.Scheme.isEqualTo(Schemas.file)) // todo@remote
I
isidor 已提交
406
});
E
Erich Gamma 已提交
407

I
isidor 已提交
408
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
I
isidor 已提交
409 410
	group: '4_search',
	order: 10,
I
isidor 已提交
411 412 413 414 415 416
	command: {
		id: FIND_IN_WORKSPACE_ID,
		title: nls.localize('findInWorkspace', "Find in Workspace...")
	},
	when: ContextKeyExpr.and(ExplorerRootContext, ExplorerFolderContext.toNegated())
});
E
Erich Gamma 已提交
417 418


419
class ShowAllSymbolsAction extends Action {
420 421 422
	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 已提交
423

424 425 426 427 428 429 430 431
	constructor(
		actionId: string, actionLabel: string,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
		@ICodeEditorService private editorService: ICodeEditorService) {
		super(actionId, actionLabel);
		this.enabled = !!this.quickOpenService;
	}

432
	public run(context?: any): Promise<void> {
433

434
		let prefix = ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX;
435
		let inputSelection: { start: number; end: number; } = void 0;
436 437
		let editor = this.editorService.getFocusedCodeEditor();
		const word = editor && getSelectionSearchString(editor);
438 439 440 441
		if (word) {
			prefix = prefix + word;
			inputSelection = { start: 1, end: word.length + 1 };
		}
E
Erich Gamma 已提交
442

443 444
		this.quickOpenService.show(prefix, { inputSelection });

445
		return Promise.resolve(null);
E
Erich Gamma 已提交
446 447 448
	}
}

449
// Register View in Viewlet and Panel area
450 451
Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets).registerViewlet(new ViewletDescriptor(
	SearchView,
452
	VIEW_ID,
453 454
	nls.localize('name', "Search"),
	'search',
455
	1
456
));
I
isidor 已提交
457 458

Registry.as<PanelRegistry>(PanelExtensions.Panels).registerPanel(new PanelDescriptor(
459
	SearchView,
460
	VIEW_ID,
E
Erich Gamma 已提交
461 462 463 464 465
	nls.localize('name', "Search"),
	'search',
	10
));

466
// Register view location updater
467
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(SearchViewLocationUpdater, LifecyclePhase.Restoring);
468

S
Sandeep Somavarapu 已提交
469
// Actions
B
Benjamin Pasero 已提交
470
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
E
Erich Gamma 已提交
471

472 473
// Show Search and Find in Files are redundant, but we can't break keybindings by removing one. So it's the same action, same keybinding, registered to different IDs.
// Show Search 'when' is redundant but if the two conflict with exactly the same keybinding and 'when' clause, then they can show up as "unbound" - #51780
B
Benjamin Pasero 已提交
474
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenSearchViewletAction, VIEW_ID, OpenSearchViewletAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F }, Constants.SearchViewVisibleKey.toNegated()), 'View: Show Search', nls.localize('view', "View"));
475
registry.registerWorkbenchAction(new SyncActionDescriptor(FindInFilesAction, Constants.FindInFilesActionId, nls.localize('findInFiles', "Find in Files"), { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_F }), 'Find in Files', category);
476 477 478 479 480 481 482 483
MenuRegistry.appendMenuItem(MenuId.MenubarEditMenu, {
	group: '4_find_global',
	command: {
		id: Constants.FindInFilesActionId,
		title: nls.localize({ key: 'miFindInFiles', comment: ['&& denotes a mnemonic'] }, "Find &&in Files")
	},
	order: 1
});
484

485 486
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);
487

488
registry.registerWorkbenchAction(new SyncActionDescriptor(ReplaceInFilesAction, ReplaceInFilesAction.ID, ReplaceInFilesAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_H }), 'Replace in Files', category);
489 490 491 492 493 494 495 496
MenuRegistry.appendMenuItem(MenuId.MenubarEditMenu, {
	group: '4_find_global',
	command: {
		id: ReplaceInFilesAction.ID,
		title: nls.localize({ key: 'miReplaceInFiles', comment: ['&& denotes a mnemonic'] }, "Replace &&in Files")
	},
	order: 2
});
S
Sandeep Somavarapu 已提交
497

R
Rob Lourens 已提交
498
KeybindingsRegistry.registerCommandAndKeybindingRule(objects.assign({
R
Rob Lourens 已提交
499
	id: Constants.ToggleCaseSensitiveCommandId,
500
	weight: KeybindingWeight.WorkbenchContrib,
S
Sandeep Somavarapu 已提交
501
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.SearchViewFocusedKey, Constants.FileMatchOrFolderMatchFocusKey.toNegated()),
502
	handler: toggleCaseSensitiveCommand
R
Rob Lourens 已提交
503 504 505
}, ToggleCaseSensitiveKeybinding));

KeybindingsRegistry.registerCommandAndKeybindingRule(objects.assign({
R
Rob Lourens 已提交
506
	id: Constants.ToggleWholeWordCommandId,
507
	weight: KeybindingWeight.WorkbenchContrib,
S
Sandeep Somavarapu 已提交
508
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.SearchViewFocusedKey),
509
	handler: toggleWholeWordCommand
R
Rob Lourens 已提交
510 511 512
}, ToggleWholeWordKeybinding));

KeybindingsRegistry.registerCommandAndKeybindingRule(objects.assign({
R
Rob Lourens 已提交
513
	id: Constants.ToggleRegexCommandId,
514
	weight: KeybindingWeight.WorkbenchContrib,
S
Sandeep Somavarapu 已提交
515
	when: ContextKeyExpr.and(Constants.SearchViewVisibleKey, Constants.SearchViewFocusedKey),
516
	handler: toggleRegexCommand
R
Rob Lourens 已提交
517
}, ToggleRegexKeybinding));
S
Sandeep Somavarapu 已提交
518

519
registry.registerWorkbenchAction(new SyncActionDescriptor(CollapseDeepestExpandedLevelAction, CollapseDeepestExpandedLevelAction.ID, CollapseDeepestExpandedLevelAction.LABEL), 'Search: Collapse All', category);
520 521
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowAllSymbolsAction, ShowAllSymbolsAction.ID, ShowAllSymbolsAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_T }), 'Go to Symbol in Workspace...');

R
Rob Lourens 已提交
522 523 524
registry.registerWorkbenchAction(new SyncActionDescriptor(RefreshAction, RefreshAction.ID, RefreshAction.LABEL), 'Search: Refresh', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(ClearSearchResultsAction, ClearSearchResultsAction.ID, ClearSearchResultsAction.LABEL), 'Search: Clear', category);

S
Sandeep Somavarapu 已提交
525

E
Erich Gamma 已提交
526
// Register Quick Open Handler
B
Benjamin Pasero 已提交
527
Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerDefaultQuickOpenHandler(
E
Erich Gamma 已提交
528
	new QuickOpenHandlerDescriptor(
529 530
		OpenAnythingHandler,
		OpenAnythingHandler.ID,
E
Erich Gamma 已提交
531
		'',
532
		defaultQuickOpenContextKey,
B
Benjamin Pasero 已提交
533
		nls.localize('openAnythingHandlerDescription', "Go to File")
E
Erich Gamma 已提交
534 535 536
	)
);

B
Benjamin Pasero 已提交
537
Registry.as<IQuickOpenRegistry>(QuickOpenExtensions.Quickopen).registerQuickOpenHandler(
538
	new QuickOpenHandlerDescriptor(
539 540
		OpenSymbolHandler,
		OpenSymbolHandler.ID,
541
		ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX,
542
		'inWorkspaceSymbolsPicker',
543 544
		[
			{
545
				prefix: ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX,
546
				needsEditor: false,
B
Benjamin Pasero 已提交
547
				description: nls.localize('openSymbolDescriptionNormal', "Go to Symbol in Workspace")
548 549 550 551 552
			}
		]
	)
);

E
Erich Gamma 已提交
553
// Configuration
B
Benjamin Pasero 已提交
554
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
E
Erich Gamma 已提交
555
configurationRegistry.registerConfiguration({
556 557 558 559 560
	id: 'search',
	order: 13,
	title: nls.localize('searchConfigurationTitle', "Search"),
	type: 'object',
	properties: {
E
Erich Gamma 已提交
561
		'search.exclude': {
562
			type: 'object',
563
			markdownDescription: nls.localize('exclude', "Configure glob patterns for excluding files and folders in searches. Inherits all glob patterns from the `#files.exclude#` setting. Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options)."),
564 565 566
			default: { '**/node_modules': true, '**/bower_components': true },
			additionalProperties: {
				anyOf: [
E
Erich Gamma 已提交
567
					{
568 569
						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 已提交
570 571
					},
					{
572 573 574 575 576 577 578
						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 已提交
579 580 581 582
							}
						}
					}
				]
S
Sandeep Somavarapu 已提交
583
			},
584
			scope: ConfigurationScope.RESOURCE
585
		},
586
		'search.useRipgrep': {
587
			type: 'boolean',
588
			description: nls.localize('useRipgrep', "This setting is deprecated and now falls back on \"search.usePCRE2\"."),
589
			deprecationMessage: nls.localize('useRipgrepDeprecated', "Deprecated. Consider \"search.usePCRE2\" for advanced regex feature support."),
590
			default: true
591
		},
592
		'search.useLegacySearch': {
593
			type: 'boolean',
594
			description: nls.localize('useLegacySearch', "Controls whether to use the deprecated legacy mode for text and file search. It supports some text encodings that are not supported by the standard ripgrep-based search."),
595 596
			default: false
		},
597
		'search.useIgnoreFiles': {
598
			type: 'boolean',
599
			markdownDescription: nls.localize('useIgnoreFiles', "Controls whether to use `.gitignore` and `.ignore` files when searching for files."),
600 601
			default: true,
			scope: ConfigurationScope.RESOURCE
602
		},
P
pkoushik 已提交
603 604 605 606
		'search.useGlobalIgnoreFiles': {
			type: 'boolean',
			markdownDescription: nls.localize('useGlobalIgnoreFiles', "Controls whether to use global `.gitignore` and `.ignore` files when searching for files."),
			default: false,
P
pkoushik 已提交
607
			scope: ConfigurationScope.RESOURCE
P
pkoushik 已提交
608
		},
609
		'search.quickOpen.includeSymbols': {
610
			type: 'boolean',
611
			description: nls.localize('search.quickOpen.includeSymbols', "Whether to include results from a global symbol search in the file results for Quick Open."),
612
			default: false
613
		},
B
Benjamin Pasero 已提交
614 615 616 617 618
		'search.quickOpen.includeHistory': {
			type: 'boolean',
			description: nls.localize('search.quickOpen.includeHistory', "Whether to include results from recently opened files in the file results for Quick Open."),
			default: true
		},
619
		'search.followSymlinks': {
620 621 622
			type: 'boolean',
			description: nls.localize('search.followSymlinks', "Controls whether to follow symlinks while searching."),
			default: true
623 624
		},
		'search.smartCase': {
625
			type: 'boolean',
626
			description: nls.localize('search.smartCase', "Search case-insensitively if the pattern is all lowercase, otherwise, search case-sensitively."),
627
			default: false
628 629
		},
		'search.globalFindClipboard': {
630 631
			type: 'boolean',
			default: false,
I
isidor 已提交
632
			description: nls.localize('search.globalFindClipboard', "Controls whether the search view should read or modify the shared find clipboard on macOS."),
633 634 635
			included: platform.isMacintosh
		},
		'search.location': {
636
			type: 'string',
637 638
			enum: ['sidebar', 'panel'],
			default: 'sidebar',
639
			description: nls.localize('search.location', "Controls whether the search will be shown as a view in the sidebar or as a panel in the panel area for more horizontal space."),
N
Nil 已提交
640
		},
R
Rob Lourens 已提交
641
		'search.collapseResults': {
N
Nil 已提交
642
			type: 'string',
R
Rob Lourens 已提交
643 644 645 646 647 648
			enum: ['auto', 'alwaysCollapse', 'alwaysExpand'],
			enumDescriptions: [
				'Files with less than 10 results are expanded. Others are collapsed.',
				'',
				''
			],
N
Nil 已提交
649
			default: 'auto',
R
Rob Lourens 已提交
650
			description: nls.localize('search.collapseAllResults', "Controls whether the search results will be collapsed or expanded."),
651 652 653 654
		},
		'search.useReplacePreview': {
			type: 'boolean',
			default: true,
655
			description: nls.localize('search.useReplacePreview', "Controls whether to open Replace Preview when selecting or replacing a match."),
656 657 658 659 660
		},
		'search.showLineNumbers': {
			type: 'boolean',
			default: false,
			description: nls.localize('search.showLineNumbers', "Controls whether to show line numbers for search results."),
661 662 663 664 665 666 667 668 669 670
		},
		'searchRipgrep.enable': {
			type: 'boolean',
			default: false,
			deprecationMessage: nls.localize('search.searchRipgrepEnableDeprecated', "Deprecated. Use \"search.runInExtensionHost\" instead"),
			description: nls.localize('search.searchRipgrepEnable', "Whether to run search in the extension host")
		},
		'search.runInExtensionHost': {
			type: 'boolean',
			default: false,
R
Rob Lourens 已提交
671
			description: nls.localize('search.runInExtensionHost', "Whether to run search in the extension host. Requires a restart to take effect.")
R
Rob Lourens 已提交
672 673 674 675
		},
		'search.usePCRE2': {
			type: 'boolean',
			default: false,
676
			description: nls.localize('search.usePCRE2', "Whether to use the PCRE2 regex engine in text search. This enables using some advanced regex features like lookbehind and backreferences. However, not all PCRE2 features are supported - only features that are also supported by JavaScript.")
677 678 679 680 681 682
		},
		'search.actionsPosition': {
			type: 'string',
			enum: ['auto', 'right'],
			default: 'auto',
			description: nls.localize('search.actionsPosition', "Controls whether to show actions at the end of match or always aligned to the right in wide panels.")
683
		}
E
Erich Gamma 已提交
684
	}
J
Johannes Rieken 已提交
685
});
686

687
registerLanguageCommand('_executeWorkspaceSymbolProvider', function (accessor, args: { query: string; }) {
688 689 690 691 692 693
	let { query } = args;
	if (typeof query !== 'string') {
		throw illegalArgument();
	}
	return getWorkspaceSymbols(query);
});
694 695 696 697 698 699 700 701 702 703 704

// View menu

MenuRegistry.appendMenuItem(MenuId.MenubarViewMenu, {
	group: '3_views',
	command: {
		id: VIEW_ID,
		title: nls.localize({ key: 'miViewSearch', comment: ['&& denotes a mnemonic'] }, "&&Search")
	},
	order: 2
});
705 706 707 708 709 710 711 712 713 714

// Go to menu

MenuRegistry.appendMenuItem(MenuId.MenubarGoMenu, {
	group: 'z_go_to',
	command: {
		id: 'workbench.action.showAllSymbols',
		title: nls.localize({ key: 'miGotoSymbolInWorkspace', comment: ['&& denotes a mnemonic'] }, "Go to Symbol in &&Workspace...")
	},
	order: 3
715
});