Skip to content
Open
Show file tree
Hide file tree
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 @@ -204,7 +204,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)

using StringWriter source = new();
source.WriteLine("// <auto-generated />");
source.WriteLine("#pragma warning disable CS0612, CS0618, CS0649"); // Suppress warnings about [Obsolete] and "lack of assignment" in generated code.
source.WriteLine("#pragma warning disable CS0612, CS0618, CS0649, CS1591"); // Suppress warnings about [Obsolete], "lack of assignment", and missing XML documentation in generated code.

// If the user has specified 'ManagedObjectWrapper', it means that the COM interface will never be used to marshal a native
// object as an RCW (eg. the IDIC vtable will also not be generated, nor any additional supporting code). To reduce binary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.Interop.UnitTests;
using Xunit;
using VerifyComInterfaceGenerator = Microsoft.Interop.UnitTests.Verifiers.CSharpSourceGeneratorVerifier<Microsoft.Interop.ComInterfaceGenerator>;
Expand Down Expand Up @@ -369,5 +373,80 @@ public async Task ValidateComInterfaceSnippets(string id, string source)

await VerifyComInterfaceGenerator.VerifySourceGeneratorAsync(source);
}

[Fact]
public async Task DocumentedComInterfaceDoesNotProduceCS1591Warnings()
{
string source = """
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

namespace Test
{
/// <summary>
/// This is my interface.
/// </summary>
[GeneratedComInterface, Guid("27dd3a3d-4c16-485a-a123-7cd8f39c6ef2")]
public partial interface IMyInterface
{
/// <summary>
/// This does something.
/// </summary>
void DoSomething();
}

/// <summary>
/// This is my other interface.
/// </summary>
[GeneratedComInterface, Guid("1b681178-368a-4d13-8893-66b4673d2ff9")]
public partial interface MyOtherInterface : IMyInterface
{
/// <summary>
/// This does something else.
/// </summary>
void DoSomethingElse();
}
}
""";

var test = new VerifyCompilationTest<Microsoft.Interop.ComInterfaceGenerator>(false)
{
TestCode = source,
TestBehaviors = TestBehaviors.SkipGeneratedSourcesCheck | TestBehaviors.SkipGeneratedCodeCheck,
CompilationVerifier = compilation =>
{
// Verify that no CS1591 warnings are produced in the generated code
var diagnostics = compilation.GetDiagnostics();
var cs1591Diagnostics = diagnostics.Where(d => d.Id == "CS1591").ToList();

Assert.Empty(cs1591Diagnostics);
}
};

// Enable XML documentation warnings to ensure CS1591 would be raised if not suppressed
test.SolutionTransforms.Add((solution, projectId) =>
{
var project = solution.GetProject(projectId);
if (project is null) return solution;

// Set parse options to enable documentation mode which is required for CS1591 validation
var parseOptions = (CSharpParseOptions?)project.ParseOptions;
if (parseOptions is not null)
{
parseOptions = parseOptions.WithDocumentationMode(DocumentationMode.Diagnose);
solution = solution.WithProjectParseOptions(projectId, parseOptions);
project = solution.GetProject(projectId)!;
}

var compilationOptions = project.CompilationOptions!
.WithSpecificDiagnosticOptions(new Dictionary<string, ReportDiagnostic>
{
["CS1591"] = ReportDiagnostic.Warn
});
return solution.WithProjectCompilationOptions(projectId, compilationOptions);
});

await test.RunAsync();
}
}
}
Loading