Skip to content

Conversation

@mateoatr
Copy link
Contributor

Share DiagnosticString, DiagnosticId, and DiagnosticCategory between linker and analyzer. DiagnosticString receives a readable diagnostic id (a resource key which maps to exactly one ILXXXX code) and returns its diagnostic message format; this way we might move warnings in the linker side to a simpler logging mechanism: context.Log(DiagnosticId, params string[] args, ...).

The Roslyn Analyzer uses this to get a diagnostic descriptor given a diagnostic id; this saves some diagnostic descriptors handwriting; useful going forward with supporting more diagnostics on the analyzers.

EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\ILLink.Shared\ILLink.Shared.projitems*{92f5e753-2179-46dc-bdce-736858c18dc7}*SharedItemsImports = 13
Copy link
Contributor

Choose a reason for hiding this comment

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

To educate myself whats this code doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code was generated by VS. Couldn't find anything particularly interesting; looks like the first entry (13) is referencing the shared project itself and the bellow ones are the projects that use the shared proj.

Copy link
Contributor

@tlakollo tlakollo left a comment

Choose a reason for hiding this comment

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

Definitely a very clever of solving the diagnostics, thanks Mateo!

Mateo Torres Ruiz added 2 commits July 27, 2021 11:30
Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

Minor comments. LGTM otherwise

{
readonly string _titleFormat;
readonly string _messageFormat;
static readonly ResourceManager _resourceManager = SharedStrings.ResourceManager;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a static field here? It seems like a local variable would suffice

var analyzerType = applicableAnalyzer.GetType ();
var rule = diagnostics[i].HasLocation && applicableAnalyzer.SupportedDiagnostics.Length == 1 ? string.Empty : $"{analyzerType.Name}.{diagnosticsId}";
var rule = diagnostics[i].HasLocation &&
applicableAnalyzer.SupportedDiagnostics.Length == 1 ? string.Empty : $"DiagnosticId.{(DiagnosticId) Int32.Parse (diagnosticsId.Substring (2))}";
Copy link
Member

Choose a reason for hiding this comment

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

Extract helper method for this usage and below?


return new DiagnosticDescriptor (diagnosticId.AsString (),
lrsTitle!,
lrsMessage!,
Copy link
Member

Choose a reason for hiding this comment

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

What if one of the title or message is null?

{
public sealed override ImmutableArray<string> FixableDiagnosticIds
=> ImmutableArray.Create (RequiresUnreferencedCodeAnalyzer.IL2026);
=> ImmutableArray.Create (DiagnosticId.RequiresUnreferencedCode.AsString ());
Copy link
Member

Choose a reason for hiding this comment

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

Consider storing the SupportedDiagnostics of the RequiresUnreferencedCodeAnalyzer as a static property, then calling that property to get the full list of diagnostic IDs for this.

Same idea for RequiresAssemblyFilesCodeFixProvider.

@mateoatr mateoatr merged commit acd72ce into dotnet:main Jul 30, 2021
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
…tor given a DiagnosticId (dotnet/linker#2170)

* Add DiagnosticId enum
Add GetDiagnosticDescriptor

* Check that the diagnostic id is in the range of the supported linker warnings

* Lint

* Share DiagnosticString

* Noisy whitespace

* Warnings go up to 6000 inclusive

* PR feedback

* Get diagnostic string
Update test

* Lint

* PR feedback

Commit migrated from dotnet/linker@acd72ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants