Hello,
I am developing a Visual Studio Extension.
What I want to achieve:
When the user clicks anywhere in the editor, I want to show the cursors scope information (Function and class name) in a separate Tool Window.
How I am trying to achieve:
I am using the CodeElementFromPoint method on FileCodeModel to get the function or class name. But that method works great for C# code but for C++ code it works only for .cpp files.
Code Snapshot:
EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)ServiceProvider.GetService(typeof(EnvDTE.DTE));
TextSelection sel =
(TextSelection)dte.ActiveDocument.Selection;
TextPoint pnt;
if (sel != null)
{
pnt = (TextPoint)sel.ActivePoint;
CodeElement elemFunctionNew = dte.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint(pnt, vsCMElement.vsCMElementFunction);
}
Does anybody have a better idea how to achieve it or which approach should be taken for C++ language?
Thanks in advance.