Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: AW: [cdt-dev] value of a constant in a tooltip

Hi Ralph,

k, I see now ... nifty, that one.
No, this feature is not currently implemented in the CDT. We would have to 
have a little bit of compiler ability to compute the value of enumerated 
constants, right?
On the other hand it may be doable when the code has been parsed and we have 
the AST available. If you like to look into the workings then look at class 

org.eclipse.cdt.internal.ui.text.c.hover.BestMatchHover.getHoverInfo(ITextViewer, 
IRegion)

Here all registered hover contributors are called, one by one, and the first 
to supply information gets picked.
Note that the registered hover contributors are collected once upon 
initialisation in CUIPlugin.getCEditorTextHoverDescriptors()

Text hovers can be contributed via the org.eclipse.cdt.ui.textHovers extension 
point. So you could

a) contribute a new text hover. The disadvantage is that, currently, the 
evaluation order of contributed hovers is (almost completely) random, but the 
first hover contributor which gives information wins. So there is currently 
no way to know whether your new hover will actually get the chance to display 
it's knowledge.

b) augment the existing org.eclipse.cdt.internal.ui.text.c.hover.CSourceHover 
so that it will add the computed enumeration value to the hover text. 
Interesting idea, though I am not sure how much effort this will take.

The simple alternative may be to add comments specifying the numeric value on 
the same line and then the code hover will display the information along with 
the definition?


Cheers,


Norbert

> Hi Norbert,
>
> > can you give us a code snippet for a constant for which you would > like
> > the tooltip.
>
>   enum StateMachine {
>                       Idle,
>                       Start,
>                       Wait,
>                       ...,
> #ifdef TARGET_A
>                       TargetAspecificState,
> #endif
>                       ...,
> #if defined(TARGET_A) || defined(TARGET_B)
>                        TargetAandBspecificState,
> #endif
>                       ...
>                       AnyOtherState,
>                       ...
>                     };
>
>   ...
>
>   enum StateMachine StateMachine;
>
>   ...
>
>     switch (StateMachine)
>     {
>       case Idle:
>         ...
>         break;
>       case Start:
>         ...
>         break;
>
>       case AnyOtherState:
>         ...
>         break;
>       ...
>     }
>
>   ...
>
> The state machines have up to 60 states, so I'm looking for an easier way
> to find the value of AnyState than counting the value myself.
>
> Bye,
>   Ralf Ebert
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev


Back to the top