I'm building a Visual Studio 2015 custom editor (not a code editor extension, a totally custom WPF control) to edit .cs files. I'm really uncertain of what the right approach is to use the .NET Compilation SDK here.
So far I've tried:
None of what I'm doing now feels clean at all. Is there a more direct way to access compiler APIs for editor's document?
I might be interpreting your question wrong but I'll take a shot. It sounds like you're trying to find the Roslyn document for a given text buffer.
There's actually a whole set of extension methods to make it easier to bridge the gap between Roslyn and Visual Studio objects.
See: Microsoft.CodeAnalysis.Text.Extensions
They're not shipped with the Microsoft.CodeAnalysis
NuGet Package though, you'll have to install them via:
Install-Package Microsoft.CodeAnalysis.EditorFeatures.Text -Version 1.0.0
Given an ITextSnapshot
or ITextBuffer
these methods will allow you to map them back to the original Roslyn Documents (if any exist).
For more info: https://joshvarty.wordpress.com/2015/07/06/lrn-quick-tip-bridging-visual-studio-and-roslyn/