Repository: dotnet/roslyn
File: src/Workspaces/CoreTest/Editing/SyntaxEditorTests.cs (C#)

Code before:

        var editor = GetEditor(cu);
        var methodX = editor.Generator.GetMembers(cls)[0];

        var syntaxGenerator = editor.Generator;
        var args = new[] { syntaxGenerator.AttributeArgument(syntaxGenerator.MemberAccessExpression(syntaxGenerator.DottedName("Sample"), "Attribute")) };
        var attribute = syntaxGenerator.Attribute("Example", args);
        editor.AddReturnAttribute(methodX, attribute);
        var newRoot = editor.GetChangedRoot();

        VerifySyntax<CompilationUnitSyntax>(
            newRoot, """
using System;
using System.CodeAnalysis;

public class C
{
    [return: Example(Sample.Attribute)]
    Type Main(Type t)
    {
    }
}
""");
    }

    [Fact]
    public void TestInsertDelegateIntoInterface()
    {
        var code = """
            public interface ITest
            {
                void Method();
            }
            """;

        var cu = SyntaxFactory.ParseCompilationUnit(code);
        var interfaceDecl = (InterfaceDeclarationSyntax)cu.Members[0];

        var editor = GetEditor(cu);

        // Create a delegate declaration
        var delegateDecl = SyntaxFactory.DelegateDeclaration(
            SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)),
            SyntaxFactory.Identifier("MyDelegate"))
            .WithParameterList(SyntaxFactory.ParameterList());

        editor.InsertMembers(interfaceDecl, 0, new[] { delegateDecl });
        var newRoot = editor.GetChangedRoot();

        VerifySyntax<CompilationUnitSyntax>(
            newRoot,

Review comment (suggestion):
@copilot add the appropriate WorkItem attribute here.  Also add to the copilot instructions file in this repo that added tests should strive to have this attribute when PRs are opened by copilot to fix issues.  

Code after:
        var cls = cu.Members[0];

        var editor = GetEditor(cu);
        var methodX = editor.Generator.GetMembers(cls)[0];

        var syntaxGenerator = editor.Generator;
        var args = new[] { syntaxGenerator.AttributeArgument(syntaxGenerator.MemberAccessExpression(syntaxGenerator.DottedName("Sample"), "Attribute")) };
        var attribute = syntaxGenerator.Attribute("Example", args);
        editor.AddReturnAttribute(methodX, attribute);
        var newRoot = editor.GetChangedRoot();

        VerifySyntax<CompilationUnitSyntax>(
            newRoot, """
using System;
using System.CodeAnalysis;

public class C
{
    [return: Example(Sample.Attribute)]
    Type Main(Type t)
    {
    }
}
""");
    }

    [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/78860")]
    public void TestInsertDelegateIntoInterface()
    {
        var code = """
            public interface ITest
            {
                void Method();
            }
            """;

        var cu = SyntaxFactory.ParseCompilationUnit(code);
        var interfaceDecl = (InterfaceDeclarationSyntax)cu.Members[0];

        var editor = GetEditor(cu);

        // Create a delegate declaration
        var delegateDecl = SyntaxFactory.DelegateDeclaration(
            SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)),
            SyntaxFactory.Identifier("MyDelegate"))
            .WithParameterList(SyntaxFactory.ParameterList());

        editor.InsertMembers(interfaceDecl, 0, new[] { delegateDecl });
        var newRoot = editor.GetChangedRoot();

        VerifySyntax<CompilationUnitSyntax>(