Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct change detection when projects not supporting EnC are added/removed #71586

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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