roslyn
roslyn copied to clipboard
Remove TextDocumentState.sourceText
First, some background: if we are opening a document, and the document is unchanged from the copy on disk, we try to reuse the version stamp from the disk version to avoid invalidating caches. If the file being opened has already been read, we have a fast path where we quickly compare against the prior text. If it's not read, we would then create a deferred text loader which would read the file on disk and then compare when somebody later asks for the version.
This sourceText argument was to guarantee that if somebody were to synchronously ask for the text (and only the text) of a file that was just opened, and they didn't care about the version, we'd be able to get the text quickly without actually going through the TextLoader.
It's unclear to me what benefit this really brings: if a file has already been read in the background, we'll take the fast path and none of this gets used. If the file hasn't been read previously, we'll be persisting a version that hasn't yet been observed -- but since we hadn't read the file nobody could have that version number to compare to.
This work was originally introduced in https://github.com/dotnet/roslyn/pull/7417, so tagging @CyrusNajmabadi if he can recall if there was something we missed here. I get the sense from the commentary there that we had this optimization (which I suspect predates TypeScript using Roslyn as a base), but then TypeScript was running into an issue and we tried carefully to preserve behavior, but we probably didn't need to?