Bug 571758 - [preferences] Add defaults (enabled/disabled) in Type Filters preferences
Summary: [preferences] Add defaults (enabled/disabled) in Type Filters preferences
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.20   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.21 RC1   Edit
Assignee: Noopur Gupta CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy, plan
Depends on:
Blocks:
 
Reported: 2021-03-07 12:21 EST by Leon Hofmeister CLA
Modified: 2021-12-09 09:03 EST (History)
11 users (show)

See Also:
kalyan_prasad: review+


Attachments
Screenshot showing unnecessary code recommendations (385.73 KB, image/png)
2021-03-07 12:21 EST, Leon Hofmeister CLA
no flags Details
Type filters - defaults (75.64 KB, image/png)
2021-08-20 02:57 EDT, Noopur Gupta CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leon Hofmeister CLA 2021-03-07 12:21:23 EST
Created attachment 285764 [details]
Screenshot showing unnecessary code recommendations

Currently, when a code suggestion is requested without any context on how it might be used (i.e. simply typing "A" in a method and then requesting code suggestions for it), most suggestions are simply unnecessary for basically all users except JDK developers:
Countless jdk.internal, org.graalvm, or com.sun classes get suggested, even though basically no one will ever use them in their project unless they are developing on the JDK internally.

So, it would be nice if the user could define package prefixes that will automatically get excluded when requesting code suggestions.

Default values for users should be:
- jvm.
- org.graalvm.
- com.sun.
- sun.
- … (if anyone has more suggestions, please add.)

By using this approach, any user can define themselves what packages they never want recommended.

Whatever the internal algorithm used may be, implementing this should not be a huge performance decrease, in the best case it even speeds up searching for code recommendations.
Comment 1 Leon Hofmeister CLA 2021-03-07 12:35:02 EST
The screenshot provides useful suggestions up until AtomicLong.
Any suggestion below is simply irrelevant for all use cases.
Beyond what it is visible, MANY more irrelevant suggestions are shown.
The "AboutEvent" from java.awt.desktop is the first (somewhat) relevant suggestion again.
After counting I can honestly say that there are (exactly) 100 irrelevant suggestions inbetween. That is simply frustrating.
Comment 2 Andrey Loskutov CLA 2021-03-07 13:19:15 EST
If you check Eclipse Java preferences, there was a possibility to filter out such packages. Not saying the bug is irrelevant, just to reduce your frustration.

And I agree, many packages should be excluded by default.
Comment 3 Noopur Gupta CLA 2021-03-08 03:52:04 EST
(In reply to Andrey Loskutov from comment #2)
> If you check Eclipse Java preferences, there was a possibility to filter out
> such packages. Not saying the bug is irrelevant, just to reduce your
> frustration.

Prefereneces > Java > Type Filters.

> And I agree, many packages should be excluded by default.

Yes, we should look at excluding some by default via the above preferences.

Bug 511443 can be referred for some points to consider while changing the defaults.
Comment 4 Leon Hofmeister CLA 2021-03-08 04:10:51 EST
Thanks, found it.

> See Preferences > Java > Type Filters.
Well, close enough, found it under

> Preferences > Java > Appearance > Type Filters
I agree too that the default values are definitively missing here and will be of great importance to be automatically inserted.

I do have to say however that placing this option as part of "Appearance" is a little bit misleading, I would have rather expected it in "Code style", "Compiler" or "Editor"…
Comment 5 Leon Hofmeister CLA 2021-03-08 04:32:50 EST
After some testing, adding the following default values seems the most sensible:

- com.sun.*
- jdk.*
- org.graalvm.*
- sun.*
(- java.rmi.*) - this one will be controversial as there are people that use it but I'd say most Java projects do not use it.
Comment 6 Andrey Loskutov CLA 2021-07-20 07:50:44 EDT
java.awt is my personal favorite to exclide, because it has java.awt.List that constantly collides with java.util.List and because of that automatic imports are nkt working. Beside this, java.awt is mostly irrelevant today.
Comment 7 Gunnar Wagenknecht CLA 2021-07-20 07:56:38 EDT
(In reply to Leon Hofmeister from comment #5)
> - com.sun.*
> - jdk.*
> - org.graalvm.*
> - sun.*

+1

(In reply to Andrey Loskutov from comment #6)
> java.awt is my personal favorite to exclide, because it has java.awt.List
> that constantly collides with java.util.List and because of that automatic
> imports are nkt working. Beside this, java.awt is mostly irrelevant today.

+1


There is a risk, though. Would it be possible to add an entry to Content Assist that reminds people about active filters? Perhaps only if the proposals are empty?
Comment 8 Christoph Laeubrich CLA 2021-07-20 08:25:31 EDT
(In reply to Andrey Loskutov from comment #6)
> it has java.awt.List
> that constantly collides with
> java.util.List 
> and because of that automatic
> imports are nkt working. 

Bug 573028 would be maybe a better approach than simply exclude it by default.

The code-complete/suggest is sadly a bit to "dumb" in certain situations and could benefit from adding some heuristics (I was told IntelliJ is doing some good work in that area recently), e.g. with simply take into account:

- what is already used in this class
- what is used in other classes in the current project+dependent ones
- what has the user chosen before
- what is compatible in the given context
Comment 9 Christoph Laeubrich CLA 2021-07-20 08:27:50 EDT
(In reply to Gunnar Wagenknecht from comment #7)
> There is a risk, though. Would it be possible to add an entry to Content
> Assist that reminds people about active filters? Perhaps only if the
> proposals are empty?

I would find it most natural to have something like google/amazon/whatever function:

Your search result in no hits, but the following items are filtered and might contain something useful...

That would require content-assist to have a flag that tells it is a filtered item that is only shown if nothing else matches (or in an extra list below the normal completions).
Comment 10 Pierre-Yves Bigourdan CLA 2021-07-20 08:34:32 EDT
"io.micrometer.shaded." could be added to the defaults as well. This is a common use case for anyone using Spring Boot, or other popular frameworks that depend on Micrometer.
Comment 11 Noopur Gupta CLA 2021-07-22 05:03:11 EDT
(In reply to Christoph Laeubrich from comment #9)
> (In reply to Gunnar Wagenknecht from comment #7)
> > There is a risk, though. Would it be possible to add an entry to Content
> > Assist that reminds people about active filters? Perhaps only if the
> > proposals are empty?
> 
> I would find it most natural to have something like google/amazon/whatever
> function:
> 
> Your search result in no hits, but the following items are filtered and
> might contain something useful...
> 
> That would require content-assist to have a flag that tells it is a filtered
> item that is only shown if nothing else matches (or in an extra list below
> the normal completions).
This can be handled in a separate bug based on the need. The above approach with a flag might be useful. Currently, there's a link to the type filters preference page on the Content Assist preference page which can act as a hint for the users.
Comment 12 Noopur Gupta CLA 2021-07-22 05:05:38 EDT
(In reply to Leon Hofmeister from comment #4)
> I do have to say however that placing this option as part of "Appearance" is
> a little bit misleading, I would have rather expected it in "Code style",
> "Compiler" or "Editor"…
See bug 84472.
Comment 13 Lars Vogel CLA 2021-07-26 08:54:20 EDT
In reply to Leon Hofmeister from comment #5)
> - com.sun.*
> - jdk.*
> - org.graalvm.*
> - sun.*

+1


Is the above list controversial? If not I suggest to start with this and discuss the other proposals like awt in a separate bug.
Comment 14 Stephan Herrmann CLA 2021-07-27 08:24:58 EDT
IMHO the proposals discussed here should likely be ranked lower (low relevance because not accessible by rules of JPMS). I filed bug 575064 as a general enhancement.

Type filters could be seen as a poor-man's quick solution.
Comment 15 Noopur Gupta CLA 2021-07-28 05:06:17 EDT
(In reply to Stephan Herrmann from comment #14)
> IMHO the proposals discussed here should likely be ranked lower (low
> relevance because not accessible by rules of JPMS). I filed bug 575064 as a
> general enhancement.
> 
> Type filters could be seen as a poor-man's quick solution.
See also bug 48736.
Comment 16 Eclipse Genie CLA 2021-08-20 02:47:53 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/184251
Comment 17 Noopur Gupta CLA 2021-08-20 02:57:45 EDT
Created attachment 286975 [details]
Type filters - defaults

(In reply to Eclipse Genie from comment #16)
> New Gerrit change created:
> https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/184251
This adds the defaults as shown in the screenshot.

If a workspace has already defined type filters then this fix will not touch the enabled/disabled state of those existing type filters. It will just add the additional defaults from the above list.

Also, the defaults are added only once so that the users have a way to opt-out if they don't want the new filters.

This is handled in a way similar to bug 511443.
Comment 19 Eclipse Genie CLA 2021-08-24 08:54:45 EDT
New Gerrit change created: https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/184364
Comment 21 Noopur Gupta CLA 2021-08-26 03:08:25 EDT
Verified in I20210824-0600.
Comment 22 Christoph Laeubrich CLA 2021-10-05 09:28:05 EDT
I really like to reopen this due to the 'java.awt.*' default enabled.
Even though there are some cases (e.g. the list) where it could be annoying, but I really think this is a general issue of content assist not being context-sensitive/smart enough, this prevent usage of other useful classes from awt (e.g. BufferedImage, Colors and alike) and even prevents auto complete for constant field using this classes.
Comment 23 Andrey Loskutov CLA 2021-10-05 09:42:02 EDT
(In reply to Christoph Laeubrich from comment #22)
> I really like to reopen this due to the 'java.awt.*' default enabled.
> Even though there are some cases (e.g. the list) where it could be annoying,
> but I really think this is a general issue of content assist not being
> context-sensitive/smart enough, this prevent usage of other useful classes
> from awt (e.g. BufferedImage, Colors and alike) and even prevents auto
> complete for constant field using this classes.

Christoph, please create new bug for this, especially if it is about "general issue of content assist not being smart enough". This one has code already merged and should be kept closed.
Comment 24 Christoph Laeubrich CLA 2021-10-05 09:57:19 EDT
(In reply to Andrey Loskutov from comment #23)
> Christoph, please create new bug for this, especially if it is about
> "general issue of content assist not being smart enough". This one has code
> already merged and should be kept closed.

I could try to came up with a new bug, but the actual issue is that the code change here cause something a normal user could interpret as a regression (code completion suddenly does not work for any awt class), while from the comments the exclusion was meant to fix another problem (content assist not smart enough) so I'm not sure if the context of this bug would be more suitable...
Comment 25 Christian humer CLA 2021-10-18 14:56:51 EDT
The default file filter for the org.graalvm.* namespace severely impacts the usage of GraalVM user-facing APIs. I've filed https://bugs.eclipse.org/bugs/show_bug.cgi?id=576708 to track this.
Comment 26 Christian Dietrich CLA 2021-10-22 10:33:56 EDT
was there yet another change? we have failing tests with M2 again
Comment 27 Christian Dietrich CLA 2021-10-22 10:37:20 EDT
java.awt.* -> java.awt.List
Comment 28 Andrey Loskutov CLA 2021-10-22 10:47:18 EDT
(In reply to Christian Dietrich from comment #27)
> java.awt.* -> java.awt.List

See bug 576549