Search code examples
c#visual-studiolanguageservice

How do you use a projection buffer to support embedded languages in the Visual Studio editor


At the end of the first paragraph in this link it states:

The Visual Studio text outlining feature is implemented by using a projection buffer to hide the collapsed text, and the Visual Studio editor for ASP.NET pages uses projection to support embedded languages such as Visual Basic and C#.

I have searched and searched but have not found any examples or documentation at all to accomplish this, does anyone have any idea how this is done? I have gotten classification working and created a projection buffer of the spans I want to be classified as C# code. I set the buffers context type as "CSharp" but the spans never get classified. I have also tried to base my content type from "projection" but that does now work either.


Solution

  • A working example can be found here but as per the warning comments it is not a simple task.

    // Abandon all hope ye who enters here.
    // https://twitter.com/Schabse/status/393092191356076032
    // https://twitter.com/jasonmalinowski/status/393094145398407168
    
    // Based on decompiled code from Microsoft.VisualStudio.Html.ContainedLanguage.Server
    // Thanks to Jason Malinowski for helping me navigate this mess.
    // All of this can go away when the Roslyn editor ships.