-
Notifications
You must be signed in to change notification settings - Fork 106
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
Improve presentation of inactive region highlight #193
Conversation
@sam-mccall I wonder what you think of this patch. On the one hand, it may seem like a lot of effort for a small cosmetic improvement. (But I've already done the effort :-) ) On the other hand, I believe visualizing inactive code with a background highlight is a common C++ IDE trope that may be worth emulating. This patch is also a good building block for the future enhancement described here (basically, to omit the semantic foreground color for inactive tokens altogether, such that the client-side highlightings (e.g. bold keywords) are retained and combined with the semantic background in inactive code). The approach taken in this patch to implement the background highlight is in line with Microsoft's suggestion to use editor decorations for this purpose until a more specific API greared towards inactive code is added. |
@sam-mccall review ping :) |
Shopping around for some other reviewers :) |
Seems to work. |
I had the same thought in clangd/clangd#132 (comment). Haven't tried to see if it's possible yet. |
The thing is that if you don't specify |
Hi, I just wanted to chime in and say that I implement this in my fork (rolandbernard@4f2c9f3) because it bugged me too much. I wanted it to look like in the official Microsoft C++ extension, i.e., the region only has a lower opacity and still uses the default syntax highlighting. So I replace all the comment semantic tokens before returning them. |
This is really neat! It's the same high-level idea that I was after: combine a presentational style indicating "inactive", with client-side (TextMate) token colors. The only difference is the choice of presentation style for "inactive" (in my case it's a grey background, in yours it's lower opacity). Anyways, I believe your patch demonstrates that this sort of combination is possible! |
@rolandbernard I looked through your patch. One thing I'm curious about is |
Yes, I choose |
Thanks, that makes sense. The other trick in your implementation that hadn't occurred to me was that the |
d8d74cc
to
4d01c3a
Compare
@rolandbernard I updated the PR to make use of the techniques from your patch to preserve the client-side coloring, hope that's cool (I added a comment to credit you). The styling in my patch currently remains a background highlight, but it's very easy to change to opacity if that's preferred, I don't really feel strongly about it. Now, we just need someone kind enough to review and consider merging this improvement :) |
I'm sorry this has taken a long time. I bounced off this many times because IMO neither "yes" nor "no" are good answers... The behavior looks great (especially preserving the client-side highlights). And our current behavior (coloring disabled code as comments) seems to be worse than nothing based on bug reports. On the other hand, the design we've landed on (in general, not this patch) isn't good.
My conclusion is we should back up and try again:
WDYT? (I'm happy to put together a patch for 1+2 if that's helpful, there are some questions about such an LSP extension to work out) |
Square one, it's nice to see you again :) This is the very first approach I took for inactive regions (modulo the "combining client-side tokens" part), in Sept 2019: Server-side patch (looking at the first version of the diff in particular, as later versions reformulate it on top of semantic highlighting) |
Wow, I'd forgotten. That's excruciating to read, I'm sorry. Still, (If you prefer to go ahead with this version, that seems reasonable. I'd love to know whether you think it's not a mistake vs not worth fixing vs too frustrating to touch anymore would be useful!) |
I agree that conceptually, a separate protocol for inactive regions makes more sense. The two reasons I see as most convincing are:
So, I think a reasonable way forward would be to resurrect the patches which add a new protocol, rebase them, and tweak them to preserve the client-side TextMate tokens. I'm happy to do that (probably after finishing up a couple of other in-progress things, so if you'd like to beat me to it, please feel free). |
Actually, maybe even in the not-so-distant future by sending pseudo-parser based heuristic semantic tokens for code inside inactive regions :) |
I guess, for completeness, it's worth noting that a downside of the dedicated protocol is that we lose the ability of other clients to have some styling of inactive code without implementing the new protocol. (Perhaps we could mitigate that by still sending the comment semantic tokens if the client doesn't indicate capability for the new protocol?) |
The opacity really makes the difference in making it clear the code is inactive. vscode.window.createTextEditorDecorationType({
isWholeLine: true,
opacity: config.get<number>('clangd.inactiveRegions.opacity').toString(),
backgroundColor:
new vscode.ThemeColor('clangd.inactiveRegions.background')
}); |
Any progress about this pr?@HighCommander4 |
03295aa
to
a837753
Compare
Fixed a typo in package.json |
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.
Thanks, the implementation looks good in general.
I have a question about the rendering theme, see my comment.
This implements the server side of the approach discussed at clangd/vscode-clangd#193 (comment) Differential Revision: https://reviews.llvm.org/D143974
20010c2
to
2dea88c
Compare
Addressed review comments, except for the one about |
@hokein, perhaps we could proceed with the current patch for now? If at some point we figure out how to make use of vscode's |
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.
The code looks great (sorry for taking it so long). Let's ship it!
Rebased and addressed review comments. |
Thanks everyone for completing this! |
This implements the server side of the approach discussed at clangd/vscode-clangd#193 (comment) Differential Revision: https://reviews.llvm.org/D143974
Thank you for making this happen! I do wonder when is this feature be released? IIUC, this change was merged in May, and the latest release was in April. Is it on the horizon or would you recommend just building the extension from source? |
and... why should one build from source - is there a "nightly" / "ci" version that may be used? |
I sent out a PR to release a new version: #516. I don't believe we currently have any sort of automatically created preview/snapshot releases for vscode-clangd. I agree that this would be nice to have. I'm not sure that "nightly" is the appropriate frequency, given that the project gets commits much less often than that (there have been a total of 6 commits in 2023 so far). Perhaps it would make sense to have every commit trigger a snapshot release? If someone has the familiarity with Github Actions to write a patch to the yaml files in .github/workflows that accomplishes this, that would be very neat. |
Filed #517 to keep any further discussion of this in a dedicated place. |
Hello @HighCommander4, The highlighting appears to be ineffective in certain instances, especially on Windows. |
@HighCommander4 Thanks for the cool work. Could somebody point out the documentation for highlighting the disabled code. Iam using Nvim with clangd, which option needs to be enabled |
I've implemented the server-side of the inactive region highlighting in clangd, and the client-side support in the vscode-clangd plugin. Client-side support in other clients like neovim needs to be implemented separately in the respective client / plugin. I don't know whether anyone has done that for neovim yet. |
This implements the server side of the approach discussed at clangd/vscode-clangd#193 (comment) Differential Revision: https://reviews.llvm.org/D143974
This patch intercepts the semantic tokens requests using middleware,
extracts the inactive code ranges, and uses setDecorations() to
provide whole-line background highlighting for them.