Search code examples
visual-studiomefvs-extensibility

Visual Studio Extensibility / Margins


I am trying to build a Margin (through MEF) as a VS addin. I need to get the lines that contain the definition of a method. I have found people doing such things but it seems most are parsing test. This seems like a really bad idea as it would obviously only work with languages you knew how to parse.

In an addin I can access the document in a programmatic fashion using a higher level model:

var fcm = _application.ActiveDocument.ProjectItem.FileCodeModel;
var elem = fcm.CodeElementFromPoint(point, vsCMElement.vsCMElementFunction);

As an example.

Is there anyway to do this from within the MEF stuff when trying to draw the margin?


Solution

  • OK so it can be done.

    The general process for this is: 1) ITextBuffer -> ITextDocument (which has a file name) 2) Use the file name find the project item (eg: recurse project items) 3) Get FCM from the project item and use it