-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix for issue #2906 (semantic highlighting styles overruled by TM scopes) #5941
Fix for issue #2906 (semantic highlighting styles overruled by TM scopes) #5941
Conversation
@kittaakos, what do you think about this alternative approach for fixing #2906? The fix is not complete (e.g. it's missing code to update the decoration options when the theme changes), but I'm curious what do you think of the general approach. |
@HighCommander4, can you please provide us an example so that we can try out your changes against the |
I tested this with the C++ language server, clangd. This can be built from source, or installed from https://apt.llvm.org/ (though note that, at this time, only the Debian Buster, Debian sid, and Ubuntu Disco packages are new enough to include the semantic highlighting feature). Example steps to demonstrate the problem:
Without this patch, on line 5, the tokens With this patch, the token |
Works very nicely! I have tried with the I add a few screenshots to show how nicely your contribution works: For instance, although we had a special rule for coloring descriptions, it did not work previosuly, as the String rule overruled our customization. Now it works. 🎉 I have manually verified the CSS classes, and with your changes there are no |
packages/monaco/src/browser/monaco-semantic-highlighting-service.ts
Outdated
Show resolved
Hide resolved
packages/monaco/src/browser/monaco-semantic-highlighting-service.ts
Outdated
Show resolved
Hide resolved
5571be9
to
20e7171
Compare
I fixed the TODOs, addressed the other comments, and cleaned up the patch a bit. Should be ready for a proper review now. Thanks! |
20e7171
to
9342973
Compare
@kittaakos please have a look when you have a chance 🙏 |
I am verifying the changes with the YANG language. |
We do not update the highlighted tokens when changing the theme. Steps to reproduce:
|
@kittaakos Could you share some instructions for testing this with YANG? Should I download the YANG language server from here? Is there any setup required on the Theia side? |
It is a hack, but I created a PR in |
@kittaakos, I tried following these steps, but at the
What should I do to get past this? (Apologies if this is a basic question; I'm new to the world of javascript development. I did try googling and ran some npm commands to try and get past this, but I'm pretty sure they just made things worse and borked my checkout altogether.) |
You do not have to.
I have never seen this before. I look into it later today and give you an update. |
@HighCommander4, what OS did you use building yangster? |
@kittaakos I am using Debian 9. (Is that relevant? My understanding was that the build process doesn't really use the OS's package repositories.) |
@kittaakos Hi, just wanted to ping here. Any suggestions for how I can get Yangster building, or another way to reproduce the issue you observed with the patch? I'd like to reproduce the issue and fix it. |
I do not have. I could build Yangster without any issues. |
Is there perhaps a different language which is affected by the issue? |
I am not aware of it. I can create a simple DSL to simplify the context, but I do not have much time dealing with this right now. Is the LS-based semantic highlighting feature that urgent for you? I mean, MS has not even accepted the proposal yet. I would expect we have to rewrite it from scratch by the time there is an update on the specification. |
I was able to get yangster to build. The missing step was:
After that, Unfortunately, the electron app fails to start, with the following error:
|
I was able to get past this by deleting the repository and starting from scratch. What appears to have made the difference is running |
And I can confirm that I can reproduce the undesirable rendering. |
I found the problem, it's a simple mistake in my patch. I had a check of the form You can tell I'm a JS newbie... We didn't notice this in the C++ language server because the semantic highlighting with kind |
9342973
to
44c6b58
Compare
I can reproduce this as well, investigating. |
To clarify, I got this package name and version from the output of the
|
The reason we're not updating the highlightings when the theme changes, is that we don't reuse CSS class names between different themes, we create new ones, but nothing updates the class names currently used in the editor. I'll try to revise the patch so that we reuse the class names, as we did before this patch. |
44c6b58
to
902a0c8
Compare
The updated patch addresses the issue with changing the theme as well. I believe that's all the issues raised so far, and the patch is ready to continue to be reviewed. |
Unfortunately, the keywords are still not highlighted. See my comment here, Besides that, changing the theme messes up the colors. See the original This contribution looks super cool, let me know if you need me for another review. |
packages/monaco/src/browser/monaco-semantic-highlighting-service.ts
Outdated
Show resolved
Hide resolved
@kittaakos Are you sure you were testing with the latest patch here (including patching it into yangster)? It works for me locally, both the |
…led by TM scopes) The idea for the fix comes from the observation that there are VSCode plugins that implement semantic highlighting using TextEditor.setDecorations(), and do not suffer from this problem. We don't want to use setDecorations() itself because it's not really suited for incremental updates to the highlighting (which the LSP protocol extension that Theia implements allows for). However, setDecorations() is implemented in terms of deltaDecorations() (which is what Theia uses), and changing Theia's use of deltaDecorations() to be more like the implementation of setDecorations() seems to fix this bug. Specifically, instead of getting an inlineClassName directly from the TokenMetadata (which seems to produce the problematic inlineClassName that coflicts with TM), we: * Get the token color from the TokenMetadata * Construct an IDecorationRenderOptions from the token color (as if we were going to call setDecorations()) * Use ICodeEditorService.registerDecorationType() and ICodeEditorService.resolveDecorationOptions() to massage the IDecorationRenderOptions into an IModelDecorationOptions. This appears to cause monaco to allocate a new inlineClassName for the color which doesn't conflict with TM. * Call deltaDecorations() with IModelDecorationOptions obtained in this way Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
902a0c8
to
ea10fc5
Compare
For convenience, I updated the code to patch yangster in theia-ide/yangster#82. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works great, thank you for your help @HighCommander4 👍🥇
I have verified it on macOS in Chrome with the YANG language.
The idea for the fix comes from the observation that there are VSCode
plugins that implement semantic highlighting using
TextEditor.setDecorations(), and do not suffer from this problem.
We don't want to use setDecorations() itself because it's not really
suited for incremental updates to the highlighting (which the LSP
protocol extension that Theia implements allows for).
However, setDecorations() is implemented in terms of deltaDecorations()
(which is what Theia uses), and changing Theia's use of
deltaDecorations() to be more like the implementation of
setDecorations() seems to fix this bug.
Specifically, instead of getting an inlineClassName directly from the
TokenMetadata (which seems to produce the problematic inlineClassName
that coflicts with TM), we:
Get the token color from the TokenMetadata
Construct an IDecorationRenderOptions from the token color
(as if we were going to call setDecorations())
Use ICodeEditorService.registerDecorationType() and
ICodeEditorService.resolveDecorationOptions() to massage the
IDecorationRenderOptions into an IModelDecorationOptions. This
appears to cause monaco to allocate a new inlineClassName for
the color which doesn't conflict with TM.
Call deltaDecorations() with IModelDecorationOptions obtained in
this way.