Skip to content

Commit 1797c84

Browse files
author
Jackson Kearl
committed
Allow passing args to search editor.
Closees microsoft#95582.
1 parent b970464 commit 1797c84

3 files changed

Lines changed: 58 additions & 35 deletions

File tree

src/vs/workbench/contrib/searchEditor/browser/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ export const SearchEditorScheme = 'search-editor';
1212
export const SearchEditorFindMatchClass = 'seaarchEditorFindMatch';
1313

1414
export const SearchEditorID = 'workbench.editor.searchEditor';
15+
16+
export const OpenNewEditorCommandId = 'search.action.openNewEditor';

src/vs/workbench/contrib/searchEditor/browser/searchEditor.contribution.ts

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import * as objects from 'vs/base/common/objects';
88
import { endsWith } from 'vs/base/common/strings';
99
import { URI } from 'vs/base/common/uri';
1010
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
11+
import { Range } from 'vs/editor/common/core/range';
1112
import { ToggleCaseSensitiveKeybinding, ToggleRegexKeybinding, ToggleWholeWordKeybinding } from 'vs/editor/contrib/find/findModel';
1213
import { localize } from 'vs/nls';
13-
import { MenuId, SyncActionDescriptor, registerAction2, Action2 } from 'vs/platform/actions/common/actions';
14+
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
1415
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
1516
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1617
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
@@ -20,20 +21,18 @@ import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
2021
import { Registry } from 'vs/platform/registry/common/platform';
2122
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2223
import { EditorDescriptor, Extensions as EditorExtensions, IEditorRegistry } from 'vs/workbench/browser/editor';
23-
import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
2424
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
25-
import { Extensions as EditorInputExtensions, IEditorInputFactory, IEditorInputFactoryRegistry, ActiveEditorContext } from 'vs/workbench/common/editor';
25+
import { ActiveEditorContext, Extensions as EditorInputExtensions, IEditorInputFactory, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
26+
import { IViewsService } from 'vs/workbench/common/views';
27+
import { getSearchView } from 'vs/workbench/contrib/search/browser/searchActions';
28+
import { searchRefreshIcon } from 'vs/workbench/contrib/search/browser/searchIcons';
2629
import * as SearchConstants from 'vs/workbench/contrib/search/common/constants';
2730
import * as SearchEditorConstants from 'vs/workbench/contrib/searchEditor/browser/constants';
2831
import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor';
29-
import { modifySearchEditorContextLinesCommand, OpenSearchEditorAction, selectAllSearchEditorMatchesCommand, toggleSearchEditorCaseSensitiveCommand, toggleSearchEditorContextLinesCommand, toggleSearchEditorRegexCommand, toggleSearchEditorWholeWordCommand, createEditorFromSearchResult, openNewSearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditorActions';
30-
import { getOrMakeSearchEditorInput, SearchEditorInput, SearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
31-
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
32+
import { createEditorFromSearchResult, modifySearchEditorContextLinesCommand, openNewSearchEditor, selectAllSearchEditorMatchesCommand, toggleSearchEditorCaseSensitiveCommand, toggleSearchEditorContextLinesCommand, toggleSearchEditorRegexCommand, toggleSearchEditorWholeWordCommand } from 'vs/workbench/contrib/searchEditor/browser/searchEditorActions';
33+
import { getOrMakeSearchEditorInput, SearchConfiguration, SearchEditorInput } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
3234
import { parseSavedSearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditorSerialization';
33-
import { Range } from 'vs/editor/common/core/range';
34-
import { searchRefreshIcon } from 'vs/workbench/contrib/search/browser/searchIcons';
35-
import { IViewsService } from 'vs/workbench/common/views';
36-
import { getSearchView } from 'vs/workbench/contrib/search/browser/searchActions';
35+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
3736

3837

3938
const OpenInEditorCommandId = 'search.action.openInEditor';
@@ -210,13 +209,35 @@ CommandsRegistry.registerCommand(
210209
//#endregion
211210

212211
//#region Actions
213-
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
214212
const category = localize('search', "Search Editor");
215213

216-
// TODO: Not an action2 becuase used in view pane container action bar, which uses actions
217-
registry.registerWorkbenchAction(
218-
SyncActionDescriptor.from(OpenSearchEditorAction),
219-
'Search Editor: Open New Search Editor', category);
214+
registerAction2(class extends Action2 {
215+
constructor() {
216+
super({
217+
id: SearchEditorConstants.OpenNewEditorCommandId,
218+
title: localize('search.openNewSearchEditor', "Open new Search Editor"),
219+
category,
220+
f1: true,
221+
});
222+
}
223+
async run(accessor: ServicesAccessor, args: Partial<SearchConfiguration>) {
224+
await accessor.get(IInstantiationService).invokeFunction(openNewSearchEditor, args);
225+
}
226+
});
227+
228+
registerAction2(class extends Action2 {
229+
constructor() {
230+
super({
231+
id: OpenNewEditorToSideCommandId,
232+
title: localize('search.openNewEditorToSide', "Open new Search Editor to the Side"),
233+
category,
234+
f1: true,
235+
});
236+
}
237+
async run(accessor: ServicesAccessor, args: Partial<SearchConfiguration>) {
238+
await accessor.get(IInstantiationService).invokeFunction(openNewSearchEditor, args, true);
239+
}
240+
});
220241

221242
registerAction2(class extends Action2 {
222243
constructor() {
@@ -242,21 +263,6 @@ registerAction2(class extends Action2 {
242263
}
243264
});
244265

245-
registerAction2(class extends Action2 {
246-
constructor() {
247-
super({
248-
id: OpenNewEditorToSideCommandId,
249-
title: localize('search.openNewEditorToSide', "Open New Search Editor to Side"),
250-
category,
251-
f1: true,
252-
});
253-
}
254-
async run(accessor: ServicesAccessor) {
255-
const instantiationService = accessor.get(IInstantiationService);
256-
await instantiationService.invokeFunction(openNewSearchEditor, true);
257-
}
258-
});
259-
260266
registerAction2(class extends Action2 {
261267
constructor() {
262268
super({

src/vs/workbench/contrib/searchEditor/browser/searchEditorActions.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ import { ILabelService } from 'vs/platform/label/common/label';
1414
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1515
import { SearchResult } from 'vs/workbench/contrib/search/common/searchModel';
1616
import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor';
17-
import { getOrMakeSearchEditorInput, SearchEditorInput } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
17+
import { getOrMakeSearchEditorInput, SearchEditorInput, SearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/searchEditorInput';
1818
import { serializeSearchResultForEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditorSerialization';
1919
import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
2020
import { ISearchConfigurationProperties } from 'vs/workbench/services/search/common/search';
2121
import { searchNewEditorIcon } from 'vs/workbench/contrib/search/browser/searchIcons';
22-
23-
const OpenNewEditorCommandId = 'search.action.openNewEditor';
22+
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
23+
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
24+
import { IHistoryService } from 'vs/workbench/services/history/common/history';
25+
import { Schemas } from 'vs/base/common/network';
26+
import { withNullAsUndefined } from 'vs/base/common/types';
27+
import { OpenNewEditorCommandId } from 'vs/workbench/contrib/searchEditor/browser/constants';
2428

2529
export const toggleSearchEditorCaseSensitiveCommand = (accessor: ServicesAccessor) => {
2630
const editorService = accessor.get(IEditorService);
@@ -95,12 +99,23 @@ export class OpenSearchEditorAction extends Action {
9599
}
96100

97101
export const openNewSearchEditor =
98-
async (accessor: ServicesAccessor, toSide = false) => {
102+
async (accessor: ServicesAccessor, args: Partial<SearchConfiguration> = {}, toSide = false) => {
99103
const editorService = accessor.get(IEditorService);
100104
const telemetryService = accessor.get(ITelemetryService);
101105
const instantiationService = accessor.get(IInstantiationService);
102106
const configurationService = accessor.get(IConfigurationService);
103107

108+
const configurationResolverService = accessor.get(IConfigurationResolverService);
109+
const workspaceContextService = accessor.get(IWorkspaceContextService);
110+
const historyService = accessor.get(IHistoryService);
111+
const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot(Schemas.file);
112+
const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined;
113+
114+
const resolvedArgs: Record<string, any> = {};
115+
Object.entries(args).forEach(([name, value]) => {
116+
resolvedArgs[name as any] = (typeof value === 'string') ? configurationResolverService.resolve(lastActiveWorkspaceRoot, value) : value;
117+
});
118+
104119
const activeEditorControl = editorService.activeTextEditorControl;
105120
let activeModel: ICodeEditor | undefined;
106121
let selected = '';
@@ -125,7 +140,7 @@ export const openNewSearchEditor =
125140

126141
telemetryService.publicLog2('searchEditor/openNewSearchEditor');
127142

128-
const input = instantiationService.invokeFunction(getOrMakeSearchEditorInput, { config: { query: selected }, text: '' });
143+
const input = instantiationService.invokeFunction(getOrMakeSearchEditorInput, { config: { query: selected, ...resolvedArgs }, text: '' });
129144
const editor = await editorService.openEditor(input, { pinned: true }, toSide ? SIDE_GROUP : ACTIVE_GROUP) as SearchEditor;
130145

131146
if (selected && configurationService.getValue<ISearchConfigurationProperties>('search').searchOnType) {

0 commit comments

Comments
 (0)