Skip to content

Ensure equivalence key is not null#52111

Merged
CyrusNajmabadi merged 9 commits intodotnet:mainfrom
Youssef1313:equiv-key
Jul 11, 2021
Merged

Ensure equivalence key is not null#52111
CyrusNajmabadi merged 9 commits intodotnet:mainfrom
Youssef1313:equiv-key

Conversation

@Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Mar 24, 2021

Fixes #52074

@Youssef1313 Youssef1313 requested a review from a team as a code owner March 24, 2021 14:23
@ghost ghost added the Area-IDE label Mar 24, 2021
@jinujoseph jinujoseph added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Mar 25, 2021
@Youssef1313 Youssef1313 marked this pull request as draft March 30, 2021 14:54
@Youssef1313 Youssef1313 marked this pull request as ready for review March 30, 2021 15:29
// Make a SolutionChangeAction. This way we can let it generate the diff
// preview appropriately.
var solutionChangeAction = new SolutionChangeAction("", c => GetUpdatedSolutionAsync(c));
var solutionChangeAction = new SolutionChangeAction("", c => GetUpdatedSolutionAsync(c), "");
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why the title is empty string here. Is this code action (for some reason) non user-facing?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes. it is only used to get the operations out.

string title,
Func<CancellationToken, Task<Solution>> createChangedSolution,
string? equivalenceKey = null,
string? equivalenceKey,
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 didn't change this to non-nullable because it's called by a public API:

public static CodeAction Create(string title, Func<CancellationToken, Task<Solution>> createChangedSolution, string? equivalenceKey = null)

I'll have to either add a suppression or change the public API nullability. I thought it's good enough for this to not be optional.

{
public MoveMisplacedUsingsCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(CSharpAnalyzersResources.Move_misplaced_using_directives, createChangedDocument)
: base(CSharpAnalyzersResources.Move_misplaced_using_directives, createChangedDocument, nameof(CSharpAnalyzersResources.Move_misplaced_using_directives))
Copy link
Member Author

Choose a reason for hiding this comment

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

This change causing cleanup tests to fail. I still didn't figure out why, would be helpful if someone knows.

Copy link
Member Author

Choose a reason for hiding this comment

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

In:

var context = new CodeFixContext(document, diagnostic, GetRegisterCodeFixAction(fixAllContext.CodeActionEquivalenceKey, codeActions), cancellationToken);

fixAllContext.CodeActionEquivalenceKey is null, causing the following condition to be false:

if (currentAction is { EquivalenceKey: var equivalenceKey }
&& codeActionEquivalenceKey == equivalenceKey)
{
lock (codeActions)
codeActions.Add(currentAction);
}

Hence, no code actions are executed:

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 fixed that in e6b3238 and 4e54b71.

I used the first fix as similar thing is done in:

// TODO: Just get the first fix for now until we have a way to config user's preferred fix
// https://github.com/dotnet/roslyn/issues/27066
return result.ToImmutable().FirstOrDefault();

@Youssef1313
Copy link
Member Author

@sharwell @CyrusNajmabadi Can you review please? Thanks.

@Youssef1313
Copy link
Member Author

Also pinging @mavasani specifically for the last two commits.

@Youssef1313
Copy link
Member Author

@sharwell @mavasani @CyrusNajmabadi Can someone review? Thanks!

@Youssef1313
Copy link
Member Author

Ping @sharwell @CyrusNajmabadi @mavasani

if (diagnostics.IsDefaultOrEmpty)
return null;

var title = FixAllContextHelper.GetDefaultFixAllTitle(fixAllContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Member Author

@Youssef1313 Youssef1313 Jul 11, 2021

Choose a reason for hiding this comment

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

why?

Possibly I was using it as equivalence key so I extracted to a variable, and changed that in a later commit to only use it as title.

@CyrusNajmabadi CyrusNajmabadi merged commit 7b4b65c into dotnet:main Jul 11, 2021
@ghost ghost added this to the Next milestone Jul 11, 2021
@CyrusNajmabadi
Copy link
Contributor

Thank you :)

@Youssef1313 Youssef1313 deleted the equiv-key branch July 11, 2021 07:16
@allisonchou allisonchou modified the milestones: Next, 17.0.P3 Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Equivalence key shouldn't be null

5 participants