0

I am trying to write a visual studio addin. The following code is used to display the global variables or class names or function names of a selected text inside visual studio code window. However it do not display the variables defined inside a function. How can I modify this to display local variables?

'Call this function inside OnConnection event of the addin

Sub displayCodeElementName()

    ' Before running this example, open a code document from a project
    ' and place the insertion point inside a variable definition.
    Try
        ' Retrieve the CodeVariable at the insertion point.
        Dim sel As TextSelection = _
            CType(applicationObject.ActiveDocument.Selection, TextSelection)
        Dim var As CodeVariable2 = CType(sel.ActivePoint.CodeElement(vsCMElement.vsCMElementVariable), CodeVariable2)

        ' Display the code element name

            MsgBox(var.Name & " is the name.")

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End sub
Jehonathan Thomas
  • 2,110
  • 1
  • 28
  • 34

1 Answers1

0

It appears that the underlying API is not made public by Microsoft. I did a research and nowhere I could find a way to access the code elements inside a function definition.

Jehonathan Thomas
  • 2,110
  • 1
  • 28
  • 34