Skip to content

Add code fix for VSSDK001 #15

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

Merged
merged 6 commits into from
Feb 9, 2018
Merged

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented Feb 9, 2018

This automatically changes the base type from Package to AsyncPackage

In the future, it can apply more changes like update the Initialize override, etc.

This is a rather large change because with it comes the testing infrastructure to support testing code fix providers.

@AArnott AArnott self-assigned this Feb 9, 2018
.WithTrailingTrivia(baseTypeSyntax.GetTrailingTrivia());
var updatedRoot = root.ReplaceNode(baseTypeSyntax, asyncPackageBaseTypeSyntax);

return document.WithSyntaxRoot(updatedRoot);
Copy link
Member

Choose a reason for hiding this comment

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

How flexible are we here? Can we also add the InitializeAsync method with it throwing NotImplementedException?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm working on that now, actually.

Copy link
Member Author

Choose a reason for hiding this comment

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

done


if (qualifiers.Count == 0)
{
throw new ArgumentException("At least one qualifier required.");
Copy link
Member

Choose a reason for hiding this comment

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

Should pass in nameof(qualifiers) as the second arg to specify the argument causing the issue

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed


private async Task<Document> ChangeBaseTypeAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

Can extension developers enable these analyzers on VS 2013 projects without referecing Shell.14.0 or Shell.15.0 in which case this fix or the original warning wouldn't apply to them?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes they can, and I haven't accommodated for that yet.

Choose a reason for hiding this comment

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

Yeah, this one is interesting to me too. If a vsix project targets VS 2013 or below, this diagnostic shouldn't apply. They can choose to simply ignore the diagnostic but I wonder if it's possible to be smarter. Maybe looking at the references of the current project and determining if the version of Shell they're referencing is Shell.14+.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a solution, yes. We could look at references but that would get tedious to maintain long-term and isn't a great pattern IMO. Instead, I plan to support this by testing for the existence of the type within that compilation unit. If it exists, the analyzer will run -- otherwise it will turn itself off. This should scale and be a pattern that other analyzers can use too.

@madskristensen
Copy link
Contributor

There are conflicts. Perhaps due to the merger of the previous 3 PRs

SyntaxFactory.MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
Types.ThreadHelper.TypeSyntax,
SyntaxFactory.IdentifierName(Types.ThreadHelper.JoinableTaskFactory)),

Choose a reason for hiding this comment

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

Why not use this.JoinableTaskFactory here instead? That's what we're planning on doing in the AsyncPackage template when we get to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh ya. whoops. Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Given Mads already completed the PR, I have a commit that addresses this that I will include in a future PR.

@codecov-io
Copy link

Codecov Report

Merging #15 into master will increase coverage by 21.98%.
The diff coverage is 96.32%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #15       +/-   ##
===========================================
+ Coverage   65.45%   87.43%   +21.98%     
===========================================
  Files           2        5        +3     
  Lines          55      191      +136     
===========================================
+ Hits           36      167      +131     
- Misses         19       24        +5
Impacted Files Coverage Δ
...nalyzers/VSSDK001DeriveFromAsyncPackageAnalyzer.cs 100% <ø> (ø)
...Microsoft.VisualStudio.SDK.Analyzers/Namespaces.cs 100% <100%> (ø)
src/Microsoft.VisualStudio.SDK.Analyzers/Types.cs 100% <100%> (ø)
src/Microsoft.VisualStudio.SDK.Analyzers/Utils.cs 48.83% <75%> (+10.12%) ⬆️
...Analyzers/VSSDK001DeriveFromAsyncPackageCodeFix.cs 97.75% <97.75%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73b9c75...fde9711. Read the comment docs.

@madskristensen madskristensen merged commit 885d282 into microsoft:master Feb 9, 2018
@madskristensen
Copy link
Contributor

Awesome. Thanks!

@AArnott AArnott deleted the codefix branch February 9, 2018 19:39
@madskristensen
Copy link
Contributor

madskristensen commented Feb 9, 2018

Sorry, it seems that I got too excited and merged the PR prematurely :)

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