Repository: dotnet/roslyn
File: src/Workspaces/Core/Portable/Rename/Renamer.RenameDocumentActionSet.cs (C#)

Code before:
            // before actions were applied.
            if (solution.ContainsDocument(_documentId))
            {
                return solution.GetRequiredDocument(_documentId);
            }

            // There are cases where we expect work to be done between when the ActionSet is first generated
            // and when the solution can be worked on. This work can remove and add documents as part of the rename
            // and thus won't have the same DocumentId. 
            // 
            // 1. Right click solution explorer > rename
            // 2. Call Renamer.RenameDocument to generate dialog for user (near synchronous) 
            // 3. CPS changes file on disk
            // 4. CPS updates project file if necessary
            // 5. In dotnet project system, a new design time build is started
            // 6. Re-evaluates what files need to be passed to Roslyn. Tell Roslyn of file changed. This is a remove then add. (Asynchronous on project-system side)
            // 7. We update the workspace snapshot in the VS Workspace. Synchronous and controlled by project system.
            // 8. RenameDocumentActionSet should be applied to the current Workspace Solution
            // 
            // Since step 6 and 7 remove and add the document, step 8 can't depend on the DocumentId being available and the same document.
            // We are guaranateed that the project is the same and we know what the document name will be. 
            // https://github.com/dotnet/roslyn/issues/43729 tracks designing a more elagent system that can help alleviate
            // this issue. 
            var project = solution.GetRequiredProject(_documentId.ProjectId);
            return project.Documents.FirstOrDefault(d => d.Name == _documentName && d.Folders.SequenceEqual(_documentFolders))
                ?? throw new InvalidOperationException(string.Format(WorkspaceExtensionsResources.The_solution_does_not_contain_the_specified_document, _documentName ?? "Unknown"));
        }
    }
}


Review comment (suggestion):
@copilot should not need the `?? "Unknown"` bit here. 

Code after:
            // before actions were applied.
            if (solution.ContainsDocument(_documentId))
            {
                return solution.GetRequiredDocument(_documentId);
            }

            // There are cases where we expect work to be done between when the ActionSet is first generated
            // and when the solution can be worked on. This work can remove and add documents as part of the rename
            // and thus won't have the same DocumentId. 
            // 
            // 1. Right click solution explorer > rename
            // 2. Call Renamer.RenameDocument to generate dialog for user (near synchronous) 
            // 3. CPS changes file on disk
            // 4. CPS updates project file if necessary
            // 5. In dotnet project system, a new design time build is started
            // 6. Re-evaluates what files need to be passed to Roslyn. Tell Roslyn of file changed. This is a remove then add. (Asynchronous on project-system side)
            // 7. We update the workspace snapshot in the VS Workspace. Synchronous and controlled by project system.
            // 8. RenameDocumentActionSet should be applied to the current Workspace Solution
            // 
            // Since step 6 and 7 remove and add the document, step 8 can't depend on the DocumentId being available and the same document.
            // We are guaranateed that the project is the same and we know what the document name will be. 
            // https://github.com/dotnet/roslyn/issues/43729 tracks designing a more elagent system that can help alleviate
            // this issue. 
            var project = solution.GetRequiredProject(_documentId.ProjectId);
            return project.Documents.FirstOrDefault(d => d.Name == _documentName && d.Folders.SequenceEqual(_documentFolders))
                ?? throw ISolutionExtensions.CreateDocumentNotFoundException(_documentName);
        }
    }
}