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

Make space for tree sitter syntax highlighting #212592

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

alexr00
Copy link
Member

@alexr00 alexr00 commented May 13, 2024

This PR takes the first steps towards adding tree sitter highlighting. I don't expect that there's much that's very interesting in here as there's no actual tree sitter based support in this PR, it's just about getting some of the uninteresting logistics out of the way to make reviewing subsequent PRs easier.

@alexr00 alexr00 self-assigned this May 13, 2024
@alexr00 alexr00 requested a review from hediet May 13, 2024 10:13
@alexr00 alexr00 enabled auto-merge (squash) May 13, 2024 10:13
@VSCodeTriageBot VSCodeTriageBot added this to the May 2024 milestone May 13, 2024
@alexr00 alexr00 disabled auto-merge May 13, 2024 10:16
Copy link
Member Author

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

@hediet if you would prefer to wait to merge or approve this until you see what the next part looks like, that's also fine for me.

Copy link
Member

@hediet hediet left a comment

Choose a reason for hiding this comment

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

Looks good so far! Left some comments.
I love to iterate and merge quickly, but I think due to its explorative nature, we should make this a WIP PR and only merge it when the architecture is settled.

Comment on lines 52 to 53
private grammarTokens: GrammarTokens | undefined;
private treeSitterTokens: TreeSitterTokens | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to not have a separate field treeSitterTokens, but have a tree sitter implemenation of GrammarTokens (and introducing an abstract class).

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, I will address in an upcoming commit.

Comment on lines 9 to 20
export class TreeSitterTokenizationService implements ITreeSitterTokenizationService {
readonly _serviceBrand: undefined;

constructor() {
// Eventually, this should actually use an extension point to add tree sitter grammars, but for now they are hard coded in core
this._addGrammar('placeholder-language');
}

private _addGrammar(languageId: string) {
TreeSitterTokenizationRegistry.register(languageId, {});
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we should really try to make this available in the monaco-editor as well.
Both to make development easier (with the playground) and to invest into the monaco-editor (which doesn't even have official textmate support, which is very annoying).


private _onDidChangeContent() {
// TODO @alexr00 this is an extremely naive implementation and should absolutely not be pushed to main, it's just a placeholder.
this._tree?.delete();
Copy link
Member Author

Choose a reason for hiding this comment

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

@hediet this is just temporary. I will implement proper content change handling in an upcoming commit.

return tokens;
}

private findMetadata(captureName: string): number {
Copy link
Member Author

Choose a reason for hiding this comment

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

@hediet, do you know if there's a better way to retrieve the token metadata given a scope? Relying on the ColorThemeData is layer breaking. I started trying to move things around to fix the layer breaker, but it quickly got complicated.

@alexr00 alexr00 marked this pull request as draft May 23, 2024 13:21
@alexr00 alexr00 modified the milestones: May 2024, June 2024 May 28, 2024
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.

None yet

4 participants