Skip to content

Conversation

@iserrato
Copy link
Contributor

  • Reorganized the DAM CodeFix to not rely on 'BaseAttributeCodeFixProvider`, as the DAM CodeFix requires different functionality for placing attributes on parameters, returns, etc.
  • Create test cases for supported Diagnostic IDs

iserrato added 2 commits July 14, 2022 11:03
- remove unsupported diagnostics from `SupportedDiagnostics` list
- remove unused functions/variables
- remove unneccessary comments
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.

Minor things, I think in general looks good

var diagnostic = context.Diagnostics.First ();
var props = diagnostic.Properties;
var model = await document.GetSemanticModelAsync (context.CancellationToken).ConfigureAwait (false);
SyntaxNode diagnosticNode = root!.FindNode (diagnostic.Location.SourceSpan);
Copy link
Member

Choose a reason for hiding this comment

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

Could you please apply the fix from https://github.com/dotnet/linker/pull/2900/files here? If I understood that fix, I think it may matter for example in the case where a method invocation is passed as an argument, like:

static void M([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type t)
{
    DoSomethingWithMethods(t.GetMethods());
}

Maybe @agocke can confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I add a test case associated with this fix?

Copy link
Member

Choose a reason for hiding this comment

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

Yes please! Best would be to confirm that the testcase produces an incorrect result before the fix, and then check that it works with the fix.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, that's exactly what my change fixes. I would agree -- creating a test case, confirming it throws an exception, then applying the fix and confirming it no longer does so is a good idea.

Copy link
Member

@agocke agocke Jul 21, 2022

Choose a reason for hiding this comment

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

Ah, actually it looks like diagnosticNode is properly null checked below, so it won't throw an exception. Probably just won't work (the type will be ArgumentSyntax instead of InvocationExpressionSyntax).

Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

One more comment and this LGTM. Thank you!

@iserrato iserrato merged commit 8062da2 into dotnet:main Jul 25, 2022

namespace ILLink.CodeFix
{
public class DAMCodeFixProvider : Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider
Copy link
Member

@Youssef1313 Youssef1313 Jul 30, 2022

Choose a reason for hiding this comment

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

I believe this won't work in Visual Studio. You need to have [ExportCodefixProvider(LanguageNames.CSharp), Shared] on the class. Opened #2932

@iserrato iserrato deleted the DAMCodeFixer branch August 19, 2022 17:30
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
* Create infrastructure for CodeFixers that will generate attribute flags for DynamicallyAccessedMembers (DAM) trimmer warnings. This commit includes fixers for the warnings `DynamicallyAccessedMembersMismatchParameterTargetsThisParameter` and `DynamicallyAccessedMembersMismatchFieldTargetsThisParameter`. Additional DiagnosticIds will be supported by future commits.

* Create new class for the DAM CodeFixer that does not rely on base class. The DAM warnings require different attribute placement depending on the type of warning that is raised, causing it to differ from the implementation of the base class.

* Added a test file specifically for the DAM CodeFixer, include tests for the functional fixes as well as tests for fixes that will soon be implemented.

* Converted all test cases within DAM to use string literals

Co-authored-by: Andy Gocke <[email protected]>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants