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

Revert "Merge pull request #163958 from microsoft/tyriar/161622_brack… #164571

Merged
merged 1 commit into from Oct 25, 2022
Merged
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
Expand Up @@ -40,8 +40,6 @@ export class BracketPairsTree extends Disposable {
private readonly denseKeyProvider = new DenseKeyProvider<string>();
private readonly brackets = new LanguageAgnosticBracketTokens(this.denseKeyProvider, this.getLanguageConfiguration);

private readonly parseQueue: TextEditInfo[][] = [];

public didLanguageChange(languageId: string): boolean {
return this.brackets.didLanguageChange(languageId);
}
Expand Down Expand Up @@ -92,7 +90,10 @@ export class BracketPairsTree extends Disposable {
toLength(r.toLineNumber - r.fromLineNumber + 1, 0)
)
);
this.queueParsing(edits);
this.astWithTokens = this.parseDocumentFromTextBuffer(edits, this.astWithTokens, false);
if (!this.initialAstWithoutTokens) {
this.didChangeEmitter.fire();
}
}

public handleContentChanged(change: IModelContentChangedEvent) {
Expand All @@ -104,23 +105,11 @@ export class BracketPairsTree extends Disposable {
lengthOfString(c.text)
);
}).reverse();
this.queueParsing(edits);
}

private queueParsing(edits: TextEditInfo[]): void {
// Queues parsing of the document so that it only runs before the state is actually
// requested, this helps reduce editor input latency by doing parsing lazily instead of eagerly.
this.parseQueue.push(edits);
}

private ensureState() {
for (const edits of this.parseQueue) {
this.astWithTokens = this.parseDocumentFromTextBuffer(edits, this.astWithTokens, false);
if (this.initialAstWithoutTokens) {
this.initialAstWithoutTokens = this.parseDocumentFromTextBuffer(edits, this.initialAstWithoutTokens, false);
}
this.astWithTokens = this.parseDocumentFromTextBuffer(edits, this.astWithTokens, false);
if (this.initialAstWithoutTokens) {
this.initialAstWithoutTokens = this.parseDocumentFromTextBuffer(edits, this.initialAstWithoutTokens, false);
}
this.parseQueue.length = 0;
}

//#endregion
Expand All @@ -138,7 +127,6 @@ export class BracketPairsTree extends Disposable {
}

public getBracketsInRange(range: Range): CallbackIterable<BracketInfo> {
this.ensureState();
const startOffset = toLength(range.startLineNumber - 1, range.startColumn - 1);
const endOffset = toLength(range.endLineNumber - 1, range.endColumn - 1);
return new CallbackIterable(cb => {
Expand All @@ -148,7 +136,6 @@ export class BracketPairsTree extends Disposable {
}

public getBracketPairsInRange(range: Range, includeMinIndentation: boolean): CallbackIterable<BracketPairWithMinIndentationInfo> {
this.ensureState();
const startLength = positionToLength(range.getStartPosition());
const endLength = positionToLength(range.getEndPosition());

Expand All @@ -160,13 +147,11 @@ export class BracketPairsTree extends Disposable {
}

public getFirstBracketAfter(position: Position): IFoundBracket | null {
this.ensureState();
const node = this.initialAstWithoutTokens || this.astWithTokens!;
return getFirstBracketAfter(node, lengthZero, node.length, positionToLength(position));
}

public getFirstBracketBefore(position: Position): IFoundBracket | null {
this.ensureState();
const node = this.initialAstWithoutTokens || this.astWithTokens!;
return getFirstBracketBefore(node, lengthZero, node.length, positionToLength(position));
}
Expand Down