Bug 420953 - [subwords] Constructors that don't match prefix not found
Summary: [subwords] Constructors that don't match prefix not found
Status: CLOSED DUPLICATE of bug 377373
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Recommenders (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 8
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on: 377373
Blocks:
  Show dependency tree
 
Reported: 2013-11-02 22:13 EDT by Timo Kinnunen CLA
Modified: 2019-07-24 14:35 EDT (History)
4 users (show)

See Also:


Attachments
Couple of test cases (889 bytes, text/plain)
2013-11-02 22:13 EDT, Timo Kinnunen CLA
no flags Details
Resulting proposals (415.56 KB, image/png)
2013-11-02 22:15 EDT, Timo Kinnunen CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Timo Kinnunen CLA 2013-11-02 22:13:50 EDT
Created attachment 237155 [details]
Couple of test cases

Subwords completion doesn't find most constructors of available types when completing with a pattern like this:

Deque<Path> paths = new deque|

None of the available constructors from ArrayDeque, ConcurrentLinkedDeque or LinkedBlockingDeque are offered.

Tested with 
Eclipse SDK Version: 4.4.0 Build id: I20131030-2000
Recommenders 2.0.1.v20131101-0937
Comment 1 Timo Kinnunen CLA 2013-11-02 22:15:13 EDT
Created attachment 237156 [details]
Resulting proposals
Comment 2 Marcel Bruch CLA 2013-11-02 23:34:09 EDT
Think you describe a known issue we have with JDT's type completion. Unfortunately, there is no simple fix possible yet with JDT's infrastructure.

In order to fix this, one needs to 

1. list of all known types in the project code completion was triggered in (potentially thousands of types), 
2. has to filter all these names by subwords-matching, 
3. create new type completion proposals and 
4. add them to the list.

While 3 and 4 are (kind of) easy, I'm not sure whether we could efficiently solve 1+2.

Stephan, any idea which (maybe internal) classes we should use for step 1.?
Comment 3 Marcel Bruch CLA 2013-11-02 23:41:26 EDT
To clarify: type completions and constructor completions have the same restrictions in JDT.
Comment 4 Timo Kinnunen CLA 2013-11-04 10:32:31 EST
1 and 2 don't have to be that hard in this particular usage pattern. The tokens preceding the caret position have a distinctive pattern:

 Type TYPEOPEN Type TYPECLOSE Identifier ASSIGN NEW Hint? CARET

The types mentioned have already gone through the proposal'n'acceptance cycle and their imports are in place. They might have been written to disk too (I save constantly to keep my code properly formatted). In this case Quick Type Hierarchy at the beginning of the line (press Home, Ctrl-T) would be almost exactly what I wanted to see.

Could those types from earlier completions be tagged to the dirty AST temporarily until the file is saved? Then the unsaved portions of the file could have as much type information as the rest of it.
Comment 5 Marcel Bruch CLA 2013-11-28 02:55:16 EST
That's unfortunately not possible. Caching types used earlier and adding them into completion if not already in also feels a bit too much like magic/would be even much more inconsistent with subwords completion for methods.

I'd prefer an approach that finds all available types and filters them according to the prefix. FWIW, this list of types may be cached to make this approach faster.

Just to let you know: We are currently focussing on other areas and this is likely not happening in 2.0.x except someone volunteers to look into this.
Comment 6 Timo Kinnunen CLA 2013-11-28 11:19:15 EST
I've been looking into it on and off but the different AST and type hierarchy and model APIs are numerous and connected in obscure ways. It turns out that the "magic" is not needed, the code has already been scrubbed and "compiled" by the time the completion engine gets it. 

My current thinking is to populate expectedTypes ObjectVector which already contains the type mentioned in the editor with all of its subtypes too. Then all that's needed is to relax the prefix test and everything should proceed from there. Now how do I get an IType from a ReferenceBinding?
Comment 7 Marcel Bruch CLA 2013-11-28 12:22:20 EST
Can you push a draft of what you are doing into Gerrit? I'm not sure why you need to convert a compiler binding to an IType first. But maybe I miss some details in which case the code you are writing could shed some more light on :)

FWIW, converting ReferenceBinding to an IType is (AFAIK) not a frequently used approach. The only code I'm aware of that does that conversion is in
org.eclipse.jdt.internal.core.search.matching.MatchLocator.lookupType(ReferenceBinding)

Maybe Stephan knows a better approach. But as I said, I don't think we need that conversion (the other way is simpler :).
Comment 8 Timo Kinnunen CLA 2013-11-28 13:36:07 EST
I really don't have much to commit. My latest foray was into trying to add subtypes at CompletionEngine.findTypesFromExpectedTypes() which got me thinking about doing it in CompletionEngine.computeExpectedTypes() instead. But both of those need the list of subtypes, which IType.newTypeHierarchy() provides. Quick Type Hierarchy uses that as well. Oh right, I also need the IType to ReferenceBinding conversion :)

I'll check out MatchLocator, thanks.
Comment 9 Marcel Bruch CLA 2013-11-29 10:51:10 EST
Regarding subtype matches:

Don't use IType.newTypeHierarchy and IType in general to do subtype checks. It's too slow. We have a prototype that uses the compiler internal bindings that works quite well. But note that even this solution causes some recognizable delays when there are hundreds to thousand of type proposals.

Regarding subwords matches:
This still needs a list of all available types to be filtered.


We shouldn't mix these two topics in this bug. Please create a new one if you like to discuss subtype matchings.
Comment 10 Marcel Bruch CLA 2013-12-11 03:13:26 EST
Closing this as a duplicate of bug 377373. 


regarding subtype discussion in this thread:
I've implemented an experimental subtype-aware type completion (which has the prefix limitations as mentioned above).

If interested, please check out https://plus.google.com/100908752439953740476/posts/jfeAHvsJAC5 and provide feedback there.


FWIW, I'd be glad to get rid of the prefix issue for type completions. Any patches for this feature are highly welcome.

*** This bug has been marked as a duplicate of bug 377373 ***
Comment 11 Timo Kinnunen CLA 2013-12-11 14:08:10 EST
You're in luck, I just happen to have that implemented :) Commented in bug 377373.