From 91a2020698b5220e50f60682724927a810608356 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Wed, 15 Nov 2017 17:09:46 -0800 Subject: [PATCH] Provide for using settings search url from vscode-distro, make relevant settings invisible --- .../environment/common/environment.ts | 2 + .../environment/node/environmentService.ts | 3 ++ src/vs/platform/node/product.ts | 1 + .../electron-browser/main.contribution.ts | 24 ++--------- .../preferences/browser/preferencesEditor.ts | 4 +- .../preferences/browser/preferencesSearch.ts | 41 +++++++++++-------- .../parts/preferences/common/preferences.ts | 2 +- 7 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/vs/platform/environment/common/environment.ts b/src/vs/platform/environment/common/environment.ts index 82572aa5692..357a7e9900f 100644 --- a/src/vs/platform/environment/common/environment.ts +++ b/src/vs/platform/environment/common/environment.ts @@ -111,4 +111,6 @@ export interface IEnvironmentService { installSource: string; disableUpdates: boolean; disableCrashReporter: boolean; + + settingsSearchUrl: string; } diff --git a/src/vs/platform/environment/node/environmentService.ts b/src/vs/platform/environment/node/environmentService.ts index 3f73cf3fe4b..d674d6af54f 100644 --- a/src/vs/platform/environment/node/environmentService.ts +++ b/src/vs/platform/environment/node/environmentService.ts @@ -74,6 +74,9 @@ export class EnvironmentService implements IEnvironmentService { @memoize get settingsSearchBuildId(): number { return product.settingsSearchBuildId; } + @memoize + get settingsSearchUrl(): string { return product.settingsSearchUrl; } + @memoize get appKeybindingsPath(): string { return path.join(this.appSettingsHome, 'keybindings.json'); } diff --git a/src/vs/platform/node/product.ts b/src/vs/platform/node/product.ts index da463d7114d..aec3cd8a91a 100644 --- a/src/vs/platform/node/product.ts +++ b/src/vs/platform/node/product.ts @@ -20,6 +20,7 @@ export interface IProductConfiguration { quality?: string; commit?: string; settingsSearchBuildId?: number; + settingsSearchUrl?: string; date: string; extensionsGallery: { serviceUrl: string; diff --git a/src/vs/workbench/electron-browser/main.contribution.ts b/src/vs/workbench/electron-browser/main.contribution.ts index 158070697e9..c7b3f2fc56d 100644 --- a/src/vs/workbench/electron-browser/main.contribution.ts +++ b/src/vs/workbench/electron-browser/main.contribution.ts @@ -227,28 +227,10 @@ let workbenchProperties: { [path: string]: IJSONSchema; } = { }; if (product.quality !== 'stable') { - workbenchProperties['workbench.settings.experimentalFuzzySearchEndpoint'] = { - 'type': 'string', - 'description': nls.localize('experimentalFuzzySearchEndpoint', "Indicates the endpoint to use for the experimental settings search."), - 'default': '' - }; - - workbenchProperties['workbench.settings.experimentalFuzzySearchKey'] = { - 'type': 'string', - 'description': nls.localize('experimentalFuzzySearchKey', "Indicates the key to use for the experimental settings search."), - 'default': '' - }; - - workbenchProperties['workbench.settings.experimentalFuzzySearchBoost'] = { - 'type': 'number', - 'description': 'Indicates the amount to boost the "literal" component of the query. Temporary.', - 'default': 10 - }; - - workbenchProperties['workbench.settings.experimentalFuzzySearchAutoIngestFeedback'] = { + workbenchProperties['workbench.settings.enableNaturalLanguageSearch'] = { 'type': 'boolean', - 'description': 'Indicates whether feedback from this client should be automatically ingested.', - 'default': false + 'description': nls.localize('enableNaturalLanguageSettingsSearch', "Controls whether to enable the natural language search mode for settings."), + 'default': true }; } diff --git a/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts b/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts index 8e6d61d3094..2c444763c33 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts @@ -147,7 +147,7 @@ export class PreferencesEditor extends BaseEditor { showFuzzyToggle: true, showResultCount: true })); - this.searchWidget.setFuzzyToggleVisible(this.searchProvider.remoteSearchEnabled); + this.searchWidget.setFuzzyToggleVisible(this.searchProvider.remoteSearchAllowed); this.searchWidget.fuzzyEnabled = this.memento['fuzzyEnabled']; this._register(this.searchProvider.onRemoteSearchEnablementChanged(enabled => this.searchWidget.setFuzzyToggleVisible(enabled))); this._register(this.searchWidget.onDidChange(value => this.onInputChanged())); @@ -559,7 +559,7 @@ class PreferencesRenderers extends Disposable { const prefSearchP = searchModel.filterPreferences(preferencesRenderer.preferencesModel); return prefSearchP.then(filterResult => { - preferencesRenderer.filterPreferences(filterResult, this.searchProvider.remoteSearchEnabled); + preferencesRenderer.filterPreferences(filterResult, this.searchProvider.remoteSearchAllowed); return filterResult; }); } diff --git a/src/vs/workbench/parts/preferences/browser/preferencesSearch.ts b/src/vs/workbench/parts/preferences/browser/preferencesSearch.ts index 3ff00898471..2a2d3e9f566 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesSearch.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesSearch.ts @@ -18,8 +18,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' export interface IEndpointDetails { urlBase: string; - key: string; - boost: number; + key?: string; } export class PreferencesSearchProvider { @@ -30,25 +29,34 @@ export class PreferencesSearchProvider { @IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService, @IEnvironmentService private environmentService: IEnvironmentService ) { - configurationService.onDidChangeConfiguration(() => this._onRemoteSearchEnablementChanged.fire(this.remoteSearchEnabled)); + configurationService.onDidChangeConfiguration(() => this._onRemoteSearchEnablementChanged.fire(this.remoteSearchAllowed)); } - get remoteSearchEnabled(): boolean { + get remoteSearchAllowed(): boolean { if (this.environmentService.appQuality === 'stable') { return false; } - const endpoint = this.endpoint; - return !!endpoint.urlBase && !!endpoint.key; + const workbenchSettings = this.configurationService.getValue().workbench.settings; + if (!workbenchSettings.enableNaturalLanguageSearch) { + return false; + } + + return !!this.endpoint.urlBase; } get endpoint(): IEndpointDetails { const workbenchSettings = this.configurationService.getValue().workbench.settings; - return { - urlBase: workbenchSettings.experimentalFuzzySearchEndpoint, - key: workbenchSettings.experimentalFuzzySearchKey, - boost: workbenchSettings.experimentalFuzzySearchBoost - }; + if (workbenchSettings.experimentalFuzzySearchEndpoint) { + return { + urlBase: workbenchSettings.experimentalFuzzySearchEndpoint, + key: workbenchSettings.experimentalFuzzySearchKey + }; + } else { + return { + urlBase: this.environmentService.settingsSearchUrl + }; + } } startSearch(filter: string, remote: boolean): PreferencesSearchModel { @@ -147,7 +155,6 @@ class RemoteSearchProvider { private getSettingsFromBing(filter: string, endpoint: IEndpointDetails): TPromise { const url = prepareUrl(filter, endpoint, this.environmentService.settingsSearchBuildId); - console.log('fetching: ' + url); const start = Date.now(); const p = fetch(url, { headers: new Headers({ @@ -160,7 +167,6 @@ class RemoteSearchProvider { .then(result => { const timestamp = Date.now(); const duration = timestamp - start; - console.log('time: ' + duration / 1000); const suggestions = (result.value || []) .map(r => ({ name: r.setting || r.Setting, @@ -200,18 +206,21 @@ function escapeSpecialChars(query: string): string { function prepareUrl(query: string, endpoint: IEndpointDetails, buildNumber: number): string { query = escapeSpecialChars(query); - const boost = endpoint.boost || 1; + const boost = 10; const userQuery = `(${query})^${boost}`; // Appending Fuzzy after each word. query = query.replace(/\ +/g, '~ ') + '~'; - let url = `${endpoint.urlBase}?${API_VERSION}&search=${encodeURIComponent(userQuery + ' || ' + query)}&${QUERY_TYPE}&${SCORING_PROFILE}`; + let url = `${endpoint.urlBase}?search=${encodeURIComponent(userQuery + ' || ' + query)}`; + if (endpoint.key) { + url += `&${API_VERSION}&${QUERY_TYPE}&${SCORING_PROFILE}`; + } if (buildNumber) { url += `&$filter startbuildno le ${buildNumber} and endbuildno ge ${buildNumber}`; } - return url; + return url + `&$filter=startbuildno le 119000227 and endbuildno ge 119000227`; } class SettingMatches { diff --git a/src/vs/workbench/parts/preferences/common/preferences.ts b/src/vs/workbench/parts/preferences/common/preferences.ts index 95ce9e9b8ec..e7399502d12 100644 --- a/src/vs/workbench/parts/preferences/common/preferences.ts +++ b/src/vs/workbench/parts/preferences/common/preferences.ts @@ -23,8 +23,8 @@ export interface IWorkbenchSettingsConfiguration { openDefaultSettings: boolean; experimentalFuzzySearchEndpoint: string; experimentalFuzzySearchKey: string; - experimentalFuzzySearchBoost: number; experimentalFuzzySearchAutoIngestFeedback: boolean; + enableNaturalLanguageSearch: boolean; } }; } -- GitLab