Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

Traversing all EnvDTE.CodeElement objects in the global/local scope

$
0
0
Is it possible to traverse all the CodeElement objects in a given source file?
My real target is to be able to find out what is the type of a variable in the cursor position from a Visual Studio Add-in.. I have tried the following code:

                    // identify where the cursor is                    TextSelection selection =                      (TextSelection)_applicationObject.ActiveWindow.Selection;                    // get the starting point                    EditPoint Start = selection.TopPoint.CreateEditPoint();                    // get the element under the cursor                    CodeElement element = _applicationObject.ActiveDocument.ProjectItem.                       FileCodeModel.CodeElementFromPoint(Start,                       vsCMElement.vsCMElementVariable);                                        if (element.Kind == vsCMElement.vsCMElementVariable)                    {                        CodeVariable theVar = element as CodeVariable;                        string t = theVar.Type.AsString;                        MessageBox(t);                    }



but it has some problems:
- It works only in a scope of a class, not in a function scope or global scope(in case of c++ source)
- It works when the cursor is in the position of the declaration, I want it to work when the cursor is in the position of a use of the variable.

So is there any way to get this semantic information without building my own compiler?



Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>