locked
Macro: Find type of variable at cursor position? RRS feed

  • Question

  • Can I use the code model in Visual Studio 2010 or 2012 to find the type of variable at the cursor position?

    I would like to do this in a macro or add-in. I have Windows 7 SP1.

    I have been able to find the name of the routine at the cursor position, but not information about the variable at the cursor position.


    Frank

    Saturday, November 17, 2012 3:15 PM

Answers

  • Hi Frank,

    Unfortunately, the answer here is no. The CodeModel APIs aren't granular enough, nor are there any API's/Interfaces exposed that would allow for this. You'd essentially have to build your own compiler to do this. :-(

    There is some ongoing work in this area for C# and VB though. The Roslyn project will open the compiler for such purposses, though  it won't support C++ anytime soon. But there is a CTP compatible with VS 2012, that you can experiment with.

    Sincerely,


    Ed Dore

    Tuesday, November 27, 2012 10:19 PM

All replies

  • Hi OldGrouch,

    I found an example you can refer to:

    http://www.mztools.com/articles/2006/mz2006009.aspx

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Monday, November 19, 2012 6:47 AM
  • Thanks, but I had already tried that sample. It works for functions, but not for variables. That is why I posted my question above.

    Regards,


    Frank

    Monday, November 19, 2012 1:20 PM
  • Hi OldGrouch,

    I will involve some experts into this issue to see whether they can help you out. There might be some time delay, appreciate for your patience.
     
    Thank you for your understanding and support.
     
    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, November 20, 2012 8:39 AM
  • Hi,

    The code model allows you to find class variables (fields), but not method variables. To find method variables you need to parse the code by yourself.

    You can also start playing with Roslyn:

    http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/

    Tuesday, November 20, 2012 9:03 AM
  • Hi Frank,

    Unfortunately, the answer here is no. The CodeModel APIs aren't granular enough, nor are there any API's/Interfaces exposed that would allow for this. You'd essentially have to build your own compiler to do this. :-(

    There is some ongoing work in this area for C# and VB though. The Roslyn project will open the compiler for such purposses, though  it won't support C++ anytime soon. But there is a CTP compatible with VS 2012, that you can experiment with.

    Sincerely,


    Ed Dore

    Tuesday, November 27, 2012 10:19 PM
  • Thanks for the information.

    Frank

    Tuesday, November 27, 2012 10:45 PM