未验证 提交 276f8dfb 编写于 作者: M Matt Bierner 提交者: GitHub

Defer RichEditBrackets creation (#38659)

* Defer RichEditBrackets creation

**Bug**
`RichEditBrackets` are currently created eagerly pretty early in startup. This can be a fairly call as well.

**fix**
Lazily create `RichEditBrackets` instead

* Also defer electricChars in CursorConfiguration

* Init all new members in ctor
上级 73f3e0df
......@@ -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; };
public static shouldRecreate(e: IConfigurationChangedEvent): boolean {
return (
......@@ -102,6 +104,8 @@ export class CursorConfiguration {
modelOptions: TextModelResolvedOptions,
configuration: IConfiguration
) {
this._languageIdentifier = languageIdentifier;
let c = configuration.editor;
this.readOnly = c.readOnly;
......@@ -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) {
......@@ -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);
}
......
......@@ -46,18 +46,23 @@ export interface IIndentConverter {
export class RichEditSupport {
private readonly _conf: LanguageConfiguration;
private readonly _languageIdentifier: LanguageIdentifier;
private _brackets: RichEditBrackets;
private _electricCharacter: BracketElectricCharacterSupport;
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) {
......@@ -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;
......@@ -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),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册