Skip to content

Commit

Permalink
EH search - replace search.enableSearchProviders with a search-rg spe…
Browse files Browse the repository at this point in the history
…cific setting
  • Loading branch information
roblourens committed May 30, 2018
1 parent 39d314e commit 43d1681
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 48 deletions.
13 changes: 12 additions & 1 deletion extensions/search-rg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,16 @@
"*"
],
"main": "./out/extension",
"contributes": {}
"contributes": {
"configuration": {
"title": "Search (ripgrep)",
"properties": {
"searchrg.enable": {
"type": "boolean",
"default": false,
"scope": "window"
}
}
}
}
}
4 changes: 2 additions & 2 deletions extensions/search-rg/package.nls.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"displayName": "Search",
"description": "Provides search."
"displayName": "Search (ripgrep)",
"description": "Provides search using Ripgrep."
}
8 changes: 5 additions & 3 deletions extensions/search-rg/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { RipgrepTextSearchEngine } from './ripgrepTextSearch';
import { RipgrepFileSearchEngine } from './ripgrepFileSearch';

export function activate(): void {
const outputChannel = vscode.window.createOutputChannel('search-rg');
const provider = new RipgrepSearchProvider(outputChannel);
vscode.workspace.registerSearchProvider('file', provider);
if (vscode.workspace.getConfiguration('searchrg').get('enable')) {
const outputChannel = vscode.window.createOutputChannel('search-rg');
const provider = new RipgrepSearchProvider(outputChannel);
vscode.workspace.registerSearchProvider('file', provider);
}
}

class RipgrepSearchProvider implements vscode.SearchProvider {
Expand Down
1 change: 0 additions & 1 deletion src/vs/platform/search/common/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ export interface ISearchConfigurationProperties {
smartCase: boolean;
globalFindClipboard: boolean;
location: 'sidebar' | 'panel';
enableSearchProviders: boolean;
}

export interface ISearchConfiguration extends IFilesConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,6 @@ configurationRegistry.registerConfiguration({
enum: ['sidebar', 'panel'],
default: 'sidebar',
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."),
},
'search.enableSearchProviders': {
type: 'boolean',
default: false,
description: nls.localize('search.enableSearchProviders', " (Experimental) Controls whether search provider extensions should be enabled.")
}
}
});
Expand Down
69 changes: 33 additions & 36 deletions src/vs/workbench/services/search/node/searchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class SearchService implements ISearchService {
public _serviceBrand: any;

private diskSearch: DiskSearch;
private readonly searchProvider: ISearchResultProvider[] = [];
private readonly searchProviders: ISearchResultProvider[] = [];
private forwardingTelemetry: PPromise<void, ITelemetryEvent>;

constructor(
Expand All @@ -47,12 +47,12 @@ export class SearchService implements ISearchService {
}

public registerSearchResultProvider(provider: ISearchResultProvider): IDisposable {
this.searchProvider.push(provider);
this.searchProviders.push(provider);
return {
dispose: () => {
const idx = this.searchProvider.indexOf(provider);
const idx = this.searchProviders.indexOf(provider);
if (idx >= 0) {
this.searchProvider.splice(idx, 1);
this.searchProviders.splice(idx, 1);
}
}
};
Expand Down Expand Up @@ -114,40 +114,37 @@ export class SearchService implements ISearchService {
}
});

const enableSearchProviders = this.configurationService.getValue<ISearchConfiguration>().search.enableSearchProviders;
const providerPromise = enableSearchProviders ?
this.extensionService.whenInstalledExtensionsRegistered().then(() => {
// If no search providers are registered, fall back on DiskSearch
// TODO@roblou this is not properly waiting for search-rg to finish registering itself
if (this.searchProvider.length) {
return TPromise.join(this.searchProvider.map(p => searchWithProvider(p)))
.then(completes => {
completes = completes.filter(c => !!c);
if (!completes.length) {
return null;
}

return <ISearchComplete>{
limitHit: completes[0] && completes[0].limitHit,
stats: completes[0].stats,
results: arrays.flatten(completes.map(c => c.results))
};
}, errs => {
if (!Array.isArray(errs)) {
errs = [errs];
}

errs = errs.filter(e => !!e);
return TPromise.wrapError(errs[0]);
});
} else {
return searchWithProvider(this.diskSearch);
}
}) :
searchWithProvider(this.diskSearch);
const providerPromise = this.extensionService.whenInstalledExtensionsRegistered().then(() => {
// If no search providers are registered, fall back on DiskSearch
// TODO@roblou this is not properly waiting for search-rg to finish registering itself
if (this.searchProviders.length) {
return TPromise.join(this.searchProviders.map(p => searchWithProvider(p)))
.then(completes => {
completes = completes.filter(c => !!c);
if (!completes.length) {
return null;
}

return <ISearchComplete>{
limitHit: completes[0] && completes[0].limitHit,
stats: completes[0].stats,
results: arrays.flatten(completes.map(c => c.results))
};
}, errs => {
if (!Array.isArray(errs)) {
errs = [errs];
}

errs = errs.filter(e => !!e);
return TPromise.wrapError(errs[0]);
});
} else {
return searchWithProvider(this.diskSearch);
}
});

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

const result: ISearchComplete = {
Expand Down

0 comments on commit 43d1681

Please sign in to comment.