Bug 488441 - [content assist] Substring proposals have incorrect relevance
Summary: [content assist] Substring proposals have incorrect relevance
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.6.1   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 481752
Blocks: 487668 501519
  Show dependency tree
 
Reported: 2016-02-25 04:56 EST by Noopur Gupta CLA
Modified: 2020-04-29 12:44 EDT (History)
6 users (show)

See Also:
manoj.palat: review+


Attachments
Proposed fix + Test (22.48 KB, patch)
2016-08-22 12:43 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Noopur Gupta CLA 2016-02-25 04:56:17 EST
public class Try18 {
	public static void main(String[] args) {
		n|
	}
}

- Press ctrl+space after 'n'.
=> Proposal for 'main(..)' (substring proposal) has a higher relevance than some other Types starting with 'n'.

----------------------------

public class Try18 {
	public static void main(String[] args) {
		y|
	}
}

- Press ctrl+space after 'y'.
=> Proposal for 'Try18' (substring proposal) has a higher relevance than other Types starting with 'y'.

----------------------------

See screenshot in bug 487668 comment #0.

Substring proposals should always be less relevant than applicable prefix proposals.
Comment 1 Jay Arthanareeswaran CLA 2016-02-25 05:38:34 EST
Quick glance, I see this:

Relevance for Try18:

BASE + RESOLVED + INTERESTING + SUBSTRING + UNQUALIFIED + NON_RESTRICTED (5 + 1 + 5 + (-1) + 3 + 3 = 16)

And for YearMonth:

BASE + RESOLVED + INTERESTING + NON_RESTRICTED (5 + 1 + 5 + 3 = 14)

The difference is the UNQUALIFIED.

Manoj, should we bump the relevance constant value for SUBSTRING? Even if we do, we need to weight it such that it neither undermines too much nor overwhelming depending on what we compare it with :)
Comment 2 Manoj N Palat CLA 2016-02-25 05:47:45 EST
Note: Jay would like to take this one up as he already has history of the dependent bug and has started to look at this (as discussed over private note) - assigning to Jay
Comment 3 Manoj N Palat CLA 2016-02-25 06:19:54 EST
(In reply to Jay Arthanareeswaran from comment #1)
> Quick glance, I see this:
> 
> Relevance for Try18:
> 
> BASE + RESOLVED + INTERESTING + SUBSTRING + UNQUALIFIED + NON_RESTRICTED (5
> + 1 + 5 + (-1) + 3 + 3 = 16)
> 
> And for YearMonth:
> 
> BASE + RESOLVED + INTERESTING + NON_RESTRICTED (5 + 1 + 5 + 3 = 14)
> 
> The difference is the UNQUALIFIED.
> 
> Manoj, should we bump the relevance constant value for SUBSTRING? Even if we
> do, we need to weight it such that it neither undermines too much nor
> overwhelming depending on what we compare it with :)

Jay: I think bumping up alone will not be a long term solution - in fact, I don't think a direct addition would satisfy the jdt.ui's requirement. 

quoting from comment 0,"Substring proposals should always be less relevant than applicable prefix proposals" -> this has an impllicit requirement hidden - that the proposals themselves need to be bucketized - A simple addition might give out mixed results - as you pointed out. 
[Not thinking of the external dependencies ] if we need to maintain a strict order within the proposals, then we would have to say Prefix starts at 200, Suffix Starts at 100, there by introducing a "base+offset" buckets where the prefix would always (well almost always) have a higher relevance than suffix.  Going forward this base+offset may be a simpler yet effective way to enforce strict boundaries of relevance.
Comment 4 Noopur Gupta CLA 2016-02-25 07:14:00 EST
See bug 481752 comment #4 also: "it would be OK to make substring matches more relevant if their result is assignable in the context."
Comment 5 Manoj N Palat CLA 2016-02-25 23:42:02 EST
(In reply to Noopur Gupta from comment #4)
> See bug 481752 comment #4 also: "it would be OK to make substring matches
> more relevant if their result is assignable in the context."

Well, we need to hit a common ground here :) - in other words, Is it better to make it more relevant in the above context - or is it that it doesn't matter?
Comment 6 Noopur Gupta CLA 2016-02-26 01:20:29 EST
(In reply to Noopur Gupta from comment #4)
> See bug 481752 comment #4 also: "it would be OK to make substring matches
> more relevant if their result is assignable in the context."

Example:

"s".st| => prefix proposals have higher relevance.

int i= "s".st| => substring proposals assignable in the context have higher relevance.
Comment 7 Jay Arthanareeswaran CLA 2016-04-05 03:04:24 EDT
I don't see an easy way out. We need to come up with a long term fix considering all possible scenarios. Moving out of 4.6.
Comment 8 Carsten Reckord CLA 2016-07-06 05:08:41 EDT
Just to add another case here - if substring proposals as well as prefix proposals are assignable in the context, prefix proposals should still be more relevant. E.g.

String msg="";
String[] parameters = {"a", "b", "c"};

System.out.println(msg+Arrays.as|);

=> the first proposal I got was for Arrays.deepHashCode. Expected proposal would have been Arrays.asList.
Comment 9 Jay Arthanareeswaran CLA 2016-08-22 01:21:51 EDT
So, to summarize, here's what we expect:

Prefix proposals should always have more relevance than substring except when the substring proposal is assignable in the context and the prefix proposal isn't assignable in the context. 

And what about camel case matches in comparison?
Comment 10 Jay Arthanareeswaran CLA 2016-08-22 01:51:10 EDT
I guess the substring offset should be just enough to offset the R_EXPECTED_TYPE but significantly less than R_EXACT_EXPECTED_TYPE.


(In reply to Carsten Reckord from comment #8)
> String msg="";
> String[] parameters = {"a", "b", "c"};
> 
> System.out.println(msg+Arrays.as|);
> 
> => the first proposal I got was for Arrays.deepHashCode. Expected proposal
> would have been Arrays.asList.

With my proposal above, it would continue to be the same. Because one of the exact expected type for the second operand in "msg + " is INT. So, all the methods that return INT would be listed ahead of asList. However, the following case would be different:

  System.out.println(Arrays.as);

Here asList would be the first proposal. Sounds good?
Comment 11 Jay Arthanareeswaran CLA 2016-08-22 04:20:59 EDT
So, the change that looks like will work for me is:

R_SUBSTRING -1 => -20

and R_DEFAULT 5 => 30

But looks like the challenge is going to be the hard-coded relevance. Worse, some testcases use some other combination of constants that produce the same relevance. This is going to be a nightmare to fix them all.
Comment 12 Noopur Gupta CLA 2016-08-22 04:24:20 EDT
(In reply to Jay Arthanareeswaran from comment #9)
> And what about camel case matches in comparison?

Camel case matches will be applicable only when a camel case pattern is typed. In that case, it should behave the same as before i.e. camel case matches should get higher priority.


(In reply to Jay Arthanareeswaran from comment #10)
> (In reply to Carsten Reckord from comment #8)
> > String msg="";
> > String[] parameters = {"a", "b", "c"};
> > 
> > System.out.println(msg+Arrays.as|);
> > 
> > => the first proposal I got was for Arrays.deepHashCode. Expected proposal
> > would have been Arrays.asList.
> 
> With my proposal above, it would continue to be the same. Because one of the
> exact expected type for the second operand in "msg + " is INT. So, all the
> methods that return INT would be listed ahead of asList. 

As summarized here:
(In reply to Jay Arthanareeswaran from comment #9)
> So, to summarize, here's what we expect:
> 
> Prefix proposals should always have more relevance than substring except
> when the substring proposal is assignable in the context and the prefix
> proposal isn't assignable in the context. 

In the above case, both substring and prefix proposals are assignable in the context. So the prefix proposal (asList) should get higher relevance.
Comment 13 Jay Arthanareeswaran CLA 2016-08-22 06:35:40 EDT
(In reply to Noopur Gupta from comment #12)
> In the above case, both substring and prefix proposals are assignable in the
> context. So the prefix proposal (asList) should get higher relevance.

There is a clear distinction in our code between R_EXPECTED_TYPE and R_EXACT_EXPECTED_TYPE. Add to that, we don't differentiate between that case and the following:

  int i = Arrays.as|

and I would imagine that hashCode() should get higher relevance here.
Comment 14 Jay Arthanareeswaran CLA 2016-08-22 09:12:34 EDT
I have pushed the test changes as prep work in master. This gets rid of hard-coded value for relevant constant R_DEFAULT.
Comment 15 Jay Arthanareeswaran CLA 2016-08-22 12:43:10 EDT
Created attachment 263706 [details]
Proposed fix + Test

The change is all about slightly modified relevance constant values. Note that in certain case, a prefix and substring proposals will get the same relevance where it boils down to alphabetic order. For e.g. this case asList() gets proposed first ahead of hashcode purely based on alphabetical order:

  System.out.println(msg + Arrays.as|)

However, in the following case asLIst() gets pushed down:

  System.out.println(msg + Arrays.AS) 

because it doesn't get the relevance for case matching.
Comment 16 Jay Arthanareeswaran CLA 2016-08-23 02:00:52 EDT
All JDT Core and UI tests pass. Released the fix here:

http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=a9d318d978e4e9e6f3804e5aae1e81ed6e4a0136

Also requesting Manoj for review for 4.6.1.
Comment 17 Jay Arthanareeswaran CLA 2016-08-25 01:39:09 EDT
Manoj is away at a conference, but he confirmed to me that he verified the fix on master as well as reviewed the patch.

Subsequently I have pushed the change in R4_6_maintenance:

http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=R4_6_maintenance&id=8e5f1dd5da000ba40b2faf1025b6a742b6cb7588
Comment 18 Sasikanth Bharadwaj CLA 2016-08-25 03:42:49 EDT
Verified for 4.6.1 RC2 using M20160824-0059 build. Just one observation though, comment 13 says hashCode should have higher relevance for the example mentioned there, (and I agree with that), but asList appears at the top of proposals. Not sure if that was implemented, but just thought may warrant another bug
Comment 19 Sasikanth Bharadwaj CLA 2016-08-25 03:50:29 EDT
Verified for 4.7 using I20160824-1429 build
Comment 20 Noopur Gupta CLA 2016-08-30 03:12:20 EDT
(In reply to Sasikanth Bharadwaj from comment #18)
> Verified for 4.6.1 RC2 using M20160824-0059 build. Just one observation
> though, comment 13 says hashCode should have higher relevance for the
> example mentioned there, (and I agree with that), but asList appears at the
> top of proposals. Not sure if that was implemented, but just thought may
> warrant another bug

I see #hashCode getting a higher relevance compared to #asList.