Vannevelj / VSDiagnostics

A collection of static analyzers based on Roslyn that integrate with VS
GNU General Public License v2.0
65 stars 16 forks source link

Incorrect use of cancellation token #609

Closed Hosch250 closed 6 years ago

Hosch250 commented 8 years ago

We use the following pattern everywhere in our code. We are not supposed to use the context.CancellationToken here, but rather the cancellation token x.

context.RegisterCodeFix(
    CodeAction.Create("Title",
                x => DoFixAsync(context.Document, methodDeclaration, root, context.CancellationToken), "Id"), 
                diagnostic);
Vannevelj commented 7 years ago

Do you have some background information on this?

Hosch250 commented 7 years ago

This is how the Roslyn team told me to do it when I was implementing code fixes for them.

Vannevelj commented 7 years ago

Well that's not enough to change the existing code though. Can you get some more info on it? I don't want to make changes based on hearsay

Hosch250 commented 7 years ago

One comment: https://github.com/dotnet/roslyn/pull/12902#r73414166 Another: https://github.com/dotnet/roslyn/pull/12902#r73414285 Here is a comment about context.CancellationToken: https://github.com/dotnet/roslyn/pull/12997#r74368743

Vannevelj commented 7 years ago

Alright, good enough for me. Would be helpful to know the difference between these though