Allow identical DocumentSnapshot sources to trigger output changes.

- Prior to this project changes would trigger re-parses which would then be thrown away because source versions were identical.
- Added test to verify new SetOutput behavior.

aspnet/Razor.VSCode#184
This commit is contained in:
N. Taylor Mullen 2018-10-16 15:31:15 -07:00
parent 71ed050fa4
commit f835291cb6
2 changed files with 28 additions and 1 deletions

View File

@ -106,7 +106,9 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
return;
}
if (_sourceVersion.HasValue && _sourceVersion == SourceVersion.GetNewerVersion(version))
if (_sourceVersion.HasValue &&
_sourceVersion != version &&
_sourceVersion == SourceVersion.GetNewerVersion(version))
{
// Latest document is newer than the provided document.
return;

View File

@ -11,6 +11,31 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
{
public class GeneratedCodeContainerTest
{
[Fact]
public void SetOutput_AcceptsSameVersionedDocuments()
{
// Arrange
var csharpDocument = RazorCSharpDocument.Create("...", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty<RazorDiagnostic>());
var hostProject = new HostProject("C:/project.csproj", RazorConfiguration.Default);
var services = TestWorkspace.Create().Services;
var projectState = ProjectState.Create(services, hostProject);
var project = new DefaultProjectSnapshot(projectState);
var hostDocument = new HostDocument("C:/file.cshtml", "C:/file.cshtml");
var text = SourceText.From("...");
var textAndVersion = TextAndVersion.Create(text, VersionStamp.Default);
var documentState = new DocumentState(services, hostDocument, text, VersionStamp.Default, () => Task.FromResult(textAndVersion));
var document = new DefaultDocumentSnapshot(project, documentState);
var newDocument = new DefaultDocumentSnapshot(project, documentState);
var container = new GeneratedCodeContainer();
container.SetOutput(csharpDocument, document);
// Act
container.SetOutput(csharpDocument, newDocument);
// Assert
Assert.Same(newDocument, container.LatestDocument);
}
[Fact]
public void SetOutput_AcceptsInitialOutput()
{