-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Conversation
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks right. The higher up we find the identifier list in the scope, the more relevant rule is.
I think there's another issue: We should start looking from top to bottom
If the stack repeats, we would find the first occurrence, not the last. But the last one would have a higher score, which might beat other rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this regressed in https://github.com/microsoft/vscode/pull/229951/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also thought https://github.com/microsoft/vscode/pull/229951/files could have regressed this, but I couldn't find a change in there that would have caused this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are already going from top to bottom, since the for loop starts at the last index of the the scopes
.
Edit, no we're not.
No description provided.