Skip to content

Commit

Permalink
Fix for Generation fails with partial classes (#26)
Browse files Browse the repository at this point in the history
* Fix for #24

Change from class analyser to method analyser

* Update code issues
  • Loading branch information
ChrisPulman authored Aug 11, 2024
1 parent 6d61331 commit bc0db32
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 303 deletions.
7 changes: 0 additions & 7 deletions src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ public TestViewModel()
[property: Test(AParameter = "Test Input")]
private void Test1() => Console.Out.WriteLine("Test1");

/// <summary>
/// Test2s this instance.
/// </summary>
/// <returns>Rectangle.</returns>
[ReactiveCommand]
private Point Test2() => default;

/// <summary>
/// Test3s the asynchronous.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions src/ReactiveUI.SourceGenerators.Execute/TestViewModel{partTwo}.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI.SourceGenerators;

namespace SGReactiveUI.SourceGenerators.Test
{
/// <summary>
/// TestViewModel.
/// </summary>
/// <seealso cref="ReactiveUI.ReactiveObject" />
public partial class TestViewModel
{
/// <summary>
/// Test2s this instance.
/// </summary>
/// <returns>Rectangle.</returns>
[ReactiveCommand]
private Point Test2() => default;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ public class PropertyToReactiveFieldAnalyzer : DiagnosticAnalyzer
/// <param name="context">The context.</param>
public override void Initialize(AnalysisContext context)
{
context?.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context?.EnableConcurrentExecution();
context?.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.PropertyDeclaration);
if (context == null)
{
return;
}

context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.PropertyDeclaration);
}

private void AnalyzeNode(SyntaxNodeAnalysisContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)

// Apply the code fix
context.RegisterCodeFix(
CodeAction.Create("Convert to Reactive field", c => Task.FromResult(context.Document.WithSyntaxRoot(newRoot!))),
CodeAction.Create("Convert to Reactive field", c => Task.FromResult(context.Document.WithSyntaxRoot(newRoot!)), "Convert to Reactive field"),
diagnostic);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ internal static class DiagnosticDescriptors
public static readonly DiagnosticDescriptor PropertyToReactiveFieldRule = new(
id: "RXUISG0016",
title: "Property To Reactive Field, change to [Reactive] private type _fieldName;",
messageFormat: "Replace the property {0} with a INPC Reactive Property for ReactiveUI",
messageFormat: "Replace the property with a INPC Reactive Property for ReactiveUI",
category: typeof(PropertyToReactiveFieldCodeFixProvider).FullName,
defaultSeverity: DiagnosticSeverity.Info,
isEnabledByDefault: true,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis;
using ReactiveUI.SourceGenerators.Helpers;
using ReactiveUI.SourceGenerators.Models;

namespace ReactiveUI.SourceGenerators.Input.Models;

/// <summary>
/// A model with gathered info on a given command method.
/// </summary>
internal sealed record CommandInfo(
string ClassNamespace,
string ClassName,
ClassDeclarationSyntax DeclarationSyntax,
EquatableArray<CommandExtensionInfo> CommandExtensionInfos);
internal record CommandInfo(
string MethodName,
ITypeSymbol MethodReturnType,
ITypeSymbol? ArgumentType,
bool IsTask,
bool IsReturnTypeVoid,
bool IsObservable,
string? CanExecuteObservableName,
CanExecuteTypeInfo? CanExecuteTypeInfo,
EquatableArray<AttributeInfo> ForwardedPropertyAttributes)
{
private const string UnitTypeName = "global::System.Reactive.Unit";

public string GetOutputTypeText() => IsReturnTypeVoid
? UnitTypeName
: MethodReturnType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);

public string GetInputTypeText() => ArgumentType == null
? UnitTypeName
: ArgumentType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
}
Loading

0 comments on commit bc0db32

Please sign in to comment.