How to create an editor with a projection buffer? RRS feed

  • Question

  • I'd like to create an editor to a custom view engine, which hosts C# code around some barriers (let's say <source></source>). In VS2008 this was done by the TextBufferCoordinator, secondary buffers and contained languages. First I tried to convert the project to VS2010 without luck, so I went to see the new Editor APIs. It seems one has to create a IProjectionBuffer, and use spans to link between the codes. But how can you tell the editor to use a ProjectionBuffer? What is the easiest way to convert code that was written using the old ContainedLanguages based API to the new Projection based Editor API?
    Monday, May 3, 2010 3:11 AM

All replies

  • Hello,

    Have you read this ?


    Chris Granger has replied that easiest thing to use IProjectionBuffer would be to use an IntraText adornment tagger to replace the text with a WPF element.

    And the Plateform team will release a sample, so please wait.



    Wednesday, May 5, 2010 3:51 AM
  • This is not a solution. So when example of using the projection text buffer will be available exactly?

    I suppose that will be best way to create editors for language-mixins (like ASP.NET Web Pages = HTML+C#/VB).

    Monday, May 10, 2010 1:31 PM
  • Even a few hints of how to get started with projection buffers would be useful. The doco at http://msdn.microsoft.com/en-us/library/dd885240.aspx#projection (Inside the Editor) is pretty vague.

    We don't need a complete example, just a few snippets and pointers. 

    Friday, May 14, 2010 4:51 AM
  • Any updates on this? I can't find a projection buffer sample anywhere.
    Friday, April 20, 2012 5:39 PM
  • (I'm interested too ...)
    Tuesday, February 26, 2013 6:07 PM
  • I'd also love a ProjectionBuffer sample or maybe an open source project I could learn off of?
    Friday, October 25, 2013 4:14 AM
  • Alright so I'm not sure if anyone will see this, but I figured I'd post a sample since a few people have asked.

    First off, you need an instance of IProjectionBufferFactoryService. You can either import this with MEF or use something along the lines of: 

    var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));
    var _ProjectionBufferFactory = componentModel.GetService<IProjectionBufferFactoryService>();

    Next you have to create a SnapshotSpan from an ITextSnapShot which can be found on something like an IVsTextBuffer or IVsTextView.

    SnapshotSpan subsetSnapshot = new SnapshotSpan(textViewHost.TextView.TextSnapshot, start, length);

    Finally, you can create an ElisionBuffer (or ProjectionBuffer similarily) using the ProjectionBufferFactoryService.

    var elisBuffer = _ProjectionBufferFactory.CreateElisionBuffer(null, NormalizedSnapshotSpanCollection(subsetSnapshot), ElisionBufferOptions.None);

    Hopefully this at least gives someone a starting point as they try to work out projection buffers. I've still struggled to get all the language services working within my projection buffer, but it's a start.

    Thursday, May 15, 2014 10:30 AM
  • I've also opened a uservoice issue officially requesting this sample here: 


    Please vote for it, it does not even require registration.

    Tuesday, June 17, 2014 7:03 PM