views:

11

answers:

1

Hiya,

I'm writing an extension for VS2010 that reorders a page of code by rearranging code sections and inserting #regions.

I want to be able to code in a call to the "Edit.CollapseToDefinitions" command after I've completed my text manipulations. I can invoke this command in the Visual Studio model by calling ExecuteCommand on my DTE2 object.

However, if I invoke the command immediately after moving my text around the document VS hasn't had time to update its outlining record. So, I want to be able to hook up to outlining events on the current Text Editor window. Does anyone know how to do this?

A: 

There's no great way to do it. You can listen for outlining region change events on the IOutliningManager (retrieved by [Import]ing an IOutliningManagerService), but there are no guarantees that the first event will be the one in which the language service re-introduces all the outlining regions it can. Most languages do it on the VS idle loop, but still at some delay so that it doesn't interrupt slow typing.

I would try playing around with something like:

  1. Complete your text edits
  2. Call collapse to definitions
  3. Subscribe to IOutliningManager.RegionsChanged
  4. If the next event is raised in, say, the next 5 seconds, call collapse to definitions again.
Noah Richards
Thanks Noah. That sounds pretty messy doesn't it?
Stephen Ellis
It's the downside of the asynchronous model the languages use. I'm hoping to introduce something in future versions of VS that'll let consumers ask for tags (including outlining regions) in such a way that means "and go ahead and block until you're ready".
Noah Richards