开发者

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, vsCME开发者_运维问答lement.vsCMElementFunction);

As an example.

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


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


I don't believe there's any way to do this now without parsing it yourself.

I think that the compiler as a service stuff that they're working on for a future version of VS will help with this.


They've added some CodeDOM stuff that could help. You'd be able to navigate the tree of code and search for the text. Here's a very basic introduction: http://msdn.microsoft.com/en-us/library/y2k85ax6%28v=vs.110%29.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜