This commit is contained in:
Sandeep Somavarapu 2017-07-25 13:23:07 +05:30
parent fed03b66ac
commit ff52b7e5f2
5 changed files with 54 additions and 14 deletions

View file

@ -35,6 +35,10 @@
"fileMatch": "vscode://defaultsettings/settings.json",
"url": "vscode://schemas/settings"
},
{
"fileMatch": "vscode://defaultsettings/resourceSettings.json",
"url": "vscode://schemas/settings/resource"
},
{
"fileMatch": "vscode://settings/workspaceSettings.json",
"url": "vscode://schemas/settings"
@ -80,4 +84,4 @@
"devDependencies": {
"@types/node": "^7.0.4"
}
}
}

View file

@ -811,7 +811,7 @@ class SettingsEditorContribution extends Disposable implements ISettingsEditorCo
createPreferencesRenderer(associatedPreferencesModelUri: URI): TPromise<IPreferencesRenderer<ISetting>> {
this.disposePreferencesRenderer();
this.preferencesRenderer = TPromise.join<any>([this.preferencesService.createPreferencesEditorModel(this.preferencesService.defaultSettingsResource), this.preferencesService.createPreferencesEditorModel(this.editor.getModel().uri)])
this.preferencesRenderer = TPromise.join<any>([this.preferencesService.createPreferencesEditorModel(associatedPreferencesModelUri), this.preferencesService.createPreferencesEditorModel(this.editor.getModel().uri)])
.then(([defaultSettingsModel, settingsModel]) => {
if (settingsModel instanceof SettingsEditorModel) {
switch (settingsModel.configurationTarget) {

View file

@ -40,6 +40,7 @@ import { Position, IPosition } from 'vs/editor/common/core/position';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IJSONEditingService } from "vs/workbench/services/configuration/common/jsonEditing";
import { ConfigurationScope } from "vs/platform/configuration/common/configurationRegistry";
interface IWorkbenchSettingsConfiguration {
@ -100,8 +101,9 @@ export class PreferencesService extends Disposable implements IPreferencesServic
});
}
readonly defaultSettingsResource = URI.from({ scheme: network.Schemas.vscode, authority: 'defaultsettings', path: '/settings.json' });
readonly defaultKeybindingsResource = URI.from({ scheme: network.Schemas.vscode, authority: 'defaultsettings', path: '/keybindings.json' });
private readonly defaultWorkbenchSettingsResource = URI.from({ scheme: network.Schemas.vscode, authority: 'defaultsettings', path: '/settings.json' });
private readonly defaultResourceSettingsResource = URI.from({ scheme: network.Schemas.vscode, authority: 'defaultsettings', path: '/resourceSettings.json' });
private readonly defaultKeybindingsResource = URI.from({ scheme: network.Schemas.vscode, authority: 'defaultsettings', path: '/keybindings.json' });
private readonly workspaceConfigSettingsResource = URI.from({ scheme: network.Schemas.vscode, authority: 'settings', path: '/workspaceSettings.json' });
get userSettingsResource(): URI {
@ -127,11 +129,22 @@ export class PreferencesService extends Disposable implements IPreferencesServic
return promise;
}
if (this.defaultSettingsResource.fsPath === uri.fsPath) {
if (this.defaultWorkbenchSettingsResource.fsPath === uri.fsPath) {
promise = TPromise.join<any>([this.extensionService.onReady(), this.fetchMostCommonlyUsedSettings()])
.then(result => {
const mostCommonSettings = result[1];
const model = this.instantiationService.createInstance(DefaultSettingsEditorModel, uri, mostCommonSettings);
const model = this.instantiationService.createInstance(DefaultSettingsEditorModel, uri, mostCommonSettings, ConfigurationScope.WORKBENCH);
return model;
});
this.defaultPreferencesEditorModels.set(uri, promise);
return promise;
}
if (this.defaultResourceSettingsResource.fsPath === uri.fsPath) {
promise = TPromise.join<any>([this.extensionService.onReady(), this.fetchMostCommonlyUsedSettings()])
.then(result => {
const mostCommonSettings = result[1];
const model = this.instantiationService.createInstance(DefaultSettingsEditorModel, uri, mostCommonSettings, ConfigurationScope.RESOURCE);
return model;
});
this.defaultPreferencesEditorModels.set(uri, promise);
@ -189,7 +202,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
if (activeEditorInput instanceof PreferencesEditorInput) {
return this.getOrCreateEditableSettingsEditorInput(target, this.getEditableSettingsURI(target, resource))
.then(toInput => {
const replaceWith = new PreferencesEditorInput(this.getPreferencesEditorInputName(target, resource), toInput.getDescription(), this.instantiationService.createInstance(DefaultPreferencesEditorInput, this.defaultSettingsResource), toInput);
const replaceWith = new PreferencesEditorInput(this.getPreferencesEditorInputName(target, resource), toInput.getDescription(), this.instantiationService.createInstance(DefaultPreferencesEditorInput, this.getDefaultSettingsResource(target)), toInput);
return this.editorService.replaceEditors([{
toReplace: this.lastOpenedSettingsInput,
replaceWith
@ -240,7 +253,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
return this.getOrCreateEditableSettingsEditorInput(configurationTarget, resource)
.then(editableSettingsEditorInput => {
if (openDefaultSettings) {
const defaultPreferencesEditorInput = this.instantiationService.createInstance(DefaultPreferencesEditorInput, this.defaultSettingsResource);
const defaultPreferencesEditorInput = this.instantiationService.createInstance(DefaultPreferencesEditorInput, this.getDefaultSettingsResource(configurationTarget));
const preferencesEditorInput = new PreferencesEditorInput(this.getPreferencesEditorInputName(configurationTarget, resource), editableSettingsEditorInput.getDescription(), defaultPreferencesEditorInput, <EditorInput>editableSettingsEditorInput);
this.lastOpenedSettingsInput = preferencesEditorInput;
return this.editorService.openEditor(preferencesEditorInput, { pinned: true });
@ -249,6 +262,13 @@ export class PreferencesService extends Disposable implements IPreferencesServic
});
}
private getDefaultSettingsResource(configurationTarget: ConfigurationTarget): URI {
if (configurationTarget === ConfigurationTarget.FOLDER) {
return this.defaultResourceSettingsResource;
}
return this.defaultWorkbenchSettingsResource;
}
private getPreferencesEditorInputName(target: ConfigurationTarget, resource: URI): string {
const name = getSettingsTargetName(target, resource, this.contextService);
return target === ConfigurationTarget.FOLDER ? nls.localize('folderSettingsName', "{0} (Folder Settings)", name) : name;

View file

@ -68,10 +68,8 @@ export const IPreferencesService = createDecorator<IPreferencesService>('prefere
export interface IPreferencesService {
_serviceBrand: any;
defaultSettingsResource: URI;
userSettingsResource: URI;
workspaceSettingsResource: URI;
defaultKeybindingsResource: URI;
resolveContent(uri: URI): TPromise<string>;
createPreferencesEditorModel<T>(uri: URI): TPromise<IPreferencesEditorModel<T>>;

View file

@ -15,7 +15,7 @@ import { visit, JSONVisitor } from 'vs/base/common/json';
import { IModel } from 'vs/editor/common/editorCommon';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { EditorModel } from 'vs/workbench/common/editor';
import { IConfigurationNode, IConfigurationRegistry, Extensions, OVERRIDE_PROPERTY_PATTERN, IConfigurationPropertySchema } from 'vs/platform/configuration/common/configurationRegistry';
import { IConfigurationNode, IConfigurationRegistry, Extensions, OVERRIDE_PROPERTY_PATTERN, IConfigurationPropertySchema, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
import { ISettingsEditorModel, IKeybindingsEditorModel, ISettingsGroup, ISetting, IFilterResult, ISettingsSection } from 'vs/workbench/parts/preferences/common/preferences';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
@ -598,7 +598,7 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements
private _content: string;
private _contentByLines: string[];
constructor(private _uri: URI, private _mostCommonlyUsedSettingsKeys: string[]) {
constructor(private _uri: URI, private _mostCommonlyUsedSettingsKeys: string[], private configurationScope: ConfigurationScope) {
super();
}
@ -643,7 +643,7 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements
private parse() {
const configurations = Registry.as<IConfigurationRegistry>(Extensions.Configuration).getConfigurations().slice();
const settingsGroups = configurations.sort(this.compareConfigurationNodes).reduce((result, config, index, array) => this.parseConfig(config, result, array), []);
const settingsGroups = this.removeEmptySettingsGroups(configurations.sort(this.compareConfigurationNodes).reduce((result, config, index, array) => this.parseConfig(config, result, array), []));
const mostCommonlyUsed = this.getMostCommonlyUsedSettings(settingsGroups);
this._allSettingsGroups = [mostCommonlyUsed, ...settingsGroups];
this._content = this.toContent(mostCommonlyUsed, settingsGroups);
@ -721,11 +721,22 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements
return result;
}
private removeEmptySettingsGroups(settingsGroups: ISettingsGroup[]): ISettingsGroup[] {
const result = [];
for (const settingsGroup of settingsGroups) {
settingsGroup.sections = settingsGroup.sections.filter(section => section.settings.length > 0);
if (settingsGroup.sections.length) {
result.push(settingsGroup);
}
}
return result;
}
private parseSettings(settingsObject: { [path: string]: IConfigurationPropertySchema; }): ISetting[] {
let result = [];
for (let key in settingsObject) {
const prop = settingsObject[key];
if (!prop.deprecationMessage) {
if (!prop.deprecationMessage && this.matchesScope(prop)) {
const value = prop.default;
const description = (prop.description || '').split('\n');
const overrides = OVERRIDE_PROPERTY_PATTERN.test(key) ? this.parseOverrideSettings(prop.default) : [];
@ -739,6 +750,13 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements
return Object.keys(overrideSettings).map((key) => ({ key, value: overrideSettings[key], description: [], range: null, keyRange: null, valueRange: null, descriptionRanges: [], overrides: [] }));
}
private matchesScope(property: IConfigurationNode): boolean {
if (this.configurationScope === ConfigurationScope.WORKBENCH) {
return true;
}
return property.scope === this.configurationScope;
}
private compareConfigurationNodes(c1: IConfigurationNode, c2: IConfigurationNode): number {
if (typeof c1.order !== 'number') {
return 1;