Skip to content

Semantic highlighting sometimes looks bad #1396

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

Closed
fbricon opened this issue Apr 16, 2020 · 9 comments
Closed

Semantic highlighting sometimes looks bad #1396

fbricon opened this issue Apr 16, 2020 · 9 comments

Comments

@fbricon
Copy link
Collaborator

fbricon commented Apr 16, 2020

When "java.semanticHighlighting.enabled": true, even without any particular token settings, this causes bad highlighting of existing code using static imports:
When enabled:
Screen Shot 2020-04-16 at 12 11 57 PM

When disabled:
Screen Shot 2020-04-16 at 12 12 30 PM

@rafaelrenanpacheco
Copy link
Contributor

Isn't this a specific color theme bug? I'm using this beautiful theme and the semantic highlight for fields inside methods are working as expected:

image

Before semantic token it was not possible to set the fields color inside a method. Only fields with this. prefix got coloring.

@Eskibear
Copy link
Contributor

Eskibear commented Apr 26, 2020

The bug is caused by caclulating semantic tokens of wrong AST nodes. And it should be fixed by eclipse-jdtls/eclipse.jdt.ls#1412 and eclipse-jdtls/eclipse.jdt.ls#1418 .

Below are steps to stably reproduce it.

  • Open an empty folder.
  • Create 2 .java files (A.java, B.java) directly under the folder.
  • Open A.java and close all the other files.
  • Do some editing in A.java, e.g. type some whitespaces
  • Now open B.java, you'll see wired highlighting.

A.java

public class A {
    String aString = "";
}

B.java

public class B {
    final static int constantInteger = 1;
}

image

@fbricon
Copy link
Collaborator Author

fbricon commented Apr 27, 2020

Fixed in 0.61.0

@fbricon fbricon closed this as completed Apr 27, 2020
@JoeyRxy
Copy link

JoeyRxy commented Sep 11, 2020

Hi, I think this problem didn't solved, I've encountered this situation in 0.66.0 version!

img

img

@Eskibear
Copy link
Contributor

@JoeyRxy Can you figure out a way to stably reproduce it? That would be a great help for us to understand the cause and provide a fix.

@JoeyRxy
Copy link

JoeyRxy commented Sep 11, 2020

@JoeyRxy Can you figure out a way to stably reproduce it? That would be a great help for us to understand the cause and provide a fix.

I think this problem occurs randomly. When you open a java file in a project (maven project most time in my situation), sometimes this problem occurs after you edit something.

in the pictures above, I just input an Enter, then it was broken, until reopening the file or do more editing. I think that's because those action trigger the refreshing or re-rendering action.

issue-in-vscode

@0dinD
Copy link
Contributor

0dinD commented Sep 11, 2020

@Eskibear I'm pretty sure this is related to #1597, and I don't think it's caused by any of my changes since I've seen it happen occasionally before, in version 0.64 or earlier. I've tried to reproduce it, but it was hard to find any consistent way to do it. See my comment for what I've been able to find out so far. I'll try to find some steps to reproduce it if I have time next week.

@lucsoft
Copy link

lucsoft commented Jun 27, 2023

Semantic highlighting often still goes bad when doing larger refactors in larger files (500 LoC)
image

Can't really show code. But i can tell that its a maven eclipse mono repo project with java 17, java module system.

Often saving or adding a new line fixes it

@0dinD
Copy link
Contributor

0dinD commented Jul 1, 2023

@lucsoft It turns out that there is a different issue which can still cause the semantic tokens to become desynced (this is probably what you've run into). This is being tracked by #2176.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants