Author Topic: Scope and type of variable under caret  (Read 4121 times)

Offline e.p

  • Multiple posting newcomer
  • *
  • Posts: 12
Scope and type of variable under caret
« on: April 20, 2011, 10:33:12 am »
Hello!
I am new to the forum, so I hope this is the right place to ask this question.

I am working on a plugin and I need to know the type of the variable (in C language) under the caret (e.g. int, long,...).
Furthermore I need to know if it is a local or global variable and if it has the static attribute.
If the variable is local, I need to get the function where it is defined, too.

The hover-text generated by the code completion plugin could be parsed to obtain these informations.
But... how do I get this text into my plugin?
And how can I find out if the variable is static?

Regards, e.p


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13165
    • Travis build status
Re: Scope and type of variable under caret
« Reply #1 on: April 20, 2011, 12:45:20 pm »
I think this info is private for the CC plugin and another plugin can't access it.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline e.p

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Scope and type of variable under caret
« Reply #2 on: April 21, 2011, 09:33:57 am »
I think this info is private for the CC plugin and another plugin can't access it.

The modified version of CB is for internal use in our company only.
So it would not be a problem to modify the rest of CB too in order to gain access to this information.
But I cannot figure out where this text is originated inside CC.

Some hints? ;-)

Regards, e.p

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13165
    • Travis build status
Re: Scope and type of variable under caret
« Reply #3 on: April 21, 2011, 10:03:17 am »
You can start from:
CodeCompletion::OnValueTooltip
CodeCompletion::OnCodeComplete
CodeCompletion::OnShowCallTip

If you succeed in making this feature, I'll be happy to look at the patch (the debugger plugin can benefit from such feature:) )
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5325
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Scope and type of variable under caret
« Reply #4 on: April 21, 2011, 10:15:16 am »
Quite interesting feature.
You need to read the Token class under plugins\codecompletion\parser\token.h
Oh, it seems only "line" information is recorded, No column info is here.
In the feature, it can be added.

BTW: I have a test project based on QUEX, which can give a very nice lexer (give token id, token string, column, and line info) , but it is not mature right now. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline e.p

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Scope and type of variable under caret
« Reply #5 on: April 21, 2011, 12:01:00 pm »
oBFusCATed, thank you. I have found it.

I think I'll try to use a customized event to forward the message to my plugin.
I will tell you later if this works...

Regards, e.p

Offline e.p

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Scope and type of variable under caret
« Reply #6 on: April 21, 2011, 03:21:54 pm »
OK, it works.
I cannot show you the patch for two reasons: the development network is not attached to the internet and if you would see my C++ code you would cry blood :-/
So I'll try to explain you what I did:

- added in sdk_events.cpp and sdk_events.h two custom events: cbEVT_REQ_SCOPE and cbEVT_RESP_SCOPE
- an event of the first type is issued when I need the information
- added in codecompletion.cpp a RegisterEventSink pointing to a copy of OnValueTooltip. This copy is slightly different, e.g. the editor is not retrieved from the event. The active editor is used instead. Another difference is that the position used is the one of the caret.
- at the end of this function, istead of displaying the tooltip msg, an event is generated and the msg is added as string to it
- my plugin has a RegisterEventSink, too, fetches the second type of event, gets the strings and parses it

I hope you can undertand my description.

Thank you for your help!
Regards, e.p