Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 271252 - [content assist] Insertion of best guessed arguments not working
Summary: [content assist] Insertion of best guessed arguments not working
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Mylyn (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows Vista
: P1 normal (vote)
Target Milestone: 3.2.2   Edit
Assignee: Steffen Pingel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 294233 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-04-05 15:20 EDT by James Synge CLA
Modified: 2009-11-06 03:14 EST (History)
6 users (show)

See Also:


Attachments
content assist -> advanced -> disable task focused proposal (124.67 KB, image/png)
2009-05-29 11:20 EDT, Ryan CLA
no flags Details
fix (3.23 KB, patch)
2009-09-02 17:31 EDT, Steffen Pingel CLA
no flags Details | Diff
fix that compiles on 3.3 (3.71 KB, patch)
2009-09-02 18:19 EDT, Steffen Pingel CLA
no flags Details | Diff
mylyn/context/zip (19.20 KB, application/octet-stream)
2009-09-02 18:20 EDT, Steffen Pingel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Synge CLA 2009-04-05 15:20:05 EDT
Build ID: I20090313-0100
Downloaded "Eclipse Modeling Tools (includes Incubating components)" from the Eclipse Packaging Project.

Steps To Reproduce:
1. Enable:
     Window > Preferences 
     Java > Editor > Content Assist
     Enable "Fill method arguments and show guessed arguments"
     Enable "Insert best guessed arguments"
2. Paste the following code into a source folder:

public class Test
{
  void foo(String s) {}
  void bar() {
    String myString = null;
    //foo
  }
}

3. Uncomment the //foo, and hit control-space at the end of that line.
4. JDT will insert:

   (s);

and not:

   (myString);
Comment 1 Dani Megert CLA 2009-04-06 03:19:46 EDT
Your example works for me using plain Eclipse SDK 3.5 M6 and I20090331-0901. Maybe one of the additional plug-ins modifies content assist (I know Mylyn does).
Comment 2 Dani Megert CLA 2009-04-06 03:25:31 EDT
.
Comment 3 Ryan CLA 2009-05-29 11:07:17 EDT
I have the same problem with Eclipse 3.5 RC1. I am using mylyn however even when I disable the current task it always uses the parameter name for the auto complete instead of guessing based on type.
Comment 4 Dani Megert CLA 2009-05-29 11:09:23 EDT
> I am using mylyn
Exactly my point ;-)
Comment 5 Ryan CLA 2009-05-29 11:20:49 EDT
Created attachment 137660 [details]
content assist -> advanced -> disable task focused proposal

Dani is correct disabled the task focused proposal causes the correct suggestion to be selected. At any rate this is a bug is it not? If not for jdt then for mylyn.
Comment 6 Dani Megert CLA 2009-05-29 11:34:07 EDT
.
Comment 7 Steffen Pingel CLA 2009-06-16 17:44:48 EDT
I can reproduce that with the latest Java package but not when running in debug mode. Will investigate further in the next release cycle.
Comment 8 Steffen Pingel CLA 2009-08-19 19:47:39 EDT
Here is what I have found out: The "Java Proposals (Task-Focused)" category provided by Mylyn will actually return the right proposal when the "Template Proposals" provider is disabled. Enabling the template proposals causes the context that is checked in ParameterGuessingProposal.createProposal() to not have the extended flag set.

The reason that the same bug does not occur when the default JDT "Java Proposals" categories is enabled seems to be due to the fact that CompletionProposalComputerRegistry.reload() always reads the JDT categories first. When the default configuration is enabled this causes the Java Proposals computer to run before the Template Proposals whereas the Mylyn Task-Focused Proposals are always run after the Template Proposals.

I don't understand the data flow of the JavaContentAssistInvocationContext object that is passed around well enough to propose a fix. 

Dani, do you have any ideas how to move forward here?



Comment 9 Dani Megert CLA 2009-09-01 08:49:59 EDT
Sorry for the delay Steffen, I was pretty busy lately. I've looked at the code and you are right there's an issue on the framework side as it does not ask all participating completion proposal computers to configure the internally used collector (filed bug 288242 to track this).

You can workaround this for now by computing the core context for your processor(s) yourself:

CompletionProposalCollector collector= new CompletionProposalCollector(cu, true);
collector.setRequireExtendedContext(true);
// set additional options
cu.codeComplete(getInvocationOffset(), collector);
collector.getContext();
Comment 10 Steffen Pingel CLA 2009-09-01 15:58:51 EDT
Thanks! I'll try that.
Comment 11 Steffen Pingel CLA 2009-09-02 17:31:18 EDT
Created attachment 146328 [details]
fix

The patch is a bit hacky but I couldn't find any good way to make this work other than by resetting the core context to null to force recomputation. Shawn, can you sanity check this patch?
Comment 12 Steffen Pingel CLA 2009-09-02 18:19:43 EDT
Created attachment 146332 [details]
fix that compiles on 3.3
Comment 13 Steffen Pingel CLA 2009-09-02 18:20:23 EDT
Committed to head and 3.2.x maintenance branch.
Comment 14 Steffen Pingel CLA 2009-09-02 18:20:27 EDT
Created attachment 146334 [details]
mylyn/context/zip
Comment 15 Dani Megert CLA 2009-09-03 08:39:29 EDT
Steffen, just a quick question: do you use your own completion proposal collector? If so, I guess it already set to use an extended context, right?
Comment 16 Steffen Pingel CLA 2009-09-03 13:32:00 EDT
(In reply to comment #15)
> Steffen, just a quick question: do you use your own completion proposal
> collector? If so, I guess it already set to use an extended context, right?

Yes. Mylyn's computer extends JavaCompletionProposalComputer which sets up the collector and sets the extended flag but by the time it is invoked the cached copy in the invocation context has already been created by TemplateCompletionProposalComputer I think.
Comment 17 Dani Megert CLA 2009-09-04 03:00:41 EDT
>but by the time it is invoked the cached
>copy in the invocation context has already been created by
>TemplateCompletionProposalComputer I think.
OK, that helps. This also means you use your own collector instance. We mainly need the cache in 'JavaContentAssistInvocationContext' for two reasons:
- give context to those that actually don't do a Java code assist (e.g. keyword or
  spelling proposals)
- compute keywords only once

Now, if a computer already has its own collector then we should always use that one instead of the cached one. This makes fixing bug 288242 easy.
Comment 18 Steffen Pingel CLA 2009-09-04 16:07:59 EDT
Great. The work-around in Mylyn will be available in 3.2.2 and later versions. We'll remove it once support for Eclipse 3.4 and 3.5 has ended.
Comment 19 Dani Megert CLA 2009-11-06 03:14:28 EST
*** Bug 294233 has been marked as a duplicate of this bug. ***