Skip to content

Commit

Permalink
Fix for missing ReactiveUI using statement in generated code (#6)
Browse files Browse the repository at this point in the history
Change test namespace to non ReactiveUI add using
  • Loading branch information
ChrisPulman authored Jul 19, 2024
1 parent d5f8835 commit 30eb677
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ReactiveUI.SourceGenerators.Execute/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using System.Reactive.Linq;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using ReactiveUI;
using ReactiveUI.SourceGenerators;

namespace ReactiveUI.SourceGenerators.Test;
namespace SGReactiveUI.SourceGenerators.Test;

#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable SA1649 // File name should match first type name
Expand Down
12 changes: 11 additions & 1 deletion src/ReactiveUI.SourceGenerators/Reactive/ReactiveGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using ReactiveUI.SourceGenerators.Extensions;
using ReactiveUI.SourceGenerators.Models;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;

namespace ReactiveUI.SourceGenerators;

Expand Down Expand Up @@ -67,7 +69,15 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.ToImmutableArray();

// Insert all members into the same partial type declaration
var compilationUnit = item.Key.GetCompilationUnit(memberDeclarations);
var compilationUnit = item.Key.GetCompilationUnit(memberDeclarations)
.WithLeadingTrivia(TriviaList(
Comment("using ReactiveUI;"),
CarriageReturn,
Comment("// <auto-generated/>"),
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)),
Trivia(NullableDirectiveTrivia(Token(SyntaxKind.EnableKeyword), true)),
CarriageReturn))
.NormalizeWhitespace();
context.AddSource($"{item.Key.FilenameHint}.Properties.g.cs", compilationUnit);
});
}
Expand Down

0 comments on commit 30eb677

Please sign in to comment.