I’m creating a Visual Studio add in, and while the basic functionality is complete, I’m trying to add some new features.
One of the features I’m planning requires the name of the method and/or class the cursor is currently located.
Take a look at the image above. It shows a Visual Studio editor with a Python file loaded. This file is not part of a project.
During my searches I encountered several references to use “FileCodeModel” or even “ITextStructureNavigatorSelectorService”.
But none of them work correctly. For example, the file shown in the image above is not part of a project, so the FileCodeModel is null for that specific file. And yet, Visual Studio shows the correct breadcrumbs at the top of the editor.
And if Visual Studio can do it, it should mean that we could query it and have this information.
What I need is to get the name of the method and/or class at the cursor in a language agnostic way. I mean, I don’t want it to be specific to C# or VB. I want ti to work with Python, JavaScript, HTML, SQL, or whatever language Visual Studio supports.
How can I do it?
