Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

How do I get an instance of IVsExpansionClient in VSPackage?

$
0
0

Documentation for extending Visual Studio is virtually nonexistent, and I managed to assemble a few lines of functioning code hacked together from a dozen or more obscure sources around the interwebs before crashing into a brick wall.

All I need to do is subscribe to an event that is fired after a snippet is inserted. Sounds easy enough, or so I thought. Almost immediately into my research I stumbled upon the following morsel:

IVsExpansionClient.OnAfterInsertion

That describes perfectly my intention, so this MUST be the answer! After looking around my SDK assemblies for longer than I would like to admit, I finally ended up yanking the assembly (Microsoft.VisualStudio.TextManager.Interop.8.0.dll) out of my GAC so that I could reference it explicitly in my solution.

Now that I have access to the interface, I just need to figure out how to get an instance of it.

IVsExpansionManager

Ah HA! That MUST somehow provide me with a mechanism for obtaining an instance of IVsExpansionClient, right? Well, not exactly. At least not in a way that I can see. I have stitched together the following code:

IVsExpansionManager expansionManager = null;
IVsTextManager2 textManager = (IVsTextManager2)Package.GetGlobalService(typeof(SVsTextManager));
int manager = textManager.GetExpansionManager(out expansionManager);

Which gives me a IVsExpansionManager COM object, but that is about as far as I can get.

I have taken notice of another potential provider:

IVsExpansionEvents

I thought perhaps like solution events, document events, window events or text events, I might be able to invoke DTE to hook these events, but they appear to be absent.

There are methods that accept IVsExpansionClient as a parameter such as:

IVsExpansion.InsertNamedExpansion

So there simply must be a way to fetch an instance of this object, right? I suppose it's possible to create my own class that implements the IVsExpansionClient interface, but I wouldn't know where to begin with implementing the interface members, and I still wouldn't know how to instantiate it in a meaningful way within my package.

I am grateful to anyone who can point me in a different direction, or provide a working sample that I can adapt for my needs. Thanks for taking the time to read through this, I appreciate your time.


Viewing all articles
Browse latest Browse all 4410

Trending Articles