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

Take MetadataAsSource out of Roslyn package startup path #73360

Merged
merged 7 commits into from
May 7, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 7, 2024 06:12
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 7, 2024
@CyrusNajmabadi CyrusNajmabadi requested a review from ToddGrun May 7, 2024 06:12
@@ -28,8 +28,6 @@ internal interface IMetadataAsSourceFileService

bool TryRemoveDocumentFromWorkspace(string filePath);

void CleanupGeneratedFiles();
Copy link
Member Author

Choose a reason for hiding this comment

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

made private, and not part of the interface.


if (deletedEverything)
{
Directory.Delete(_rootTemporaryPath);
Copy link
Member Author

Choose a reason for hiding this comment

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

no need to delete the topmost directory. It's fine for there to be one top level temp folder we create once and which sticks around across sessions (note: we delete the contents within). This just keeps thigns simpler.


public int OnAfterCloseSolution(object pUnkReserved)
{
_metadataAsSourceFileService.CleanupGeneratedFiles();
Copy link
Member Author

Choose a reason for hiding this comment

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

this existed to hear about solution close, so we could clean things up. but we can already just clean things up when we startup anyways.

return _rootTemporaryPathWithGuid;
var guidString = Guid.NewGuid().ToString("N");
_rootTemporaryPathWithGuid = Path.Combine(_rootTemporaryPath, guidString);
_mutex = new Mutex(initiallyOwned: true, name: CreateMutexName(guidString));
}
Copy link
Member Author

Choose a reason for hiding this comment

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

can initialize all these values when teh type is created.


// We're being initialized the first time. Use this time to clean up any stale metadata-as-source files
// from previous VS sessions.
CleanupGeneratedFiles(_rootTemporaryPath);
Copy link
Member Author

Choose a reason for hiding this comment

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

the logic here inverts, becoming much simpler. Instead of trying to hook up to shutdown logic to try to clean things at that point, we simply cleanup stale data when we create our first MAS file.

// Release our mutex to indicate we're no longer using our directory and reset state
if (_mutex != null)
{
_mutex.Dispose();
Copy link
Member Author

Choose a reason for hiding this comment

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

no need to dispose our own mutex. when VS shuts down that will automatically happen.

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge May 7, 2024 07:42
@CyrusNajmabadi CyrusNajmabadi merged commit 31bb53c into dotnet:main May 7, 2024
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 7, 2024
@CyrusNajmabadi CyrusNajmabadi deleted the masShutdown branch May 8, 2024 00:12
@CyrusNajmabadi
Copy link
Member Author

@jasonmalinowski For review when you get back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants