我正在使用 Visual Studio 2008 集成为 .NET 编写另一个代码覆盖工具。
一切都很顺利,除了一件事:我找不到突出显示某些代码块的方法。
我需要它来通知用户有关覆盖和未覆盖的块。
您可以在下一个屏幕截图中看到我想要的功能示例(来自本机 VS 代码覆盖工具集):
有人可以为我提供一个代码片段,在代码视图窗口中突出显示文本吗?
也感谢与 VS2008 相关的适当 MSDN 文章的链接!
提前致谢。
我正在使用 Visual Studio 2008 集成为 .NET 编写另一个代码覆盖工具。
一切都很顺利,除了一件事:我找不到突出显示某些代码块的方法。
我需要它来通知用户有关覆盖和未覆盖的块。
您可以在下一个屏幕截图中看到我想要的功能示例(来自本机 VS 代码覆盖工具集):
有人可以为我提供一个代码片段,在代码视图窗口中突出显示文本吗?
也感谢与 VS2008 相关的适当 MSDN 文章的链接!
提前致谢。
我找到了答案,请参见下面的代码:
// retrieving IVsTextManager and highlight id
DTE2 applicationObject = ...; // get it during addin init
Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider = (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)applicationObject;
Guid SID = typeof(SVsTextManager).GUID;
Guid IID = typeof(IVsTextManager).GUID;
IntPtr output;
serviceProvider.QueryService(ref SID, ref IID, out output);
IVsTextManager textManager = (IVsTextManager)Marshal.GetObjectForIUnknown(output);
int highlightID;
Guid highlightGuid = ...; // your highlighted text style guid
textManager.GetRegisteredMarkerTypeID(ref highlightGuid, out highlightID);
// highlighting text block in the active view
IVsTextView view;
int result = textManager.GetActiveView(0, null, out view);
IVsTextLines buffer;
view.GetBuffer(out buffer);
buffer.CreateLineMarker(highlightID, startLine, startColumn, endLine, endColumn, null, null);
更多示例可以在MetaScroll Visual Studio Addin中找到。