Consolidate `RazorSourceDocument` and `SourceText`
Currently the compiler produces RazorSourceDocuments which bear a passing resemblance to Roslyn's SourceText class, though with less features around dealing with lines and line spans etc. In order to take advantage of those features, in tooling we often convert that RazorSourceDocument to a SourceText by copying the buffer array, then converting it to a string, then creating a SourceText. All of that is inefficient and a LOH risk, and seems unnecessary.
We should fix this in some way, either:
- Have
RazorSourceDocumentsimply wrap a smarterSourceTextclass, and allow direct access to it for tooling- We can't remove
RazorSourceDocumentbecause its part of the public API - Worth noting that other parts of Razor tooling already use
SourceText, for example theDocumentSnapshotsystem
- We can't remove
- Fill in the gaps between
RazorSourceDocumentandSourceTextand have tooling stop doing the conversion- I prototyped this for
RazorDocumentMappingServiceand its not difficult, but we would miss out on any optimizations Roslyn had made, if we reimplement the API
- I prototyped this for
Thoughts @DustinCampbell @333fred ?
I prefer the first approach, especially since the public API here is something that we will end up breaking at some point.
I'm also in favor of the first approach. I'd rather defer to the existing Roslyn abstraction rather than augmenting the existing API. We can do this internally for tooling.
A 3rd option, one I think I'm most in favor of:
- Delete
RazorSourceDocument, and useSourceTextdirectly.
I'm not sure I love that 3rd option. Having some sort of higher-level document class is valuable for hanging additional data on. SourceText is just meant to represent a text.
Having some sort of higher-level document class is valuable for hanging additional data on. SourceText is just meant to represent a text.
A RazorSourceDocument is only SourceText + FilePath. Locally, I have a change where I've been moving it to exactly that state, but at some point we may want to consolidate RazorSourceDocument and RazorCodeDocument. I'm not sure having a distinction between those is particularly useful :).
Option 1 has been completed.