Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer RichEditBrackets creation #38659

Merged
merged 3 commits into from Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/vs/editor/common/controller/cursorCommon.ts
Expand Up @@ -82,7 +82,9 @@ export class CursorConfiguration {
public readonly autoClosingPairsOpen: CharacterMap;
public readonly autoClosingPairsClose: CharacterMap;
public readonly surroundingPairs: CharacterMap;
public readonly electricChars: { [key: string]: boolean; };

private readonly _languageIdentifier: LanguageIdentifier;
private _electricChars: { [key: string]: boolean; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit-pick: To avoid a hidden class mutation at runtime, I prefer to have all members initialized in the ctor. Can you please add this._electricChars = null;


public static shouldRecreate(e: IConfigurationChangedEvent): boolean {
return (
Expand All @@ -102,6 +104,8 @@ export class CursorConfiguration {
modelOptions: TextModelResolvedOptions,
configuration: IConfiguration
) {
this._languageIdentifier = languageIdentifier;

let c = configuration.editor;

this.readOnly = c.readOnly;
Expand All @@ -119,14 +123,7 @@ export class CursorConfiguration {
this.autoClosingPairsOpen = {};
this.autoClosingPairsClose = {};
this.surroundingPairs = {};
this.electricChars = {};

let electricChars = CursorConfiguration._getElectricCharacters(languageIdentifier);
if (electricChars) {
for (let i = 0; i < electricChars.length; i++) {
this.electricChars[electricChars[i]] = true;
}
}
this._electricChars = null;

let autoClosingPairs = CursorConfiguration._getAutoClosingPairs(languageIdentifier);
if (autoClosingPairs) {
Expand All @@ -144,6 +141,19 @@ export class CursorConfiguration {
}
}

public get electricChars() {
if (!this._electricChars) {
this._electricChars = {};
let electricChars = CursorConfiguration._getElectricCharacters(this._languageIdentifier);
if (electricChars) {
for (let i = 0; i < electricChars.length; i++) {
this._electricChars[electricChars[i]] = true;
}
}
}
return this._electricChars;
}

public normalizeIndentation(str: string): string {
return TextModel.normalizeIndentation(str, this.tabSize, this.insertSpaces);
}
Expand Down
28 changes: 21 additions & 7 deletions src/vs/editor/common/modes/languageConfigurationRegistry.ts
Expand Up @@ -46,18 +46,23 @@ export interface IIndentConverter {
export class RichEditSupport {

private readonly _conf: LanguageConfiguration;
private readonly _languageIdentifier: LanguageIdentifier;
private _brackets: RichEditBrackets;
private _electricCharacter: BracketElectricCharacterSupport;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Can you please add this._brackets = null; this._electricCharacter = null;


public readonly electricCharacter: BracketElectricCharacterSupport;
public readonly comments: ICommentsConfiguration;
public readonly characterPair: CharacterPairSupport;
public readonly wordDefinition: RegExp;
public readonly onEnter: OnEnterSupport;
public readonly indentRulesSupport: IndentRulesSupport;
public readonly brackets: RichEditBrackets;
public readonly indentationRules: IndentationRule;
public readonly foldingRules: FoldingRules;

constructor(languageIdentifier: LanguageIdentifier, previous: RichEditSupport, rawConf: LanguageConfiguration) {
this._languageIdentifier = languageIdentifier;

this._brackets = null;
this._electricCharacter = null;

let prev: LanguageConfiguration = null;
if (previous) {
Expand All @@ -66,16 +71,11 @@ export class RichEditSupport {

this._conf = RichEditSupport._mergeConf(prev, rawConf);

if (this._conf.brackets) {
this.brackets = new RichEditBrackets(languageIdentifier, this._conf.brackets);
}

this.onEnter = RichEditSupport._handleOnEnter(this._conf);

this.comments = RichEditSupport._handleComments(this._conf);

this.characterPair = new CharacterPairSupport(this._conf);
this.electricCharacter = new BracketElectricCharacterSupport(this.brackets, this.characterPair.getAutoClosingPairs(), this._conf.__electricCharacterSupport);

this.wordDefinition = this._conf.wordPattern || DEFAULT_WORD_REGEXP;

Expand All @@ -87,6 +87,20 @@ export class RichEditSupport {
this.foldingRules = this._conf.folding || {};
}

public get brackets(): RichEditBrackets {
if (!this._brackets && this._conf.brackets) {
this._brackets = new RichEditBrackets(this._languageIdentifier, this._conf.brackets);
}
return this._brackets;
}

public get electricCharacter(): BracketElectricCharacterSupport {
if (!this._electricCharacter) {
this._electricCharacter = new BracketElectricCharacterSupport(this.brackets, this.characterPair.getAutoClosingPairs(), this._conf.__electricCharacterSupport);
}
return this._electricCharacter;
}

private static _mergeConf(prev: LanguageConfiguration, current: LanguageConfiguration): LanguageConfiguration {
return {
comments: (prev ? current.comments || prev.comments : current.comments),
Expand Down