Bug 427201 - [content assist] Direct assignment of return value on content proposal selection
Summary: [content assist] Direct assignment of return value on content proposal selection
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-01 16:55 EST by Marco Descher CLA
Modified: 2014-05-09 06:32 EDT (History)
5 users (show)

See Also:


Attachments
embedding place (86.93 KB, image/png)
2014-02-12 01:33 EST, Marco Descher CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Descher CLA 2014-02-01 16:55:02 EST
As mentioned in http://stackoverflow.com/questions/21482918/auto-generate-variable-for-return-value-of-method I miss a content proposal method to have the return value of a method as delivered by content proposal do a direct assignment to a variable.

That is (see above example)

sps.[CTRL+SPACE] should allow for a single selection to return me the respective getter method and a variable assignment.

So instead of having to

sps.[CTRL+SPACE] --> select getChildren [ENTER]
sps.getChildren() [CTRL+2]+L
List<foo> = sps.getChildren()

a one presser would be nice. Like

sps.[CTRL+SPACE] --> select getChildren [CTRL+ENTER]

I think this would be more intuitive than the way over quick fix.
Comment 1 Dani Megert CLA 2014-02-11 10:41:39 EST
> I think this would be more intuitive than the way over quick fix.

I don't think it's intuitive that one knows, Ctrl+Enter directly assigns to a variable and it's definitely not discoverable.

There are no plans to overload content assist in such a way.
Comment 2 Marco Descher CLA 2014-02-12 01:33:54 EST
Created attachment 239846 [details]
embedding place

Well, if it would be mentioned in the botton line (see image) then I guess it would be obvious.

What do you mean by "there are no plans"? That, you are not considering this, that you think it is unnecessary, ... if so, please resolve as WONTFIX

thanks
Comment 3 Dani Megert CLA 2014-02-12 04:51:38 EST
As you see in your picture, that space is already used. Showing two hints would overload the status line.
Comment 4 Marco Descher CLA 2014-03-05 15:20:43 EST
Realising it like the postfix feature in IntelliJ (see http://blog.jetbrains.com/idea/2014/03/postfix-completion/) would be a very good approach!
Comment 5 Sven Efftinge CLA 2014-03-06 02:14:40 EST
(In reply to Marco Descher from comment #4)
> Realising it like the postfix feature in IntelliJ (see
> http://blog.jetbrains.com/idea/2014/03/postfix-completion/) would be a very
> good approach!

That would turn your request into two distinct completion proposal. I.e. one for "getChildren()" and one for "assign to new local variable". Which makes more sense to me. We should investigate (maybe just work a bit with intellij) how cool this feature really is in practice. Also generally in template proposals it would be cool, to have access to the receiver expression, such that you can surround it with text rather than just appending text.
Comment 6 Marco Descher CLA 2014-03-06 09:10:39 EST
(In reply to Sven Efftinge from comment #5)
> (In reply to Marco Descher from comment #4)
> > Realising it like the postfix feature in IntelliJ (see
> > http://blog.jetbrains.com/idea/2014/03/postfix-completion/) would be a very
> > good approach!
> 
> That would turn your request into two distinct completion proposal. I.e. one
> for "getChildren()" and one for "assign to new local variable". Which makes
> more sense to me. We should investigate (maybe just work a bit with
> intellij) how cool this feature really is in practice. Also generally in
> template proposals it would be cool, to have access to the receiver
> expression, such that you can surround it with text rather than just
> appending text.

Resolving it could work like sps.[CTRL+SPACE; select getChildren()].[CTRL+SPACE; select assignToNewLocalVariable] 

Would it be possible to add scripting capability here? So one could write a script named "assignToNewLocalVariable" which just executes the aforementioned [CTRL+2]+L at this place and is presented in the content proposal?!
Comment 7 Timo Kinnunen CLA 2014-03-06 10:46:45 EST
One option might be to change Content Assist popup so that instead of eating a shortcut key combination it doesn't recognize it could treat it like a confirmation, perform the change and after that pass the original shortcut key to the underlying editor to be handled. So you could have 'Assign to new local variable' command bound to Ctrl+; and could press that instead of Enter to confirm the selected item.
Comment 8 Lars Vogel CLA 2014-03-07 01:00:17 EST
I agree with Dani, that [CTRL+ENTER] is hard to discover and it is is more or less the same as [CTRL+2]+L.

But I really like the idea of using [CTRL+ENTER] to propose also a variable assignment. Dani, would that fit in the JDT architecture? I think such a functionality could also be used to implement PostFix completion similar to IntelliJ.
Comment 9 Timo Kinnunen CLA 2014-04-02 10:13:22 EDT
I've pushed a patch to Gerrit for bug 428139 which among other things adds a key binding Ctrl-Alt-Left Arrow for extracting new local variable from an expression or a method call, like you would have after using Content Assist. It may provide another way of satisfying some of the use-cases in this bug. Please try it out to see if it works for you.