Skip to content

Show ZWSP (zero width space) as code mining#1437

Merged
marcushoepfner merged 1 commit into
eclipse-platform:masterfrom
marcushoepfner:zwsp
Mar 9, 2026
Merged

Show ZWSP (zero width space) as code mining#1437
marcushoepfner merged 1 commit into
eclipse-platform:masterfrom
marcushoepfner:zwsp

Conversation

@marcushoepfner
Copy link
Copy Markdown
Contributor

Issue: #1002

For more information refer to https://www.compart.com/en/unicode/U+200B To get a ZWSP refer to https://zerowidthspace.me/

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 19, 2023

Test Results

   852 files  ±0     852 suites  ±0   53m 43s ⏱️ - 3m 5s
 7 844 tests ±0   7 601 ✅ +1  243 💤 ±0  0 ❌  - 1 
20 058 runs  ±0  19 402 ✅ +1  656 💤 ±0  0 ❌  - 1 

Results for commit a0b6352. ± Comparison against base commit b819cf9.

♻️ This comment has been updated with latest results.

@BeckerWdf
Copy link
Copy Markdown
Member

BeckerWdf commented Dec 20, 2023

I did a quick manual test on macOS. I found the following issues:

  1. code mining is not displayed emidiately. I have to close and reopen the editor for the code minings to be shown
  2. Two ZWSP next to each other are drawn one the (almost?) same location. See line 4 in:
image
  1. When select the "a" and the "ZWSP" in line 2 from the above screenshot to with the keyboard I have to press the right-cursor two times until the caret is behind the "ZWSP".

@marcushoepfner marcushoepfner force-pushed the zwsp branch 4 times, most recently from b082ac8 to 6cccc08 Compare August 5, 2025 14:06
@marcushoepfner marcushoepfner marked this pull request as draft August 6, 2025 06:21
@marcushoepfner marcushoepfner marked this pull request as ready for review August 13, 2025 06:35
@BeckerWdf
Copy link
Copy Markdown
Member

I manually tested your change.

the ZWSP is shown correctly:
image

but when I disable the "show whitespace character" function (e.g. via the toolbar button) the ZWSP code mining still not disappears (even though the other "white space character" stuff does correctly disappear:
image

Copy link
Copy Markdown
Member

@BeckerWdf BeckerWdf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments above

@BeckerWdf
Copy link
Copy Markdown
Member

another topic:
a user can change the color of the code minings in the "fonts and colors" preference page. If you do this you will see a mix of colors:

image

Maybe this can be improved:

  • either by ignoring the users color pref here
  • also use the code mining color from preferences for the other "white space character" drawing logic.

@marcushoepfner
Copy link
Copy Markdown
Contributor Author

I manually tested your change.

the ZWSP is shown correctly: image

but when I disable the "show whitespace character" function (e.g. via the toolbar button) the ZWSP code mining still not disappears (even though the other "white space character" stuff does correctly disappear: image

fixed with the last commit.

@marcushoepfner
Copy link
Copy Markdown
Contributor Author

another topic: a user can change the color of the code minings in the "fonts and colors" preference page. If you do this you will see a mix of colors:

image Maybe this can be improved:
  • either by ignoring the users color pref here
  • also use the code mining color from preferences for the other "white space character" drawing logic.

I tried to ignore and overwrite the color with the one TextEditor uses for drawing spaces, tabs,...
According to

this is SWT.COLOR_LIST_FOREGROUND, which is black.
I even debugged the drawing of a tab and it was colored 0, 0, 0 but appeared grey. I dont get it....

@marcushoepfner marcushoepfner force-pushed the zwsp branch 3 times, most recently from 0ee781a to 8b2948b Compare October 9, 2025 13:27
@BeckerWdf
Copy link
Copy Markdown
Member

I just played around a bit with the current state.
I got this:

java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.widgets.Display.getSystemColor(int)" because the return value of "org.eclipse.swt.widgets.Display.getCurrent()" is null
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMining.<init>(ZeroWidthCharactersLineContentCodeMining.java:40)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.createCodeMining(ZeroWidthCharactersLineContentCodeMiningProvider.java:108)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.provideCodeMinings(ZeroWidthCharactersLineContentCodeMiningProvider.java:72)
	at org.eclipse.jface.internal.text.codemining.CodeMiningManager.lambda$2(CodeMiningManager.java:194)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)

@marcushoepfner marcushoepfner marked this pull request as draft October 13, 2025 05:20
@BeckerWdf
Copy link
Copy Markdown
Member

fixed with the last commit.

Thanks. That looks good now.

@BeckerWdf
Copy link
Copy Markdown
Member

I just played around a bit with the current state. I got this:

java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.widgets.Display.getSystemColor(int)" because the return value of "org.eclipse.swt.widgets.Display.getCurrent()" is null
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMining.<init>(ZeroWidthCharactersLineContentCodeMining.java:40)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.createCodeMining(ZeroWidthCharactersLineContentCodeMiningProvider.java:108)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.provideCodeMinings(ZeroWidthCharactersLineContentCodeMiningProvider.java:72)
	at org.eclipse.jface.internal.text.codemining.CodeMiningManager.lambda$2(CodeMiningManager.java:194)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)

This is now also fixed. Thanks,

@marcushoepfner
Copy link
Copy Markdown
Contributor Author

I just played around a bit with the current state. I got this:

java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.widgets.Display.getSystemColor(int)" because the return value of "org.eclipse.swt.widgets.Display.getCurrent()" is null
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMining.<init>(ZeroWidthCharactersLineContentCodeMining.java:40)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.createCodeMining(ZeroWidthCharactersLineContentCodeMiningProvider.java:108)
	at org.eclipse.ui.internal.texteditor.codemining.ZeroWidthCharactersLineContentCodeMiningProvider.provideCodeMinings(ZeroWidthCharactersLineContentCodeMiningProvider.java:72)
	at org.eclipse.jface.internal.text.codemining.CodeMiningManager.lambda$2(CodeMiningManager.java:194)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)

This is now also fixed. Thanks,

Is the color of "ZWSP" grey or black in your case?

@BeckerWdf
Copy link
Copy Markdown
Member

I tried to ignore and overwrite the color with the one TextEditor uses for drawing spaces, tabs,... According to

this is SWT.COLOR_LIST_FOREGROUND, which is black.
I even debugged the drawing of a tab and it was colored 0, 0, 0 but appeared grey. I dont get it....

I also just debugged this. And I see that the color (for the whitespace chars comes from the styleRange not the textWidget:

@BeckerWdf
Copy link
Copy Markdown
Member

Is the color of "ZWSP" grey or black in your case?

black.

@tobiasmelcher
Copy link
Copy Markdown
Contributor

The WhitespaceCharacterPainter uses in the light theme the black color Color {0, 0, 0, 255} to draw the invisible characters with gc.drawString. It looks greyish because gc.setAlpha(fAlpha); is called beforehand with value fAlpha=80.
Here the location where setAlpha is called.

private void handleDrawRequest(GC gc, int x, int y, int w, int h) {
		int startLine= fTextWidget.getLineIndex(y);
		int endLine= fTextWidget.getLineIndex(y + h - 1);
		if (startLine <= endLine && startLine < fTextWidget.getLineCount()) {

			// avoid painting into the margins:
			Rectangle clipping= gc.getClipping();
			Rectangle clientArea= fTextWidget.getClientArea();
			int leftMargin= fTextWidget.getLeftMargin();
			int rightMargin= fTextWidget.getRightMargin();
			clientArea.x+= leftMargin;
			clientArea.width-= leftMargin + rightMargin;
			clipping.intersect(clientArea);
			gc.setClipping(clientArea);
			if (fIsAdvancedGraphicsPresent) {
				int alpha= gc.getAlpha();
				gc.setAlpha(fAlpha); // <!------------------------------------
				drawLineRange(gc, startLine, endLine, x, w);
				gc.setAlpha(alpha);
			} else {
				drawLineRange(gc, startLine, endLine, x, w);
			}
			gc.setClipping(clipping);
		}
	}

We could do the same in the ZeroWidthCharactersLineContentCodeMining so that all whitespaces are rendered in the same color. Maybe introduce a re-usable in WhitespaceCharacterPainter to retrieve the color config which can then be reused by the code mining.

@tobiasmelcher
Copy link
Copy Markdown
Contributor

​[c5d21c1] sets the same color in the ZWSP code minings as it is done in the whitespace character painter

image

@marcushoepfner
Copy link
Copy Markdown
Contributor Author

Interesting, the current version in main branch is 3.20

And that is the problem

But the API warning says something about 3.19...

Because we don't increase minor version twice for the same release. It was already bumped in 5f6cae6.

So please undo the version increment in manifest and change since tag to 3.20. After that there will be still API error on org.eclipse.ui.texteditor.AbstractTextEditor.PREFERENCE_SHOW_ZW_CHARACTERS, and you can add a filter for this error in the editor via Ctrl+1.

Also would be good if you could squash all commits to a single one and after that rebase on latest master branch.

I don't see the quickfix/error.
I used 2026-03 RC2 as baseline and did not change any settings. I can even see that org.eclipse.ui.workbench.texteditor already has one filter.

Is there any documentation on how to setup the baseline?
I followed the help, but it did not solve my problem.
Contributing.md does not contain information regarding baseline setup. I wonder why not, as this seems to be an essential step in Eclipse contribution.

@marcushoepfner
Copy link
Copy Markdown
Contributor Author

Interesting, the current version in main branch is 3.20

And that is the problem

But the API warning says something about 3.19...

Because we don't increase minor version twice for the same release. It was already bumped in 5f6cae6.
So please undo the version increment in manifest and change since tag to 3.20. After that there will be still API error on org.eclipse.ui.texteditor.AbstractTextEditor.PREFERENCE_SHOW_ZW_CHARACTERS, and you can add a filter for this error in the editor via Ctrl+1.
Also would be good if you could squash all commits to a single one and after that rebase on latest master branch.

I don't see the quickfix/error. I used 2026-03 RC2 as baseline and did not change any settings. I can even see that org.eclipse.ui.workbench.texteditor already has one filter.

Is there any documentation on how to setup the baseline? I followed the help, but it did not solve my problem. Contributing.md does not contain information regarding baseline setup. I wonder why not, as this seems to be an essential step in Eclipse contribution.

@merks Can you help here?

@marcushoepfner marcushoepfner merged commit b8d7d92 into eclipse-platform:master Mar 9, 2026
18 checks passed
@marcushoepfner marcushoepfner deleted the zwsp branch March 9, 2026 08:16
@iloveeclipse
Copy link
Copy Markdown
Member

This change introduces memory leak, please check eclipse-jdt/eclipse.jdt.ui#2856.

@BeckerWdf
Copy link
Copy Markdown
Member

@marcushoepfner: Can you pls. have a look?

@marcushoepfner
Copy link
Copy Markdown
Contributor Author

It seems that the dipose call on CodeMiningProviders is completely missing from text editor.
Only Java does it for its own providers in JavaEditor.dispose()

@BeckerWdf
Copy link
Copy Markdown
Member

JavaEditor.dispose()

So you say it's not a regression of this PR but this PR only did uncover and pre-existing issue?

@marcushoepfner
Copy link
Copy Markdown
Contributor Author

JavaEditor.dispose()

So you say it's not a regression of this PR but this PR only did uncover and pre-existing issue?

Seems so. I have a local solution already and will create a PR later.
Code Mining "experts" need to check it then.

@BeckerWdf
Copy link
Copy Markdown
Member

Code Mining "experts" need to check it then.

We can ask @tobiasmelcher to review it.

@marcushoepfner
Copy link
Copy Markdown
Contributor Author

Provided a fix in #3770 .
Let's stop the discussion here and move over to #3770 and eclipse-jdt/eclipse.jdt.ui#2856.

@BeckerWdf
Copy link
Copy Markdown
Member

@marcushoepfner: Should we add this to the New & Noteworthy document?

@eclipse-platform eclipse-platform deleted a comment from LiamHD May 18, 2026
@marcushoepfner
Copy link
Copy Markdown
Contributor Author

@marcushoepfner: Should we add this to the New & Noteworthy document?

Oh yes. Any documentation on how to do that?

@marcushoepfner marcushoepfner added the noteworthy Noteworthy feature label May 18, 2026
@BeckerWdf
Copy link
Copy Markdown
Member

Oh yes. Any documentation on how to do that?

It's about editing https://github.com/eclipse-platform/www.eclipse.org-eclipse/blob/master/news/4.40/platform.md

@BeckerWdf BeckerWdf added this to the 4.40 milestone May 18, 2026
marcushoepfner added a commit to eclipse-platform/www.eclipse.org-eclipse that referenced this pull request May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

noteworthy Noteworthy feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants