Skip to content

[Bug]: <inheritdoc/> is not respected by IntelliSense due to attribute order in generated properties. #260

@SiriusED

Description

@SiriusED

Describe the bug 🐞

The ReactiveUI.SourceGenerators currently emits generated [Reactive] properties like this:

[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ReactiveGenerator", "2.2.0.0")]

/// <inheritdoc cref="_someField"/>
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public bool? SomeProperty { get => _someField; set => this.RaiseAndSetIfChanged(ref _someField, value); }

However, Visual Studio's IntelliSense does not show documentation in this case. The issue is caused by the placement of the /// <inheritdoc/> comment after an attribute, which breaks XML documentation binding.

Step to reproduce

  1. Create new C# class.
public partial class ReactiveViewModelTest : ReactiveObject
{
	/// <summary>
	/// This doc should be visible on the SomeProperty's tooltip.
	/// </summary>
	[Reactive] private bool? _someProperty;
	
	private void TestMethod()
	{
		// Hover mouse cursor on the generated `SomeProperty`
		// in the Visual Studio's text editor.
		var generated = SomeProperty;
	}
}
  1. Build the project
  2. Hover mouse cursor on the generated SomeProperty.
  3. Expected to see

Step to reproduce (VS behavior only)

  1. Create new C# file.
  2. Add this test class into:
public partial class TestClass
{
	/// <summary>This is the WorkingProperty's doc.</summary>
	public int WorkingProperty { get; set; }
}

public partial class TestClass
{
	[System.CodeDom.Compiler.GeneratedCode("TestGen", "1.0.0.0")]
	/// <inheritdoc cref="WorkingProperty"/>
	[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
	public int BrokenProperty { get; set; }
}
  1. Hover a mouse on the BrokenProperty -> and you will not be able to see the doc in the VS tooltip window.
  2. Then move /// <inheritdoc cref="WorkingProperty"/> one line above to put it before all the generator attributes like this:
	/// <inheritdoc cref="WorkingProperty"/>
	[System.CodeDom.Compiler.GeneratedCode("TestGen", "1.0.0.0")]
	[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
	public int BrokenProperty { get; set; }
  1. Hover a mouse on the BrokenProperty again -> and now you can see the summary doc just like you expected.

I guess the reason is: C# only binds XML comments to the next member if the comment comes before all attributes.

Reproduction repository

No response

Expected behavior

/// <inheritdoc cref="_someField"/>
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ReactiveGenerator", "2.2.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public bool? SomeProperty { get => _someField; set => this.RaiseAndSetIfChanged(ref _someField, value); }

Screenshots 🖼️

No response

IDE

Visual Studio 2022

Operating system

Microsoft Windows 10

Version

Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.14.5

Device

PC

ReactiveUI Version

ReactiveUI 20.3.1, ReactiveUI.SourceGenerators 2.2.4

Additional information ℹ️

Suggested fix
Change the code generation order to ensure that /// <inheritdoc/> (or /// <summary>) appears above all attributes on the generated property. This small change will ensure IntelliSense works as expected.

Thanks for maintaining this great project!

P.S. I also checked the CommunityToolkit.Mvvm code generator. It does like I said, puts /// <inheritdoc/> before all attributes in the generated file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions