Skip to content

Commit

Permalink
Correct change detection when projects not supporting EnC are added/r…
Browse files Browse the repository at this point in the history
…emoved (#71586)
  • Loading branch information
tmat authored Jan 11, 2024
1 parent dbeefc3 commit 9fc882c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ public async Task SemanticError()
[Fact]
public async Task HasChanges()
{
using var _ = CreateWorkspace(out var solution, out var service);
using var _ = CreateWorkspace(out var solution, out var service, [typeof(NoCompilationLanguageService)]);

var pathA = Path.Combine(TempRoot.Root, "A.cs");
var pathB = Path.Combine(TempRoot.Root, "B.cs");
Expand Down Expand Up @@ -1903,6 +1903,17 @@ public async Task HasChanges()
// remove a project:
Assert.True(await EditSession.HasChangesAsync(solution, solution.RemoveProject(projectD.Id), CancellationToken.None));

// add a project that doesn't support EnC:

oldSolution = solution;
var projectE = solution.AddProject("E", "E", NoCompilationConstants.LanguageName);
solution = projectE.Solution;

Assert.False(await EditSession.HasChangesAsync(oldSolution, solution, CancellationToken.None));

// remove a project that doesn't support EnC:
Assert.False(await EditSession.HasChangesAsync(solution, oldSolution, CancellationToken.None));

EndDebuggingSession(debuggingSession);
}

Expand Down Expand Up @@ -3677,9 +3688,7 @@ public async Task ActiveStatements_SyntaxErrorOrOutOfSyncDocument(bool isOutOfSy
[CombinatorialData]
public async Task ActiveStatements_ForeignDocument(bool withPath, bool designTimeOnly)
{
var composition = FeaturesTestCompositions.Features.AddParts(typeof(NoCompilationLanguageService));

using var _ = CreateWorkspace(out var solution, out var service, new[] { typeof(NoCompilationLanguageService) });
using var _ = CreateWorkspace(out var solution, out var service, [typeof(NoCompilationLanguageService)]);

var project = solution.AddProject("dummy_proj", "dummy_proj", designTimeOnly ? LanguageNames.CSharp : NoCompilationConstants.LanguageName);
var filePath = withPath ? Path.Combine(TempRoot.Root, "test.cs") : null;
Expand Down
28 changes: 21 additions & 7 deletions src/Features/Core/Portable/EditAndContinue/EditSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,22 +290,36 @@ public static async ValueTask<bool> HasChangesAsync(Solution oldSolution, Soluti
return false;
}

if (oldSolution.ProjectIds.Count != newSolution.ProjectIds.Count)
{
return true;
}

foreach (var newProject in newSolution.Projects)
{
if (!newProject.SupportsEditAndContinue())
{
continue;
}

var oldProject = oldSolution.GetProject(newProject.Id);
if (oldProject == null || await HasChangedOrAddedDocumentsAsync(oldProject, newProject, changedOrAddedDocuments: null, cancellationToken).ConfigureAwait(false))
{
// project added or has changes
return true;
}
}

foreach (var oldProject in oldSolution.Projects)
{
if (!oldProject.SupportsEditAndContinue())
{
continue;
}

var newProject = newSolution.GetProject(oldProject.Id);
if (newProject == null)
{
// project removed
return true;
}
}

// The number of projects in both solution is the same and there are no new projects and no changes in existing projects.
// Therefore there are no changes.
return false;
}

Expand Down

0 comments on commit 9fc882c

Please sign in to comment.