redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 433 forks source link

Syntax highlighting changes #3641

Closed realqpat closed 4 months ago

realqpat commented 4 months ago

Seems like the syntax highlighting has changed recently. I've noticed it with the constant variables They are highlighted the same as a regular variable now When opening a java file, the syntax highlight is correct and a few seconds later it changes

When checking the developer tools, I noticed the following that seems related but not sure

TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope source.java.
Old grammar file: file:///opt/visual-studio-code/resources/app/extensions/java/syntaxes/java.tmLanguage.json.
New grammar file: file:///home/user/.vscode/extensions/redhat.java-1.30.0-linux-x64/language-support/java/java.tmLanguage.json
register @ TMScopeRegistry.ts:46

Is there a way to keep the old grammar file ?

Environment
rgrunber commented 4 months ago

Our java.tmLanguage.json is directly copied into vscode. See https://github.com/microsoft/vscode/blob/facea7e2c298bc0e9fcb553464cd7fc7d4b519e0/extensions/java/syntaxes/java.tmLanguage.json#L2-L6 . Doing a quick comparison the only difference is in the information_for_contributors that explains the origin.

The difference probably comes from semantic highlighting, which is an extra layer of highlighting done by the language server itself, since it collects even more information about the source file.

Are you using the dark theme ? I noticed a difference on the Dark+ theme but not on the Quiet Light theme. We don't really control the colours, we just provide information on the tokens and it's up to the theme whether it chooses to use that info to distinguish certain tokens from each other (constant vs. variable) or treat them the same. Maybe the theme has been updated ?

Screencast from 2024-05-06 11-03-58.webm

Screencast from 2024-05-06 11-04-57.webm

fbricon commented 4 months ago

You can try this in your vscode settings:


    "[java]": {
        "editor.semanticHighlighting.enabled": false
    }
realqpat commented 4 months ago

I checked the token and scope and it's exactly the same for a variable and a constant variable which results in the syntax highlight being the same for both (I presume) Not sure when this broke but it's fairly recent I tried to disable some extensions that i thought would be responsible for this but to no avail And yes, I'm using a light theme but noticed the same behavior no matter the theme I use (light or dark)

image

rgrunber commented 4 months ago

Do you have a sample project / snippet of code you're able to share that produces this ? Is there anything in your error logs that indicate a failure to start the language server ?

The popup you're showing doesn't contain any information about the semantic tokens at all, which would indicate you don't have a language server started. Here's what it looks like when the language server is running :

(note the portion about semantic token type and modifiers) image

realqpat commented 4 months ago

I restarted the Java Language Server via the command-palette and this is the log. I don't see anything that might indicate something went wrong

!ENTRY org.eclipse.jdt.ls.core 1 0 2024-05-06 16:38:39.952
!MESSAGE >> shutdown

!ENTRY org.eclipse.jdt.ls.core 1 0 2024-05-06 16:38:39.967
!MESSAGE >> exit

!ENTRY org.eclipse.jdt.ls.core 1 0 2024-05-06 16:38:40.328
!MESSAGE Shutdown received... waking up main thread

!ENTRY org.eclipse.jdt.ls.core 1 0 2024-05-06 16:38:40.346
!MESSAGE class org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin is stopping:
!SESSION 2024-05-06 16:38:40.572 -----------------------------------------------
eclipse.buildId=unknown
java.version=17.0.3
java.vendor=Eclipse Adoptium
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments:  --pipe=/run/user/1000/lsp-d596f6638288205b027147433867a2fe.sock
Command-line arguments:  -data /home/patrice/.config/Code/User/workspaceStorage/e3fb2e0977f37ff141ae29441be34630/redhat.java/jdt_ws --pipe=/run/user/1000/lsp-d596f6638288205b027147433867a2fe.sock

!ENTRY org.eclipse.jdt.ls.core 1 0 2024-05-06 16:38:43.312
!MESSAGE class org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin is started

!ENTRY org.eclipse.jdt.ls.core 1 0 2024-05-06 16:38:43.592
!MESSAGE Main thread is waiting

But something interesting did happen I'm migrating a project from Java 8 to Java 17. I was on a the Java 17 branch when I noticed the issue When I switched to the Java 8, the issue was gone. I went back to the Java 17 branch and issue is no longer reproducible (I now have the semantic token type as seen on your screenshot)

Ultimately, i'll only have a Java 17 branch. So pretty sure this issue will be resolved then (the switching back and forth probably messed up the language server ?) Good to close this issue. My bad

rgrunber commented 4 months ago

@realqpat is the project available somewhere public ? Are you able to share it ? I don't mind seeing if switching branches (effectively changing build configurations) causes some issues for the language server.

realqpat commented 4 months ago

Switching is not the actual solution. I've actually narrowed it down On startup, the syntax highlight is not working as I posted initially (and in my screenshot). I have to restart the Language Server and all is good afterwards

This has been my workaround for now. Restart the Language Server when I face the issue.