Skip to content

Commit

Permalink
#38329 Always compute most relevant line offset
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Nov 14, 2017
1 parent c87f59c commit 9fd5625
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/vs/workbench/parts/preferences/common/preferencesModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
import { assign } from 'vs/base/common/objects';
import { tail } from 'vs/base/common/arrays';
import URI from 'vs/base/common/uri';
import { IReference } from 'vs/base/common/lifecycle';
import { IReference, Disposable } from 'vs/base/common/lifecycle';
import Event, { Emitter } from 'vs/base/common/event';
import { Registry } from 'vs/platform/registry/common/platform';
import { visit, JSONVisitor } from 'vs/base/common/json';
Expand Down Expand Up @@ -499,17 +499,20 @@ export class WorkspaceConfigModel extends SettingsEditorModel implements ISettin
}
}

export class DefaultSettings {

export class DefaultSettings extends Disposable {

private _allSettingsGroups: ISettingsGroup[];
private _content: string;
private _settingsByName: Map<string, ISetting>;

private _onDidChange: Emitter<void> = this._register(new Emitter<void>());
readonly onDidChange: Event<void> = this._onDidChange.event;

constructor(
private _mostCommonlyUsedSettingsKeys: string[],
readonly configurationScope: ConfigurationScope,
) {
super();
}

public get content(): string {
Expand All @@ -527,12 +530,16 @@ export class DefaultSettings {
}

parse(): string {
const currentContent = this._content;
const configurations = Registry.as<IConfigurationRegistry>(Extensions.Configuration).getConfigurations().slice();
const settingsGroups = this.removeEmptySettingsGroups(configurations.sort(this.compareConfigurationNodes).reduce((result, config, index, array) => this.parseConfig(config, result, array), []));
this.initAllSettingsMap(settingsGroups);
const mostCommonlyUsed = this.getMostCommonlyUsedSettings(settingsGroups);
this._allSettingsGroups = [mostCommonlyUsed, ...settingsGroups];
this._content = this.toContent(mostCommonlyUsed, settingsGroups);
if (this._content !== currentContent) {
this._onDidChange.fire();
}
return this._content;
}

Expand Down Expand Up @@ -678,9 +685,6 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements

private _model: IModel;
private _settingsByName: Map<string, ISetting>;
private _mostRelevantLineOffset: number;

private _settingsGroups: ISettingsGroup[];

private _onDidChangeGroups: Emitter<void> = this._register(new Emitter<void>());
readonly onDidChangeGroups: Event<void> = this._onDidChangeGroups.event;
Expand All @@ -689,28 +693,23 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements
private _uri: URI,
reference: IReference<ITextEditorModel>,
readonly configurationScope: ConfigurationScope,
defaultSettings: DefaultSettings
private readonly defaultSettings: DefaultSettings
) {
super();
this._settingsGroups = defaultSettings.settingsGroups;

this._register(defaultSettings.onDidChange(() => this._onDidChangeGroups.fire()));
this._model = reference.object.textEditorModel;
this._register(this.onDispose(() => reference.dispose()));
this._register(this._model.onDidChangeContent(() => {
this._settingsGroups = defaultSettings.settingsGroups;
this._onDidChangeGroups.fire();
}));

this.initAllSettingsMap();
this._mostRelevantLineOffset = tail(this.settingsGroups).range.endLineNumber + 2;
}

public get uri(): URI {
return this._uri;
}

public get settingsGroups(): ISettingsGroup[] {
return this._settingsGroups;
return this.defaultSettings.settingsGroups;
}

public filterSettings(filter: string, groupFilter: IGroupFilter, settingFilter: ISettingFilter, mostRelevantSettings?: string[]): IFilterResult {
Expand All @@ -733,7 +732,8 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements
}

private renderMostRelevantSettings(mostRelevantSettings: string[]): ISettingsGroup {
const builder = new SettingsContentBuilder(this._mostRelevantLineOffset - 1);
const mostRelevantLineOffset = tail(this.settingsGroups).range.endLineNumber + 2;
const builder = new SettingsContentBuilder(mostRelevantLineOffset - 1);
builder.pushLine(',');
const mostRelevantGroup = this.getMostRelevantSettings(mostRelevantSettings);
builder.pushGroups([mostRelevantGroup]);
Expand All @@ -746,7 +746,7 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements
{
text: mostRelevantContent,
forceMoveMarkers: false,
range: new Range(this._mostRelevantLineOffset, 1, mostRelevantEndLine, 1),
range: new Range(mostRelevantLineOffset, 1, mostRelevantEndLine, 1),
identifier: { major: 1, minor: 0 }
}
]);
Expand Down

0 comments on commit 9fd5625

Please sign in to comment.