Skip to content
Merged
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 @@ -124,14 +124,15 @@ public async ValueTask<bool> TryRemoveMiscellaneousDocumentAsync(string document
return await ExecuteUnderGateAsync(async loadedProjects =>
{
// Try to find and remove the document from the miscellaneous workspace only
var miscWorkspace = _workspaceFactory.MiscellaneousFilesWorkspaceProjectFactory.Workspace;
var solution = _workspaceFactory.MiscellaneousFilesWorkspaceProjectFactory.Workspace.CurrentSolution;

var documents = miscWorkspace.CurrentSolution.GetDocumentIdsWithFilePath(documentPath);
if (documents.Any())
// Filter to actual documents, ignoring additional documents like Razor files etc.
var documentIds = solution.GetDocumentIdsWithFilePath(documentPath).WhereAsArray(id => solution.GetDocument(id) is not null);
Copy link
Member

Choose a reason for hiding this comment

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

im not sure this is quite right - razor docs are added as misc, and when we find the real one we need to remove the misc one. this will just cause it to leak.

might need to check below wjat kind of doc, and remove it

Copy link
Member Author

@davidwengier davidwengier Dec 22, 2025

Choose a reason for hiding this comment

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

Definitely not claiming to understand this, but the key change here in my mind is that this method not only doesn't error, but will now return false when it finds a Razor document. That allows the project system to fall back to the previous path and unload the misc project for the Razor file altogether.

It seems to me, from reading the code here, that since the CanonicalMiscFilesProjectLoader only ever adds documents, never additional documents, then it should only ever remove the same. Having said that, I don't know what "canonical" means in this scenario, nor why Razor files are ever seen in anything with "File Based" in the name.

What exactly does it mean to "leak" here?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry - I think you're right - the FBP loader will unload it if it returns false here. I missed that the FBP loader would actually do it if this returned false

if (documentIds.Length > 0)
{
await _workspaceFactory.MiscellaneousFilesWorkspaceProjectFactory.ApplyChangeToWorkspaceAsync(workspace =>
{
foreach (var documentId in documents)
foreach (var documentId in documentIds)
{
workspace.OnDocumentRemoved(documentId);
}
Expand Down
Loading