-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
MEGA-ISSUE: Syntax highlighting in language-javascript
#875
Comments
There have already been a handful of JavaScript fixes in #859 (check the commit descriptions for details), and I've upgraded the |
I'm see some inconsistency in identifier coloring in JS. In particular, variables are scoped and colored differently inside and outside of "blocks", and also depending on how they're used. Here's an example (this is the Firefox theme, but he results are the same for the built in themes that I tried) Notice how
In CSS/terms, this means that The legacy tree-sitter highlighter does not appear to apply the I note that in your write up on scopes you say that you want "to avoid the temptation to classify every remaining identifier as variable.other and thereby dilute the significance of the scope", and I totally get that, but this is a case where semantically similar/identical things are looking different. Is this a case where themes should be updated, or what purpose is |
Oh, BTW I tried this out on the latest version of #859 and I didn't see it changing. The screenshot above was taken while running that branch. (At least to the best of my knowledge. 😄 ) |
You had me nervous for a second. The For instance, the whole file is scoped as Anything inside a block gets scoped as |
This post illustrates the sorts of things you can do with |
In the "Solarized Dark" theme, I kind of like I tend to think Legacy Tree-sitter(I like this highlighting) Modern Tree-sitter(Seems less contrasty to me, less variety of color leading to slightly less readable/skimmable code? Particularly, Code Snippet |
The legacy Tree-sitter grammar picks such utterly ridiculous scope names for both In the legacy grammar, The modern grammar scopes these as Drop this into your user stylesheet: @import "syntax-variables";
.syntax--source.syntax--js {
.syntax--builtin.syntax--console {
color: @syntax-color-function;
}
} |
Eesh. Nice catch. I'll be able to make unit tests out of these examples. (Once I fix this bug, of course — which does not seem like it will be easy!) |
@asiloisad, a fix for this issue is now present in #941. We analyze the tree to determine when we need to adjust indentation after a newline is inserted. But Pulsar has always wanted to answer that question as soon as possible — right after the given buffer change is made. Even if the change is part of a transaction. That's painful for modern Tree-sitter because it would require an immediate and synchronous tree reparse. Instead, we try to get away with waiting until the transaction is over, then auto-indenting the given row. But this isn't always correct, because a transaction can contain any number of arbitrary edits. By the end of the transaction, the content that we wanted to auto-indent may no longer be on the same row that it was on when we were first asked! So in complex cases, we give up on the atomic adjustments and just do an auto-indent of the entire range affected by the transaction. Previously, our heuristic for determining when to perform this fallback was simple: if a transaction contains more than one edit, use the fallback behavior. But that logic triggers in a multi-cursor edit scenario such as the one in your example. Since the edit increases the indent on line 2, invoking auto-indentation over the entire buffer range affected by the three edits will set the indention on line 4 to match that of line 2, and the indentation on line 7 to match that of line 5. Hence the ever-increasing indentation. This happens even though we can perform each of the three indentation adjustments just fine, since they're on different lines and don't get in each other's way. So the new heuristic is a bit laxer: if the content of the line is identical to what it was in the middle of the transaction, then it's still safe to do an atomic re-indent. The fallback option of a transaction-wide auto-indent will sometimes fail to produce the outcome that the user wants, as in your example. I hate that fallback. It's a better outcome than giving up on trying to auto-indent altogether — if we'd done that in your example, none of the But the other option is bad, too. We could disable async indentation altogether, and get indentation behavior that's just as good as what we get in the other modes. But then your example would involve forcibly re-parsing the tree each time we inserted a newline — three times total — and then once more at the end of the transaction. Those are three “throwaway” trees that we can't use for any other purpose. And even in your example that's probably the best approach! Three re-parses isn't that bad; the user won't even notice it! The hard part is that the decision point inside One option might be to start out in synchronous indent mode, but only allow ourselves a certain number of re-parses (or a certain amount of total re-parse time) in a given transaction before we decide that our budget has been exceeded and flip to async indent mode. At any rate, this change in heuristic is a good thing and makes multi-cursor edits less tricky. And it kicks the can down the road. Thanks for the report! |
@asiloisad: Actually, I rubber-ducked myself into the idea of a time budget in the previous comment — then decided to implement it while my brain still found the idea fascinating. This is now also part of #941! So your example should now work just fine for two different reasons: first, because the edits in question will result in synchronous indentation decisions, since the tree re-parses that are needed won't come close to exceeding the re-parse time budget. Second, because even if we were forced to fall back to async indent, we recognize your example as one in which we can still auto-indent three lines atomically because their contents won't have changed between the original indent hinting request and the end of the transaction. The new test case proves this. |
thanks you for investigation, a detailed explanation and fix. the logic around auto-indent is quite hard. I'm waiting for 1.115 :) It's should resolve the same problem, but in Python #880 👍. |
IMPORTANT: Some issues have already been fixed!
If you’re still on the regular 1.113 release, you might be suffering from a problem that has already been fixed. Many fixes landed on
master
in #859. You are encouraged to download the latest rolling release — both (a) to see whether what you’re reporting has been fixed, and (b) so that you can enjoy the fixes that have been reported since the 1.113 release.This will serve as a catch-all issue for any problems you may encounter with syntax highlighting in JavaScript files (
language-javascript
). If you have problems with the new syntax highlighting (or folds, or indents) that are specific tojs
orjsx
files, keep reading.Something isn't highlighting correctly!
If there are any highlighting regressions since 1.113:
First, please scroll down and see if someone else has reported the issue. If not, please comment with
I want to go back to the old highlighting!
You can easily opt out of the new Tree-sitter highlighting for any language, but first please:
To revert to the old Tree-sitter grammar for this language only, add the following to your
config.cson
:To revert to the TextMate-style grammar for this language only, add the following to your
config.cson
:The text was updated successfully, but these errors were encountered: