Skip to content
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

Syntax highlighting changes #3641

Closed
realqpat opened this issue May 5, 2024 · 7 comments
Closed

Syntax highlighting changes #3641

realqpat opened this issue May 5, 2024 · 7 comments
Labels

Comments

@realqpat
Copy link

realqpat commented May 5, 2024

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
  • Operating System: Linux
  • JDK version: 17
  • Visual Studio Code version: 1.89.0
  • Java extension version: 1.30
  • Name: Language Support for Java(TM) by Red Hat
@rgrunber
Copy link
Member

rgrunber commented May 6, 2024

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
Copy link
Collaborator

fbricon commented May 6, 2024

You can try this in your vscode settings:

	"[java]": {
		"editor.semanticHighlighting.enabled": false
	}

@realqpat
Copy link
Author

realqpat commented May 6, 2024

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
Copy link
Member

rgrunber commented May 6, 2024

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
Copy link
Author

realqpat commented May 6, 2024

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

@realqpat realqpat closed this as completed May 6, 2024
@rgrunber
Copy link
Member

rgrunber commented May 6, 2024

@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
Copy link
Author

realqpat commented May 7, 2024

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.

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

No branches or pull requests

3 participants