• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Sholtee / proxygen / 1046

27 Apr 2025 01:21PM UTC coverage: 92.705% (+0.6%) from 92.112%
1046

push

appveyor

Sholtee
Merge branch 'v10-preview1'

4791 of 5168 relevant lines covered (92.71%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.89
/SRC/Private/SourceGenerators/ProxyEmbedderBase.cs
1
/********************************************************************************
2
* ProxyEmbedderBase.cs                                                          *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Collections.Generic;
8
using System.Diagnostics;
9
using System.Linq;
10
using System.Threading;
11

12
using Microsoft.CodeAnalysis;
13
using Microsoft.CodeAnalysis.CSharp;
14
using Microsoft.CodeAnalysis.Diagnostics;
15

16
namespace Solti.Utils.Proxy.Internals
17
{
18
    internal abstract partial class ProxyEmbedderBase
19
    {
20
        protected static SymbolEqualityComparer SymbolEqualityComparer { get; } = SymbolEqualityComparer.Default;
1✔
21

22
        protected static void Execute
23
        (
24
            Compilation cmp,
25
            AnalyzerConfigOptions configOptions,
26
            IReadOnlyCollection<INamedTypeSymbol> aotGenerators,
27
            Action<Diagnostic> reportDiagnostic,
28
            Action<SourceCode> addSource,
29
            CancellationToken cancellation
30
        )
31
        {
1✔
32
            AnalyzerConfig config = new(configOptions);
1✔
33
#if DEBUG
34
            if (config.DebugGenerator && !Debugger.IsAttached)
×
35
                Debugger.Launch();
×
36
#endif
37
            //
38
            // Only C# 9.0+ is supported
39
            //
40

41
            if (cmp is not CSharpCompilation { LanguageVersion: >= LanguageVersion.CSharp9 } compilation)
1✔
42
            {
1✔
43
                reportDiagnostic
1✔
44
                (
1✔
45
                    Diagnostics.PGE00(Location.None)
1✔
46
                );
1✔
47
                return;
1✔
48
            }
49

50
            if (!aotGenerators.Any())
1✔
51
                return;
1✔
52

53
            using LoggerFactory loggerFactory = new(config);
1✔
54

55
            ILogger logger = loggerFactory.CreateLogger($"SourceGenerator-{cmp.AssemblyName}-{Guid.NewGuid():N}");
1✔
56

57
            SyntaxFactoryContext context = new()
1✔
58
            {
1✔
59
                OutputType = OutputType.Unit,
1✔
60
                LanguageVersion = compilation.LanguageVersion,
1✔
61
                AssemblyNameOverride = compilation.Assembly.Name,
1✔
62
                LoggerFactory = loggerFactory
1✔
63
            };
1✔
64

65
            int extensionCount = 0;
1✔
66

67
            foreach (INamedTypeSymbol generator in aotGenerators)
1✔
68
            {
1✔
69
                Location location = generator.Locations[0];  // don't use Single() here
1✔
70

71
                logger.Log(LogLevel.Info, "PREM-200", $"Found generator ({generator.Name}) in location: {location}");
1✔
72

73
                try
74
                {
1✔
75
                    generator.EnsureNotError();
1✔
76

77
                    ProxyUnitSyntaxFactoryBase mainUnit = CreateMainUnit(generator, compilation, context);
1✔
78

79
                    ExtendWith(mainUnit, location);
1✔
80

81
                    extensionCount++;
1✔
82
                }
1✔
83
                catch (InvalidSymbolException)
1✔
84
                {
1✔
85
                    //
86
                    // Jump to the next generator
87
                    //
88

89
                    logger.Log(LogLevel.Info, "PREM-201", $"Invalid generator symbol in location: {location}. Skipping");
1✔
90
                }
1✔
91
                catch (Exception e)
1✔
92
                {
1✔
93
                    ReportError(e, location);
1✔
94
                }
1✔
95
            }
1✔
96

97
            //
98
            // Chunks are applied only if the source has been augmented.
99
            //
100

101
            if (extensionCount > 0)
1✔
102
            {
1✔
103
                try
104
                {
1✔
105
                    foreach (UnitSyntaxFactoryBase chunk in CreateChunks(compilation, context))
1✔
106
                    {
1✔
107
                        logger.Log(LogLevel.Info, "PREM-202", "Applying chunk", new Dictionary<string, object?> { ["Name"] = chunk.ExposedClass });
1✔
108

109
                        ExtendWith(chunk, Location.None);
1✔
110
                    }
1✔
111
                }
1✔
112
                catch (Exception e)
×
113
                {
×
114
                    ReportError(e, Location.None);
×
115
                }
×
116
            }
1✔
117

118
            void ReportError(Exception ex, Location location) => reportDiagnostic
1✔
119
            (
1✔
120
                Diagnostics.PGE01(location, ex.Message)
1✔
121
            );
1✔
122

123
            void ExtendWith(UnitSyntaxFactoryBase syntaxFactory, Location location)
124
            {
1✔
125
                SourceCode source = new
1✔
126
                (
1✔
127
                    $"{syntaxFactory.ExposedClass}.cs",
1✔
128
                    syntaxFactory.ResolveUnit(null!, cancellation)
1✔
129
                );
1✔
130

131
                addSource(source);
1✔
132

133
                reportDiagnostic
1✔
134
                (
1✔
135
                    Diagnostics.PGI00(location, source.Hint)
1✔
136
                );
1✔
137
            }
1✔
138
        }
1✔
139
    }
140
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc