提交 91a20206 编写于 作者: R Rob Lourens

Provide for using settings search url from vscode-distro, make relevant settings invisible

上级 f7bb5573
......@@ -111,4 +111,6 @@ export interface IEnvironmentService {
installSource: string;
disableUpdates: boolean;
disableCrashReporter: boolean;
settingsSearchUrl: string;
}
......@@ -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'); }
......
......@@ -20,6 +20,7 @@ export interface IProductConfiguration {
quality?: string;
commit?: string;
settingsSearchBuildId?: number;
settingsSearchUrl?: string;
date: string;
extensionsGallery: {
serviceUrl: string;
......
......@@ -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
};
}
......
......@@ -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(<ISettingsEditorModel>preferencesRenderer.preferencesModel);
return prefSearchP.then(filterResult => {
preferencesRenderer.filterPreferences(filterResult, this.searchProvider.remoteSearchEnabled);
preferencesRenderer.filterPreferences(filterResult, this.searchProvider.remoteSearchAllowed);
return filterResult;
});
}
......
......@@ -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<IWorkbenchSettingsConfiguration>().workbench.settings;
if (!workbenchSettings.enableNaturalLanguageSearch) {
return false;
}
return !!this.endpoint.urlBase;
}
get endpoint(): IEndpointDetails {
const workbenchSettings = this.configurationService.getValue<IWorkbenchSettingsConfiguration>().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<IFilterMetadata> {
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 {
......
......@@ -23,8 +23,8 @@ export interface IWorkbenchSettingsConfiguration {
openDefaultSettings: boolean;
experimentalFuzzySearchEndpoint: string;
experimentalFuzzySearchKey: string;
experimentalFuzzySearchBoost: number;
experimentalFuzzySearchAutoIngestFeedback: boolean;
enableNaturalLanguageSearch: boolean;
}
};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册