Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagnostics using source generator #975

Merged
merged 11 commits into from
Feb 26, 2024

Conversation

erri120
Copy link
Member

@erri120 erri120 commented Feb 21, 2024

Diagnostics can now be created using a template builder:

    [DiagnosticTemplate]
    private static readonly IDiagnosticTemplate Diagnostic1Template = DiagnosticTemplateBuilder
        .Start()
        .WithId(new DiagnosticId(source: "Example", number: 1))
        .WithSeverity(DiagnosticSeverity.Warning)
        .WithMessage("Mod '{ModA}' conflicts with '{ModB}'!", messageBuilder => messageBuilder
            .AddDataReference<ModReference>("ModA")
            .AddDataReference<ModReference>("ModB")
        )
        .Finish();

This will generate the following method and struct:

	internal static global::NexusMods.Abstractions.Diagnostics.Diagnostic<Diagnostic1MessageData> CreateDiagnostic1(global::NexusMods.Abstractions.Diagnostics.References.ModReference ModA, global::NexusMods.Abstractions.Diagnostics.References.ModReference ModB)
	{
		var messageData = new Diagnostic1MessageData(ModA, ModB);

		return new global::NexusMods.Abstractions.Diagnostics.Diagnostic<Diagnostic1MessageData>
		{
			Id = new global::NexusMods.Abstractions.Diagnostics.DiagnosticId(source: "Example",number: 1),
			Severity = global::NexusMods.Abstractions.Diagnostics.DiagnosticSeverity.Warning,
			Message = global::NexusMods.Abstractions.Diagnostics.DiagnosticMessage.From("Mod '{ModA}' conflicts with '{ModB}'!"),
			MessageData = messageData,
			DataReferences = new global::System.Collections.Generic.Dictionary<global::NexusMods.Abstractions.Diagnostics.References.DataReferenceDescription, global::NexusMods.Abstractions.Diagnostics.References.IDataReference>
			{
				{ global::NexusMods.Abstractions.Diagnostics.References.DataReferenceDescription.From("ModA"), messageData.ModA },
				{ global::NexusMods.Abstractions.Diagnostics.References.DataReferenceDescription.From("ModB"), messageData.ModB },
			},
		};
	}

	internal readonly struct Diagnostic1MessageData
	{
		public readonly global::NexusMods.Abstractions.Diagnostics.References.ModReference ModA;
		public readonly global::NexusMods.Abstractions.Diagnostics.References.ModReference ModB;

		public Diagnostic1MessageData(global::NexusMods.Abstractions.Diagnostics.References.ModReference ModA, global::NexusMods.Abstractions.Diagnostics.References.ModReference ModB)
		{
			this.ModA = ModA;
			this.ModB = ModB;
		}

	}

This generator isn't complete yet, and this PR is only to get started with some basic source generation. I'm going to create an epic to go over some future features of our diagnostic system.

@erri120 erri120 requested a review from a team February 21, 2024 09:47
@erri120 erri120 self-assigned this Feb 21, 2024
@erri120 erri120 mentioned this pull request Feb 21, 2024
@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2024

Codecov Report

Attention: 273 lines in your changes are missing coverage. Please review.

Comparison is base (596d997) 58.18% compared to head (37b588c) 57.93%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #975      +/-   ##
==========================================
- Coverage   58.18%   57.93%   -0.25%     
==========================================
  Files         637      644       +7     
  Lines       20564    21058     +494     
  Branches     1572     1642      +70     
==========================================
+ Hits        11966    12201     +235     
- Misses       8240     8467     +227     
- Partials      358      390      +32     
Flag Coverage Δ
Linux 57.26% <50.18%> (-0.15%) ⬇️
Windows 57.18% <50.18%> (-0.20%) ⬇️
clean_environment_tests 57.91% <50.18%> (-0.25%) ⬇️
macOS 56.63% <50.18%> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...NexusMods.Abstractions.FileExtractor/Signatures.cs 100.00% <100.00%> (ø)
...s/NexusMods.Games.BethesdaGameStudios/Constants.cs 100.00% <100.00%> (ø)
...sMods.Games.BethesdaGameStudios/PluginOrderFile.cs 66.66% <100.00%> (ø)
...udios/SkyrimSpecialEdition/SkyrimSpecialEdition.cs 69.23% <100.00%> (ø)
...ountAndBlade2Bannerlord/Emitters/BuiltInEmitter.cs 57.14% <100.00%> (ø)
...Games/NexusMods.Games.StardewValley/Diagnostics.cs 100.00% <100.00%> (ø)
...nerators.Diagnostics/CustomSymbolDisplayFormats.cs 100.00% <100.00%> (ø)
src/NexusMods.App.UI/Initializers.cs 60.00% <100.00%> (-4.71%) ⬇️
src/NexusMods.App.UI/ReactiveUIExtensions.cs 86.27% <ø> (ø)
....StandardGameLocators.TestHelpers/ListFilesTool.cs 100.00% <100.00%> (ø)
... and 14 more

... and 4 files with indirect coverage changes

Copy link
Contributor

@Al12rs Al12rs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be merged for now with the Caveat of the things we discussed in call before.

Mainly allowing the definition of custom link handlers rather than just having a limited set of operations to do.

@Al12rs Al12rs merged commit 1b2881d into Nexus-Mods:main Feb 26, 2024
7 checks passed
@erri120 erri120 deleted the feat/better-diagnostics branch February 26, 2024 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants