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

Support to redefine icons for LSP client #3459

Merged
merged 6 commits into from Jan 18, 2022

Conversation

sdedic
Copy link
Member

@sdedic sdedic commented Jan 15, 2022

I reworked the stuff originally in #3414 to a state hopefully acceptable for NB13 before freeze/branching. Overview

Openide changes

  • ImageUtilities just formalize PROPERTY_URL in API + implementation bugfixes

LSP / VSCode changes

  • UIDefaults are patched at startup, with ImageUtilities.loadImages converted to icons for keys that are actually present. Replacement table is in a resource file. Stub image is replicated at build time, and mapped to images not mapped explicitly (just listed).
  • regexps in vscode client adjusted.

@sdedic sdedic requested review from entlicher, neilcsmith-net, JaroslavTulach and eirikbakke and removed request for entlicher January 15, 2022 11:39
@sdedic sdedic changed the title Vscode/redefined icons3 Support to redefine icons for LSP client Jan 15, 2022
Copy link
Contributor

@eirikbakke eirikbakke left a comment

Choose a reason for hiding this comment

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

Thanks for splitting out this digestible PR; looks good. I read over everything, though assuming that the LSP stuff was reviewed before by someone more familiar with that part of the codebase.

See in-code comments... main changes requested was fixing a double equals in a properties file and adding a comment to UIDefaultsIconMetadata to make it clear that it doesn't run during normal IDE execution.

Copy link
Contributor

@eirikbakke eirikbakke left a comment

Choose a reason for hiding this comment

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

Thanks for the updates!

@sdedic sdedic self-assigned this Jan 16, 2022
@sdedic sdedic added this to the NB13 milestone Jan 16, 2022
@sdedic sdedic added enhancement LSP [ci] enable Language Server Protocol tests VSCode Extension [ci] enable VSCode Extension tests API Change [ci] enable extra API related tests Need Squashing labels Jan 16, 2022
Copy link
Member

@neilcsmith-net neilcsmith-net left a comment

Choose a reason for hiding this comment

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

Can you double check the static initialization logic in ImageUtilities. Then please squash and merge when ready. Will be branching for NB13 later today.


static {
/* Could have used Mutex.EVENT.writeAccess here, but it doesn't seem to be available during
testing. */
if (EventQueue.isDispatchThread()) {
dummyIconComponent = new JLabel();
dummyIconComponentLabel = new JLabel();
dummyIconComponentButton = new JCheckBox();
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're doing a JCheckBox here instead of a JButton, the variable should be called dummyIconComponentCheckBox.

But remind me why we are doing a JCheckBox? I know it extends JButton but unless you know of specific cases that need it, I'd prefer to just have a JButton. Otherwise the hacks start getting too specific, and we'll be afraid to change them in the future.

Copy link
Member Author

@sdedic sdedic Jan 17, 2022

Choose a reason for hiding this comment

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

During development of the UIDefaults replacing code, I used ImageUtilities on real icons served by UIManager (default LaF). Several of them had special implementations that downcast the Component to JCheckbox in their paint(). Having a JCheckbox satisfies more icons than just JButton (there are such icons as well) I tried to choose the class that covered most of the errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, as long as you saw actual cases, that's fine. What do you mean by "using ImageUtilities"; which method(s) specifically? And which LAF was this? (Which OS?) Why haven't these cases come up before?

Copy link
Member Author

@sdedic sdedic Jan 17, 2022

Choose a reason for hiding this comment

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

which method(s) specifically

ImageUtilities.icon2Image; that ultimately calls paintIcon() to get the icon rendered to a BufferedImage. OS Linux / KDE, JDK 8+11, default L&F.

Why haven't these cases come up before?

Nobody called icon2Image on those particular UIManager icons ?

Copy link
Member

Choose a reason for hiding this comment

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

I think the reasoning is captured fine in the comment above too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it's fine with me. Just wondering if these were problems caused due to aggressive manual testing only, or whether they actually occur during real use.

*/
public static URL findImageBaseURL(Image image) {
Object o = image.getProperty(PROPERTY_URL, null);
return o instanceof URL ? (URL)o : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Space after ")", if you're doing another round of changes...

Copy link
Member

@neilcsmith-net neilcsmith-net left a comment

Choose a reason for hiding this comment

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

OK, let's get it in before branching.

@neilcsmith-net
Copy link
Member

neilcsmith-net commented Jan 17, 2022

@sdedic actually, hold on! Travis CI VSCode test is broken. Lots of logged java.lang.NoClassDefFoundError: Could not initialize class org.openide.util.ImageUtilities.

java.lang.NullPointerException: The image parameter cannot be null
    [junit] 	at org.openide.util.Parameters.notNull(Parameters.java:64)
    [junit] 	at org.openide.util.ImageUtilities.assignToolTipToImageInternal(ImageUtilities.java:397)
    [junit] 	at org.openide.util.ImageUtilities.image2Icon(ImageUtilities.java:328)
    [junit] 	at org.netbeans.modules.nbcode.integration.UIDefaultsIconMetadata$1.createValue(UIDefaultsIconMetadata.java:94)
    [junit] 	at javax.swing.UIDefaults.getFromHashtable(UIDefaults.java:216)
    [junit] 	at javax.swing.UIDefaults.get(UIDefaults.java:161)
    ...
    [junit] 	at javax.swing.JCheckBox.<init>(JCheckBox.java:174)
    ...
    [junit] Caused: java.lang.ExceptionInInitializerError
    [junit] 	at org.netbeans.modules.nbcode.integration.UIDefaultsIconMetadata$1.createValue(UIDefaultsIconMetadata.java:94)

Coincidence that that's with JCheckbox, or because of previous fix?

@eirikbakke
Copy link
Contributor

@neilcsmith-net ImageUtilities.image2Icon(ImageUtilities.loadImage(resImage)) is suspect in any case, since loadImage can return null and image2Icon does not accept null.

@sdedic sdedic added the do not merge Don't merge this PR, it is not ready or just demonstration purposes. label Jan 17, 2022
@neilcsmith-net
Copy link
Member

@sdedic I need to proceed with branching. Once available, please rebase this on delivery.

@sdedic
Copy link
Member Author

sdedic commented Jan 17, 2022

Got it, running tests. Will rebase.

@sdedic sdedic changed the base branch from master to delivery January 17, 2022 17:13
@sdedic
Copy link
Member Author

sdedic commented Jan 17, 2022

Seems that when the 1st call to ImageUtilities happened in the EDT (seemed not the case when running as a headless NBLS server or as an IDE, but did in the test), UIDefaultsIconMetadata attempted to call back to stil-not-initialized class ImageUtilities that resulted in CDNFE; at least when running locally.

@neilcsmith-net
Copy link
Member

Thanks! See, I knew that would cause a bug somewhere, or that fixing it would. 😆

Bit of a backlog in tests with all the branching and merging today. Please merge when it goes green.

@neilcsmith-net neilcsmith-net merged commit 2b91be1 into apache:delivery Jan 18, 2022
@neilcsmith-net neilcsmith-net removed the do not merge Don't merge this PR, it is not ready or just demonstration purposes. label Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Change [ci] enable extra API related tests enhancement LSP [ci] enable Language Server Protocol tests VSCode Extension [ci] enable VSCode Extension tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants