Skip to content

Commit bc0db32

Browse files
authored
Fix for Generation fails with partial classes (#26)
* Fix for #24 Change from class analyser to method analyser * Update code issues
1 parent 6d61331 commit bc0db32

File tree

9 files changed

+241
-303
lines changed

9 files changed

+241
-303
lines changed

src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ public TestViewModel()
104104
[property: Test(AParameter = "Test Input")]
105105
private void Test1() => Console.Out.WriteLine("Test1");
106106

107-
/// <summary>
108-
/// Test2s this instance.
109-
/// </summary>
110-
/// <returns>Rectangle.</returns>
111-
[ReactiveCommand]
112-
private Point Test2() => default;
113-
114107
/// <summary>
115108
/// Test3s the asynchronous.
116109
/// </summary>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using ReactiveUI.SourceGenerators;
7+
8+
namespace SGReactiveUI.SourceGenerators.Test
9+
{
10+
/// <summary>
11+
/// TestViewModel.
12+
/// </summary>
13+
/// <seealso cref="ReactiveUI.ReactiveObject" />
14+
public partial class TestViewModel
15+
{
16+
/// <summary>
17+
/// Test2s this instance.
18+
/// </summary>
19+
/// <returns>Rectangle.</returns>
20+
[ReactiveCommand]
21+
private Point Test2() => default;
22+
}
23+
}

src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldAnalyzer.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ public class PropertyToReactiveFieldAnalyzer : DiagnosticAnalyzer
3434
/// <param name="context">The context.</param>
3535
public override void Initialize(AnalysisContext context)
3636
{
37-
context?.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
38-
context?.EnableConcurrentExecution();
39-
context?.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.PropertyDeclaration);
37+
if (context == null)
38+
{
39+
return;
40+
}
41+
42+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
43+
context.EnableConcurrentExecution();
44+
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.PropertyDeclaration);
4045
}
4146

4247
private void AnalyzeNode(SyntaxNodeAnalysisContext context)

src/ReactiveUI.SourceGenerators/CodeAnalyzers/PropertyToReactiveFieldCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
7777

7878
// Apply the code fix
7979
context.RegisterCodeFix(
80-
CodeAction.Create("Convert to Reactive field", c => Task.FromResult(context.Document.WithSyntaxRoot(newRoot!))),
80+
CodeAction.Create("Convert to Reactive field", c => Task.FromResult(context.Document.WithSyntaxRoot(newRoot!)), "Convert to Reactive field"),
8181
diagnostic);
8282
}
8383
}

src/ReactiveUI.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ internal static class DiagnosticDescriptors
258258
public static readonly DiagnosticDescriptor PropertyToReactiveFieldRule = new(
259259
id: "RXUISG0016",
260260
title: "Property To Reactive Field, change to [Reactive] private type _fieldName;",
261-
messageFormat: "Replace the property {0} with a INPC Reactive Property for ReactiveUI",
261+
messageFormat: "Replace the property with a INPC Reactive Property for ReactiveUI",
262262
category: typeof(PropertyToReactiveFieldCodeFixProvider).FullName,
263263
defaultSeverity: DiagnosticSeverity.Info,
264264
isEnabledByDefault: true,

src/ReactiveUI.SourceGenerators/ReactiveCommand/Models/CommandExtensionInfo.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
1-
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
1+
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
22
// Licensed to the .NET Foundation under one or more agreements.
33
// The .NET Foundation licenses this file to you under the MIT license.
44
// See the LICENSE file in the project root for full license information.
55

6-
using Microsoft.CodeAnalysis.CSharp.Syntax;
6+
using Microsoft.CodeAnalysis;
77
using ReactiveUI.SourceGenerators.Helpers;
8+
using ReactiveUI.SourceGenerators.Models;
89

910
namespace ReactiveUI.SourceGenerators.Input.Models;
1011

11-
/// <summary>
12-
/// A model with gathered info on a given command method.
13-
/// </summary>
14-
internal sealed record CommandInfo(
15-
string ClassNamespace,
16-
string ClassName,
17-
ClassDeclarationSyntax DeclarationSyntax,
18-
EquatableArray<CommandExtensionInfo> CommandExtensionInfos);
12+
internal record CommandInfo(
13+
string MethodName,
14+
ITypeSymbol MethodReturnType,
15+
ITypeSymbol? ArgumentType,
16+
bool IsTask,
17+
bool IsReturnTypeVoid,
18+
bool IsObservable,
19+
string? CanExecuteObservableName,
20+
CanExecuteTypeInfo? CanExecuteTypeInfo,
21+
EquatableArray<AttributeInfo> ForwardedPropertyAttributes)
22+
{
23+
private const string UnitTypeName = "global::System.Reactive.Unit";
24+
25+
public string GetOutputTypeText() => IsReturnTypeVoid
26+
? UnitTypeName
27+
: MethodReturnType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
28+
29+
public string GetInputTypeText() => ArgumentType == null
30+
? UnitTypeName
31+
: ArgumentType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
32+
}

0 commit comments

Comments
 (0)