1- using System . Collections . Immutable ;
1+ using System ;
2+ using System . Collections . Immutable ;
3+ using System . IO ;
4+ using System . Linq ;
25using Devlooped . Sponsors ;
6+ using Humanizer ;
37using Microsoft . CodeAnalysis ;
48using Microsoft . CodeAnalysis . Diagnostics ;
59using static Devlooped . Sponsors . SponsorLink ;
610
711namespace Analyzer ;
812
9- [ DiagnosticAnalyzer ( LanguageNames . CSharp ) ]
13+ [ DiagnosticAnalyzer ( LanguageNames . CSharp , LanguageNames . VisualBasic ) ]
1014public class StatusReportingAnalyzer : DiagnosticAnalyzer
1115{
12- public override ImmutableArray < DiagnosticDescriptor > SupportedDiagnostics => ImmutableArray < DiagnosticDescriptor > . Empty ;
16+ public override ImmutableArray < DiagnosticDescriptor > SupportedDiagnostics => ImmutableArray . Create ( new DiagnosticDescriptor (
17+ "SL001" , "Report Sponsoring Status" , "Reports sponsoring status determined by SponsorLink" , "Sponsors" ,
18+ DiagnosticSeverity . Warning , true ) ) ;
1319
1420 public override void Initialize ( AnalysisContext context )
1521 {
1622 context . EnableConcurrentExecution ( ) ;
1723 context . ConfigureGeneratedCodeAnalysis ( GeneratedCodeAnalysisFlags . None ) ;
18-
19- context . RegisterCodeBlockAction ( c =>
24+
25+ context . RegisterCompilationAction ( c =>
2026 {
27+ var installed = c . Options . AdditionalFiles . Where ( x =>
28+ {
29+ var options = c . Options . AnalyzerConfigOptionsProvider . GetOptions ( x ) ;
30+ // In release builds, we'll have a single such item, since we IL-merge the analyzer.
31+ return options . TryGetValue ( "build_metadata.Analyzer.ItemType" , out var itemType ) &&
32+ options . TryGetValue ( "build_metadata.Analyzer.NuGetPackageId" , out var packageId ) &&
33+ itemType == "Analyzer" &&
34+ packageId == "SponsorableLib" ;
35+ } ) . Select ( x => File . GetLastWriteTime ( x . Path ) ) . OrderByDescending ( x => x ) . FirstOrDefault ( ) ;
36+
2137 var status = Diagnostics . GetStatus ( Funding . Product ) ;
22- Tracing . Trace ( $ "Status: { status } ") ;
38+ if ( installed != default )
39+ Tracing . Trace ( $ "Status: { status } , Installed: { ( DateTime . Now - installed ) . Humanize ( ) } ago") ;
40+ else
41+ Tracing . Trace ( $ "Status: { status } , unknown install time") ;
2342 } ) ;
2443 }
2544}
0 commit comments