Visual Studio Extensibility / Margins

做~自己de王妃 提交于 2020-01-06 04:21:05

问题


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?


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/4985697/visual-studio-extensibility-margins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!