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

Support targeting multiple scopes in a theme with tree sitter #241703

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexr00
Copy link
Member

@alexr00 alexr00 commented Feb 24, 2025

No description provided.

@alexr00 alexr00 self-assigned this Feb 24, 2025
@alexr00 alexr00 added this to the March 2025 milestone Feb 25, 2025
for (let i = lastIndex; i < scopes.length; i++) {
if (scopesAreMatching(scopes[i], identifier)) {
score = (identifierIndex + 1) * 0x10000 + identifier.length;
score = (i + 1) * 0x10000 + identifier.length;
Copy link
Member Author

Choose a reason for hiding this comment

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

The identifiers are the scopes in a them rule. In this example, they are the scope property here:

{
			"name": "Function declarations",
			"scope": [
				"entity.name.function",
				"support.function",
				"support.constant.handlebars",
				"source.powershell variable.other.member",
				"entity.name.operator.custom-literal"
			],
			"settings": {
				"foreground": "#DCDCAA"
			}
		},

The scopes are the scopes that the token we're trying to find the theme for has. In this code snippet:

new URL('./../../renderer/dist/index.html', import.meta.url);

URL has the following scopes from tree sitter:

new.expr
variable
entity.name.function

By using the identifierIndex the score was using the position of the scope in the theme rule as to calculate the score, and I'm unclear on the intent behind this. Why would it's position in the theme rule influence the score?

This change instead uses the position of the scope in the token's scope list as part of the score, with scopes that are more specific getting greater weight.

@alexr00 alexr00 requested a review from aeschli February 25, 2025 14:07
@alexr00 alexr00 marked this pull request as ready for review February 25, 2025 14:07
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.

1 participant