Skip to content

When we're removing the last project, fire SolutionRemoved#62257

Merged
jasonmalinowski merged 2 commits intodotnet:mainfrom
jasonmalinowski:fire-solutionremoved
Jul 12, 2022
Merged

When we're removing the last project, fire SolutionRemoved#62257
jasonmalinowski merged 2 commits intodotnet:mainfrom
jasonmalinowski:fire-solutionremoved

Conversation

@jasonmalinowski
Copy link
Copy Markdown
Member

@jasonmalinowski jasonmalinowski commented Jun 29, 2022

We have a fair bit of code that assumed it could look for a WorkspaceChangeKind of SolutionRemoved or SolutionCleared to indicate when we've closed the solution and can drop caches and such. Except we never actually fired anything like that. This fires SolutionRemoved on the removal of the last project.

We had a test that asserted that the solution persistence service would continue to return the solution path even once the solution was closed; this fixes that test to assert that it's no longer available.

@jasonmalinowski jasonmalinowski requested a review from ryzngard June 29, 2022 22:40
@jasonmalinowski jasonmalinowski requested a review from a team as a code owner June 29, 2022 22:40
@jasonmalinowski jasonmalinowski self-assigned this Jun 29, 2022
@ghost ghost added the Area-IDE label Jun 29, 2022
ryzngard
ryzngard previously approved these changes Jun 29, 2022
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

We have a fair bit of code that assumed it could look for a WorkspaceChangeKind of SolutionRemoved to indicate when we've closed the solution and can drop caches and such. Except we never actually fired anything like that

So were none of these drop-caches working?

@jasonmalinowski
Copy link
Copy Markdown
Member Author

@CyrusNajmabadi I didn't dig carefully, but probably not? Some code might have re-cleared though if a new solution was loaded.


// If this is our last project, remove the entire solution so components that expect to see a
// SolutionRemoved actually get it
if (w.CurrentSolution.ProjectIds.Count == 1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not exactly sure how this works. is this because .CurrentSolution is not updated yet, despite teh call to _workspace.RemoveProjectFromTrackingMaps_NoLock(Id); above?

can we check this info immediately prior to doing any mutation to make things clearer? or at least doc why this is safe?

}
}

base.OnProjectRemoved(projectId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're not calling this here anymore, where is it calleD? i think i missed it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Called here now: https://github.com/dotnet/roslyn/pull/62257/files/bc2c117a9e2879ca5c696298e8e829d59433a3c7#diff-ed848e0f1ffd29eb5f329de7a11007a2801075fa3173f8b25dc30ad342903606R1244

Which I think answers your other question too. Before we just called the overridden method, which did some cleanup and then deferred to the base. Now we call the cleanup, but let the caller call the appropriate On* method.

davidwengier
davidwengier previously approved these changes Jun 30, 2022
@dotnet dotnet deleted a comment from azure-pipelines bot Jul 7, 2022
@jasonmalinowski jasonmalinowski dismissed stale reviews from davidwengier and ryzngard July 8, 2022 04:28

Subtle bug was found that makes the change much ickier.

@jasonmalinowski jasonmalinowski marked this pull request as draft July 8, 2022 04:28
@jasonmalinowski jasonmalinowski changed the title When we're removing the last project, fire SolutionRemoved When we're removing the last project, fire SolutionCleared Jul 8, 2022
@jasonmalinowski
Copy link
Copy Markdown
Member Author

@CyrusNajmabadi @ryzngard @davidwengier I've had to make some tweaks to this PR after discovering some subtle behaviors; this needs a rereview and you should just review from scratch.

Copy link
Copy Markdown
Contributor

@ryzngard ryzngard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as far as I can tell...

@jasonmalinowski
Copy link
Copy Markdown
Member Author

Chatting further with @CyrusNajmabadi we figure this test is actually no longer accurate:

[IdeFact]
public async Task VerifyWorkingFolder()
{
await SetUpEditorAsync(@"class EmptyContent {$$}", HangMitigatingCancellationToken);
var visualStudioWorkspace = await TestServices.Shell.GetComponentModelServiceAsync<VisualStudioWorkspace>(HangMitigatingCancellationToken);
var persistentStorageConfiguration = visualStudioWorkspace.Services.GetRequiredService<IPersistentStorageConfiguration>();
// verify working folder has set
Assert.NotNull(persistentStorageConfiguration.TryGetStorageLocation(SolutionKey.ToSolutionKey(visualStudioWorkspace.CurrentSolution)));
await TestServices.SolutionExplorer.CloseSolutionAsync(HangMitigatingCancellationToken);
// because the solution cache directory is stored in the user temp folder,
// closing the solution has no effect on what is returned.
Assert.NotNull(persistentStorageConfiguration.TryGetStorageLocation(SolutionKey.ToSolutionKey(visualStudioWorkspace.CurrentSolution)));
}

And instead we should be indeed asserting the working folder is null once the solution is closed. I'm go to update this PR which means we'll be moving back to SolutionRemoved as the event that's fired. 😄

Not sure why this would be "DocumentRemoved", so updated here.
@jasonmalinowski jasonmalinowski changed the title When we're removing the last project, fire SolutionCleared When we're removing the last project, fire SolutionRemoved Jul 11, 2022
We have a fair bit of code that assumed it could look for a
WorkspaceChangeKind of SolutionRemoved or SolutionCleared to indicate
when we've closed the solution and can drop caches and such. Except we
never actually fired anything like that. This fires SolutionRemoved on
the removal of the last project.

We had a test that asserted that the solution persistence service would
continue to return the solution path even once the solution was closed;
this fixes that test to assert that it's no longer available.
@jasonmalinowski
Copy link
Copy Markdown
Member Author

@CyrusNajmabadi Updated the new behavior per our conversation on Friday; @ryzngard if you want to re-review, now might be a good time. 😄

@ryzngard
Copy link
Copy Markdown
Contributor

@jasonmalinowski is there an easy way to know what changed? The commits don't seem terribly helpful.

@jasonmalinowski
Copy link
Copy Markdown
Member Author

@ryzngard: ah, I force pushed to abandon the old approach, which I should not have done. (Or at least, I should have squashed only later.) Here's the diff in any case: https://github.com/dotnet/roslyn/compare/4b3db498d52d1a09ba26555d9570b6db054a97a4..4af81555ff176a0b096b019b11516fd19865a9af

@ryzngard
Copy link
Copy Markdown
Contributor

@ryzngard: ah, I force pushed to abandon the old approach, which I should not have done. (Or at least, I should have squashed only later.) Here's the diff in any case: 4b3db498d52d1a09ba26555d9570b6db054a97a4..4af81555ff176a0b096b019b11516fd19865a9af (compare)

ah gotcha. Yes, changes look good to me. Thanks for the diff link

@jasonmalinowski jasonmalinowski marked this pull request as ready for review July 12, 2022 02:20
@jasonmalinowski jasonmalinowski merged commit 0274d02 into dotnet:main Jul 12, 2022
@jasonmalinowski jasonmalinowski deleted the fire-solutionremoved branch July 12, 2022 18:12
@ghost ghost added this to the Next milestone Jul 12, 2022
@allisonchou allisonchou modified the milestones: Next, 17.4 P1 Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants