English 中文(简体)
Highlight text from Visual Studio 2008 add-in
原标题:

I m writing another code coverage tool for .NET with Visual Studio 2008 integration.
Everything goes well except one thing: I can t find a way to highlight some code chunks.

I need it to inform user about covered and not covered blocks.
You can see example of the feature I want on the next screenshot (from native VS code coverage toolset):

Coverage Example

Can someone provide me a code snippet that highlights text in the code view window?
Links to appropriate MSDN articles related to VS2008 are also appreciated!

Thanks in advance.

最佳回答

I ve found the answer, see code below:

// 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);

More examples could be found in MetaScroll Visual Studio Addin.

问题回答




相关问题
How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Trouble with VS.PHP installing it s own Apache server

I tried installing VS.PHP some time ago. I was intent on seeing how it works with my current setup. I immediately encountered trouble: none of my sites wanted to render. On windows, I m using WAMP ...

Jquery and Intellisense in VS 2008 with hotfix and SP1

I followed Scott Guthrie s instructions as outlined at http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx but no avail: intellisense still doesn t work. Any tips?

Fixing "error C2065: undeclared identifier"

First off, I m completely out of my depth here. So the question might be the wrong one to ask, but here goes... As per the accepted answer to this question, I m trying to compile the bindings for the ...

View whitespace in VS2008

After Jeph most recent post: http://www.codinghorror.com/blog/archives/001310.html, I thought to myself it would be fun to see if any of my code has those trailing whitespaces. So I open Visual ...

热门标签