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

Add event for when tree tokens change #228593

Merged
merged 1 commit into from
Sep 18, 2024
Merged

Conversation

alexr00
Copy link
Member

@alexr00 alexr00 commented Sep 13, 2024

Part of #210475

@alexr00 alexr00 requested a review from hediet September 13, 2024 19:18
@alexr00 alexr00 self-assigned this Sep 13, 2024
@alexr00 alexr00 enabled auto-merge (squash) September 13, 2024 19:18
@vs-code-engineering vs-code-engineering bot added this to the September 2024 milestone Sep 13, 2024
@@ -102,7 +105,13 @@ export class TextModelTreeSitter extends Disposable {
}

private async _onDidChangeContent(treeSitterTree: TreeSitterParseResult, changes: IModelContentChange[]) {
return treeSitterTree.onDidChangeContent(this.model, changes);
const oldTree = treeSitterTree.tree?.copy();
await treeSitterTree.onDidChangeContent(this.model, changes);
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if that is a problem here, but subsequent onDidChangeContent event calls can make multiple promises to get stuck here.
Then line 110 might cause a race condition, depending on which promise resolves first.

const oldTree = treeSitterTree.tree?.copy();
await treeSitterTree.onDidChangeContent(this.model, changes);
if (oldTree && treeSitterTree.tree) {
const diff = oldTree.getChangedRanges(treeSitterTree.tree);
Copy link
Member

Choose a reason for hiding this comment

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

This diff propagates all the way up to the tokenizer.
However, I'm not sure how "local" the tokenization rules are.
Lets say you have this class:

class Foo {
	public bar() {}
}

Now, you change public to private:

class Foo {
	private bar() {}
}

In the tree, the keyword public now changed to private, so that's (hopefully) the range you'd get.
However, it might not be sufficient to only re-render the private token now, as there might be a rule which makes bar bold depending on if the method is public or private.

@alexr00 alexr00 merged commit 3ea0cbb into main Sep 18, 2024
7 checks passed
@alexr00 alexr00 deleted the alexr00/territorial-gamefowl branch September 18, 2024 08:16
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants