From 43d168182c8df35a99c7f5ee0ef227de34f75fbd Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Tue, 29 May 2018 21:00:50 -0700 Subject: [PATCH] EH search - replace search.enableSearchProviders with a search-rg specific setting --- extensions/search-rg/package.json | 13 +++- extensions/search-rg/package.nls.json | 4 +- extensions/search-rg/src/extension.ts | 8 ++- src/vs/platform/search/common/search.ts | 1 - .../electron-browser/search.contribution.ts | 5 -- .../services/search/node/searchService.ts | 69 +++++++++---------- 6 files changed, 52 insertions(+), 48 deletions(-) diff --git a/extensions/search-rg/package.json b/extensions/search-rg/package.json index 8a214641086df..0b58003b5d2b4 100644 --- a/extensions/search-rg/package.json +++ b/extensions/search-rg/package.json @@ -27,5 +27,16 @@ "*" ], "main": "./out/extension", - "contributes": {} + "contributes": { + "configuration": { + "title": "Search (ripgrep)", + "properties": { + "searchrg.enable": { + "type": "boolean", + "default": false, + "scope": "window" + } + } + } + } } diff --git a/extensions/search-rg/package.nls.json b/extensions/search-rg/package.nls.json index ad6083c7edda4..483138a7bb78f 100644 --- a/extensions/search-rg/package.nls.json +++ b/extensions/search-rg/package.nls.json @@ -1,4 +1,4 @@ { - "displayName": "Search", - "description": "Provides search." + "displayName": "Search (ripgrep)", + "description": "Provides search using Ripgrep." } \ No newline at end of file diff --git a/extensions/search-rg/src/extension.ts b/extensions/search-rg/src/extension.ts index 161662b1009ad..f7728fd7e9676 100644 --- a/extensions/search-rg/src/extension.ts +++ b/extensions/search-rg/src/extension.ts @@ -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 { diff --git a/src/vs/platform/search/common/search.ts b/src/vs/platform/search/common/search.ts index 000bb94441844..e10e1656ea5ed 100644 --- a/src/vs/platform/search/common/search.ts +++ b/src/vs/platform/search/common/search.ts @@ -190,7 +190,6 @@ export interface ISearchConfigurationProperties { smartCase: boolean; globalFindClipboard: boolean; location: 'sidebar' | 'panel'; - enableSearchProviders: boolean; } export interface ISearchConfiguration extends IFilesConfiguration { diff --git a/src/vs/workbench/parts/search/electron-browser/search.contribution.ts b/src/vs/workbench/parts/search/electron-browser/search.contribution.ts index 54a16ff3ceb9f..9cb03d2e7e4e4 100644 --- a/src/vs/workbench/parts/search/electron-browser/search.contribution.ts +++ b/src/vs/workbench/parts/search/electron-browser/search.contribution.ts @@ -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.") } } }); diff --git a/src/vs/workbench/services/search/node/searchService.ts b/src/vs/workbench/services/search/node/searchService.ts index ccae05f6d24e2..f9bb3b703feb8 100644 --- a/src/vs/workbench/services/search/node/searchService.ts +++ b/src/vs/workbench/services/search/node/searchService.ts @@ -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; constructor( @@ -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); } } }; @@ -114,40 +114,37 @@ export class SearchService implements ISearchService { } }); - const enableSearchProviders = this.configurationService.getValue().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 { - 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 { + 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 = {