Skip to content

Commit 43d1681

Browse files
committed
EH search - replace search.enableSearchProviders with a search-rg specific setting
1 parent 39d314e commit 43d1681

6 files changed

Lines changed: 52 additions & 48 deletions

File tree

extensions/search-rg/package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,16 @@
2727
"*"
2828
],
2929
"main": "./out/extension",
30-
"contributes": {}
30+
"contributes": {
31+
"configuration": {
32+
"title": "Search (ripgrep)",
33+
"properties": {
34+
"searchrg.enable": {
35+
"type": "boolean",
36+
"default": false,
37+
"scope": "window"
38+
}
39+
}
40+
}
41+
}
3142
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"displayName": "Search",
3-
"description": "Provides search."
2+
"displayName": "Search (ripgrep)",
3+
"description": "Provides search using Ripgrep."
44
}

extensions/search-rg/src/extension.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import { RipgrepTextSearchEngine } from './ripgrepTextSearch';
88
import { RipgrepFileSearchEngine } from './ripgrepFileSearch';
99

1010
export function activate(): void {
11-
const outputChannel = vscode.window.createOutputChannel('search-rg');
12-
const provider = new RipgrepSearchProvider(outputChannel);
13-
vscode.workspace.registerSearchProvider('file', provider);
11+
if (vscode.workspace.getConfiguration('searchrg').get('enable')) {
12+
const outputChannel = vscode.window.createOutputChannel('search-rg');
13+
const provider = new RipgrepSearchProvider(outputChannel);
14+
vscode.workspace.registerSearchProvider('file', provider);
15+
}
1416
}
1517

1618
class RipgrepSearchProvider implements vscode.SearchProvider {

src/vs/platform/search/common/search.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ export interface ISearchConfigurationProperties {
190190
smartCase: boolean;
191191
globalFindClipboard: boolean;
192192
location: 'sidebar' | 'panel';
193-
enableSearchProviders: boolean;
194193
}
195194

196195
export interface ISearchConfiguration extends IFilesConfiguration {

src/vs/workbench/parts/search/electron-browser/search.contribution.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,6 @@ configurationRegistry.registerConfiguration({
604604
enum: ['sidebar', 'panel'],
605605
default: 'sidebar',
606606
description: nls.localize('search.location', "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."),
607-
},
608-
'search.enableSearchProviders': {
609-
type: 'boolean',
610-
default: false,
611-
description: nls.localize('search.enableSearchProviders', " (Experimental) Controls whether search provider extensions should be enabled.")
612607
}
613608
}
614609
});

src/vs/workbench/services/search/node/searchService.ts

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class SearchService implements ISearchService {
3131
public _serviceBrand: any;
3232

3333
private diskSearch: DiskSearch;
34-
private readonly searchProvider: ISearchResultProvider[] = [];
34+
private readonly searchProviders: ISearchResultProvider[] = [];
3535
private forwardingTelemetry: PPromise<void, ITelemetryEvent>;
3636

3737
constructor(
@@ -47,12 +47,12 @@ export class SearchService implements ISearchService {
4747
}
4848

4949
public registerSearchResultProvider(provider: ISearchResultProvider): IDisposable {
50-
this.searchProvider.push(provider);
50+
this.searchProviders.push(provider);
5151
return {
5252
dispose: () => {
53-
const idx = this.searchProvider.indexOf(provider);
53+
const idx = this.searchProviders.indexOf(provider);
5454
if (idx >= 0) {
55-
this.searchProvider.splice(idx, 1);
55+
this.searchProviders.splice(idx, 1);
5656
}
5757
}
5858
};
@@ -114,40 +114,37 @@ export class SearchService implements ISearchService {
114114
}
115115
});
116116

117-
const enableSearchProviders = this.configurationService.getValue<ISearchConfiguration>().search.enableSearchProviders;
118-
const providerPromise = enableSearchProviders ?
119-
this.extensionService.whenInstalledExtensionsRegistered().then(() => {
120-
// If no search providers are registered, fall back on DiskSearch
121-
// TODO@roblou this is not properly waiting for search-rg to finish registering itself
122-
if (this.searchProvider.length) {
123-
return TPromise.join(this.searchProvider.map(p => searchWithProvider(p)))
124-
.then(completes => {
125-
completes = completes.filter(c => !!c);
126-
if (!completes.length) {
127-
return null;
128-
}
129-
130-
return <ISearchComplete>{
131-
limitHit: completes[0] && completes[0].limitHit,
132-
stats: completes[0].stats,
133-
results: arrays.flatten(completes.map(c => c.results))
134-
};
135-
}, errs => {
136-
if (!Array.isArray(errs)) {
137-
errs = [errs];
138-
}
139-
140-
errs = errs.filter(e => !!e);
141-
return TPromise.wrapError(errs[0]);
142-
});
143-
} else {
144-
return searchWithProvider(this.diskSearch);
145-
}
146-
}) :
147-
searchWithProvider(this.diskSearch);
117+
const providerPromise = this.extensionService.whenInstalledExtensionsRegistered().then(() => {
118+
// If no search providers are registered, fall back on DiskSearch
119+
// TODO@roblou this is not properly waiting for search-rg to finish registering itself
120+
if (this.searchProviders.length) {
121+
return TPromise.join(this.searchProviders.map(p => searchWithProvider(p)))
122+
.then(completes => {
123+
completes = completes.filter(c => !!c);
124+
if (!completes.length) {
125+
return null;
126+
}
127+
128+
return <ISearchComplete>{
129+
limitHit: completes[0] && completes[0].limitHit,
130+
stats: completes[0].stats,
131+
results: arrays.flatten(completes.map(c => c.results))
132+
};
133+
}, errs => {
134+
if (!Array.isArray(errs)) {
135+
errs = [errs];
136+
}
137+
138+
errs = errs.filter(e => !!e);
139+
return TPromise.wrapError(errs[0]);
140+
});
141+
} else {
142+
return searchWithProvider(this.diskSearch);
143+
}
144+
});
148145

149146
combinedPromise = providerPromise.then(value => {
150-
this.logService.debug(`SearchService#search took ${Date.now() - startTime}ms ${enableSearchProviders ? 'with' : 'without'} search-rg`);
147+
this.logService.debug(`SearchService#search: ${Date.now() - startTime}ms`);
151148
const values = [value];
152149

153150
const result: ISearchComplete = {

0 commit comments

Comments
 (0)