Bug 461680 - [Content Assist] Enhance parameter hints
Summary: [Content Assist] Enhance parameter hints
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: Next   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 9.3.0   Edit
Assignee: Nathan Ridge CLA
QA Contact: Anton Leherbauer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-09 03:02 EDT by Mathias Kunter CLA
Modified: 2017-02-09 20:22 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mathias Kunter CLA 2015-03-09 03:02:56 EDT
Display complete function prototypes within the parameter hints instead of just the parameter list itself. For example, instead of just displaying "int x" as parameter hint, display "void MyClass::foo(int x)" as hint, whereby "int x" is of course in bold.

Benefits:

-> See the function return type directly within parameter hints.
-> See which exact function is called directly within parameter hints. This is especially helpful when calling virtual functions, since you can easily see which virtual function implementation is actually invoked by looking at the class name.
Comment 1 Nathan Ridge CLA 2017-01-17 22:05:01 EST
(In reply to Mathias Kunter from comment #0)
> -> See which exact function is called directly within parameter hints. This
> is especially helpful when calling virtual functions, since you can easily
> see which virtual function implementation is actually invoked by looking at
> the class name.

I'm confused by this. How would you know which virtual function implementation will be invoked? The whole point of virtual functions is that you don't know which one will be invoked until runtime.
Comment 2 Nathan Ridge CLA 2017-01-17 23:30:15 EST
(In reply to Nathan Ridge from comment #1)
> (In reply to Mathias Kunter from comment #0)
> > -> See which exact function is called directly within parameter hints. This
> > is especially helpful when calling virtual functions, since you can easily
> > see which virtual function implementation is actually invoked by looking at
> > the class name.
> 
> I'm confused by this. How would you know which virtual function
> implementation will be invoked? The whole point of virtual functions is that
> you don't know which one will be invoked until runtime.

I guess you mean that we should show the static type of the object on which the method is being called, even if the method itself was declared in the base class of that static type.
Comment 3 Mathias Kunter CLA 2017-01-18 03:59:29 EST
Sorry for not being clear about this.

Note that you actually do know at compile time which virtual function is invoked IFF that virtual function is NOT re-implemented within a type derived from the static object type on which the method is being called.

An example:


class Base {
    void func() { }
    virtual void vFunc1() { }
    virtual void vFunc2() { }
};

class Derived : public Base {
    virtual void vFunc1() { }
};

void main() {
    Base *b = new Derived();
    Derived *d = new Derived();

    b->vFunc1();      // must be resolved at runtime
    d->vFunc1();      // known at compile time: calls Derived::vFunc1()

    b->vFunc2();      // known at compile time: calls Base::vFunc2()
    d->vFunc2();      // known at compile time: calls Base::vFunc2()
}


So, I'd suggest parameter hints to be the following:


void main() {
    Base *b = new Derived();
    Derived *d = new Derived();

    b->func(*** PARAMETER HINTS: "void Base::func()" ***);
    d->func(*** PARAMETER HINTS: "void Base::func()" ***);

    b->vFunc1(*** PARAMETER HINTS: "virtual void Base::vFunc1()" ***);
    d->vFunc1(*** PARAMETER HINTS: "void Derived::vFunc1()" ***);

    b->vFunc2(*** PARAMETER HINTS: "void Base::vFunc2()" **** );
    d->vFunc2(*** PARAMETER HINTS: "void Base::vFunc2()" **** );
}
Comment 4 Nathan Ridge CLA 2017-01-18 11:22:01 EST
(In reply to Mathias Kunter from comment #3)

Thanks, that makes sense. One question:

>     b->vFunc1(*** PARAMETER HINTS: "virtual void Base::vFunc1()" ***);
>     d->vFunc1(*** PARAMETER HINTS: "void Derived::vFunc1()" ***);
> 
>     b->vFunc2(*** PARAMETER HINTS: "void Base::vFunc2()" **** );
>     d->vFunc2(*** PARAMETER HINTS: "void Base::vFunc2()" **** );

Why would there be no "virtual" in the last three? A class could derive from Derived and override either of vFunc1 or vFunc2.
Comment 5 Mathias Kunter CLA 2017-01-18 12:15:52 EST
(In reply to Nathan Ridge from comment #4)
> Why would there be no "virtual" in the last three?

My thoughts were that omitting the "virtual" keyword for these parameter hints would tell the user that this is the method which becomes *actually* invoked when calling the virtual function. This is sometimes very nice to know.

However, you're right that this could confuse users, so maybe it's better to just always display the "virtual" keyword within the parameter hints, even if the actually invoked function can be statically detected.

> A class could derive from Derived and override either of vFunc1 or vFunc2.

As soon as this happens, the parameter hints would of course have to display the "virtual" keyword again.
Comment 6 Eclipse Genie CLA 2017-01-19 21:46:53 EST
New Gerrit change created: https://git.eclipse.org/r/89160
Comment 7 Nathan Ridge CLA 2017-01-19 21:48:39 EST
The behaviour I implemented matches what you describe in comment 3, with the exception that "virtual" is displayed in the last three cases as well.
Comment 8 Mathias Kunter CLA 2017-01-20 03:46:49 EST
Very nice! Thank you, Nathan.

One more question, though: are default parameter values also displayed within the new parameter hints? E.g. something like

> virtual void Base::vFunc1(int x = 1, int y = 2)
Comment 9 Nathan Ridge CLA 2017-01-20 11:15:10 EST
(In reply to Mathias Kunter from comment #8)
> One more question, though: are default parameter values also displayed
> within the new parameter hints? E.g. something like
> 
> > virtual void Base::vFunc1(int x = 1, int y = 2)

We already show default parameter values (that was added in bug 418493), and we'll continue to do so with this change.
Comment 11 Nathan Ridge CLA 2017-01-26 20:33:19 EST
Fixed for 9.3.
Comment 12 Nathan Ridge CLA 2017-02-09 20:22:09 EST
Mentioned in the 9.3 N&N: https://wiki.eclipse.org/CDT/User/NewIn93#Enhanced_parameter_hints