-
Notifications
You must be signed in to change notification settings - Fork 466
Since July update cause java highlight break #1597
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
Comments
Are you saying semantic highlighting is fine when not debugging? |
after I close and open it sometime it appears fine |
Does the highlighting also "fix" itself after you type a character? Not sure if it's related, but I've seen something very similar happen when applying large changes to the document, such as undo/redo or using git reset --hard. I unfortunately could not find a way to consistently reproduce the issue, but the semantic highlighting broke in the same way as in your screenshot. @ericsia if you could find a way to consistently reproduce the issue, that would help a lot in finding a fix. Does it always happen when debugging? Also, what version of the extension are you using? The latest? |
I also notice that this happens a lot since July, I'm on a mac OSX 10.12.6. |
@clankill3r can you provide some more info about what you're doing when the issue occurs? It would make the debugging process a lot easier if we had a way to reproduce the issue. And by "since July", do you mean the 0.65.0 update or do you not know which version you were using? Personally I've seen this issue occur earlier than 0.65.0, but I couldn't find a way to consistently reproduce it. It seemed to occur somewhat randomly when applying large changes to the document. Spamming undo/redo sometimes reproduced it, but there was not pattern to it. |
most accurately I didn't know since when do I turn it on. During last 2 update if I didn't rmb wrongly, I saw VS Code prompt me a msg to enable semantic highlight. So I go and turn it on. There is where I notice the highlights broken. |
During I start typing code from scratch I think. When I added comment, add more code then it might occurs |
Ok, that strengthens my belief that this issue was not introduced via any of my changes in 0.65.0, and has been present since the initial implementation. Again, if someone could provide a way to consistently reproduce this issue (via steps), that would make the debugging process a lot less time-consuming. (Meaning a fix can be released sooner.) @ericsia how often do you estimate that this issue appears for you? And what's the connection between this issue and debug mode? Are you saying that the issue only appears when debugging, or that it appears more often when debugging? |
The color highlight when get messed like that doesn't go back to normal (when stop debug) until I reopen vscode again. I am also trying hard to find how to reproduce it but right now I'm not writing any code atm. |
While I have not come up with a reliable way to reproduce this issue, it did occur again during development, so I thought I'd share another screenshot. For me it occurred quite randomly when typing code, possibly as an effect of pasting ~10 lines of code, but I'm not sure yet whether the two were related. The bug doesn't happen very often, but it's still annoying the few times where it does. What's interesting to note is that just like the screenshot shared in the first comment of this issue, the tokens are not completely wrong, just offset by a few characters. Weirdly enough, the The issue goes away as soon as new semantic tokens are requested, so all you have to do is type a character and the highlighting is no longer broken. |
This issue has proven hard to debug, but I believe I've found a possible explanation, even if I don't know the exact cause or how to fix it. It seems to occur in some rare cases, when changes are made to the document during a request for semantic tokens. The most reliable I've been able to reproduce it is to make multiple small changes to the document in rapid succession, but the timing required to reproduce the issue is very specific. I would also guess that the issue can occur when there is a change to the document during a particularly long running request for semantic tokens. Perhaps then, the issue will occur more frequently on machines with lower performance or when working with very large Java files. All of the information that I've gathered seems to suggest that this is a bug in VS Code, rather than this extension. But again, I'm not entirely sure, as this issue is hard to reproduce. The code below this line looks like it could be part of the cause. It seems to shift the semantic tokens around and wait for new ones, if changes are made to the document during a request for semantic tokens. I think I've noticed this behavior when trying to reproduce the issue, as the tokens do get shifted around (like in the previous screenshot!), only to get corrected a split second later. My best guess is that the request for new semantic tokens occasionally gets ignored on this line for some reason, in which case this issue would appear since the tokens have been shifted around but not fixed by requesting new ones. Again, as soon as you type a character, new semantic tokens are requested and the issue is gone. If someone with more time on their hands or experience with the VS Code source-code could look into this, that would be greatly appreciated. I might submit an issue over at the VS Code repo, but right now I'm not sure if it's entirely the fault of VS Code, and I don't have a very reliable way to reproduce the issue. |
yeah, I've encountered this problem since the beginning of semantic color rendering tech. |
@0dinD good findings. I also observe the same behavior, but it prevents me from digging deep as I cannot stably reproduce it. The root cause might be either of the below: If you have time, one way to validate might be, setting |
@Eskibear thanks for the tip, I'll try to figure out more details when I can. One thing that makes me think it's more of a VS Code-issue is that the |
here I produced it again, after copy paste. I am copy paste from a document to another java file. |
@ericsia does the highlighted problem appear at the same time as the highlighting breaks? And does it also go away when the highlighting problems "fix" themselves? If the two are related, that's an interesting find. I spent some more time debugging the semantic highlighting issue today, and come to the following conclusions:
@Eskibear @fbricon do you have any idea why this might be happening? Are there any good ways to check if the document has had changes during the request? If so, maybe we can recompute the token positions when a change to the document is detected during the request. I'm just not that familiar with the Eclipse JDT APIs. |
Yes. When I notice the color started to change, often it tells me some syntax error. But I can still compile it. The color won't fix automatically for me, I have to close vs code and reopen to appear normal again. |
Finally, after another debugging session, I think I've found the real issue, and a fix for it. The strange offset for semantic tokens seems to be introduced on this line, when the encoding algorithm needs to figure out the line and column number of a semantic token. The reason for the offset is that the document used to calculate the line and column number from the offset can sometimes get out-of-sync in the middle of a semantic tokens request, due to frequent updates of the document. This means that some token positions will be calculated based on an older version of the document, which causes them to be offset by the number of characters in the document edit. @fbricon @Eskibear I've submitted a PR to fix this issue, could you please take a look at it? |
After playing around a little more with my changes in eclipse-jdtls/eclipse.jdt.ls#1552, I realized that there were two separate problems that can cause the tokens to become offset while editing.
When using both eclipse-jdtls/eclipse.jdt.ls#1552 and #1632, I can no longer reproduce this issue, no matter how many changes I spam to the document. |
omg you are amazing, you are the first one to discovered the fix. Owh that makes more sense now |
@0dinD it is getting worst after vscode since 2 updates before. Whenever I save the code, it auto-format and everything get messed up. |
@ericsia is this about #1597 or #1633 (or both)? Could you provide me with some details about which formatter and settings you're using? It would be really helpful if you've found a way to reliably reproduce the issue. For the record, the issue with the semantic tokens doesn't seem to be entirely fixed, because I've still seen it happen on very rare occasions. Usually it happens when doing multiple edits in quick succession at the same time as I'm starting some CPU-intensive process (which will cause the language server to be slow at computing the semantic tokens). #1632 seems to have mitigated the issue, but not fixed the root cause. Unfortunately I don't have much time to investigate this at the moment, so any help in reproducing the issue or finding the cause is greatly appreciated. |
my bad, it is the bug after plugin update #1917 |
They broke the offset again like 3 updates ago. At first I thought it was the workspace request permission fault. |
@ericsia Right, so you have format-on-save, that does seem likely to offset the semantic tokens based on my findings. Starting the debugger is likely also a contributing factor, as that may increase response times from the language server due to CPU load, which increases the likelihood of the semantic tokens becoming offset.
Not sure what you mean here, can't you just undo and then redo? ( Either way, the original "fix" for this issue was more of a workaround (#1632), but with my new findings in eclipse-jdtls/eclipse.jdt.ls#1806 I think I've found a more robust solution to fix this bug once and for all. Speaking of, do you have time to review eclipse-jdtls/eclipse.jdt.ls#1806 and the related #2000 @Eskibear? See this comment, specifically the second section, for a more detailed explanation of how this offset bug happens with semantic tokens. |
If I don't remember incorrectly it can't be REDO after UNDO too since the offset is changed. |
Is the issue you're talking about related to the code being formatted wrong, or the syntax highlighting (semantic tokens) being wrong? Could you please share some screenshots showing the current problem? Also, you should always be able to redo a change that you have just undone, not sure what you mean by "it can't be REDO after UNDO too since the offset is changed". You may need to undo/redo more than once since the formatter can create multiple edits. |
code being formatted wrong |
If what you've been talking about is a bug with the formatter rather than syntax highlighting, please report that in a new issue (after searching for an existing one). This issue tracks the bug where semantic tokens sometimes got offset during multiple edits, causing strange syntax highlighting artifacts as shown in your initial screenshot. |
@ericsia It looks more like a formating issue. Have you turned on "formatOnSave"? I suggest you to do following to get help: |
the thing is I need the format on save thought that is why I turn it on. I see, I thought this belong to same category of issue. If not mistaken this also cause semantic highlight changed too. |
I love to use VSC Java plugin but I had so much pain working with java now.
Now the highlight is glitchy, it don't highlight properly when Semantic Highlight is turn on.
Comment don't get highlighted :( I feel sad
Also I would appreciate it if it is easier to use junit assertEqual, when I try to open a single .java file, it cannot import org.junit
Environment
Steps To Reproduce
Current Result
Expected Result
Additional Informations
The text was updated successfully, but these errors were encountered: