Skip to content

Commit

Permalink
NET-1035 AnalysisContext: Rename CancellationToken to Cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-mikula-sonarsource authored and sonartech committed Jan 24, 2025
1 parent 90bd7dc commit a11f629
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override async Task RegisterCodeFixesAsync(SyntaxNode root, SonarCodeF
oldNode = globalStatementSyntax.Statement;
}

var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await context.Document.GetSemanticModelAsync(context.Cancel).ConfigureAwait(false);
var newNode = Simplify(diagnostic, semanticModel, oldNode);
if (newNode != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static async Task RegisterCodeFixesForMethodsAsync(SonarCodeFixContext c
},
context.Diagnostics);

var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await context.Document.GetSemanticModelAsync(context.Cancel).ConfigureAwait(false);

var systemNeedsToBeAdded = NamespaceNeedsToBeAdded(methodBody, semanticModel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override Task RegisterCodeFixesAsync(SyntaxNode root, SonarCodeFixCont
return Task.CompletedTask;
}

var semanticModel = context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false).GetAwaiter().GetResult();
var semanticModel = context.Document.GetSemanticModelAsync(context.Cancel).ConfigureAwait(false).GetAwaiter().GetResult();
var enumerableHelperType = semanticModel.Compilation.GetTypeByMetadataName(KnownType.System_Linq_Enumerable);

if (enumerableHelperType != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ protected override async Task RegisterCodeFixesAsync(SyntaxNode root, SonarCodeF
var diagnosticSpan = diagnostic.Location.SourceSpan;
var memberAccess = (MemberAccessExpressionSyntax)root.FindNode(diagnosticSpan, getInnermostNodeForTie: true);

var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await context.Document.GetSemanticModelAsync(context.Cancel).ConfigureAwait(false);
var fieldSymbol = (IFieldSymbol)semanticModel.GetSymbolInfo(memberAccess.Expression).Symbol;
var typeParameterSymbol = (ITypeParameterSymbol)fieldSymbol.Type;
var genericType = typeParameterSymbol.ContainingType;

var classDeclarationTasks = genericType.DeclaringSyntaxReferences
.Select(reference => reference.GetSyntaxAsync(context.CancellationToken))
.Select(reference => reference.GetSyntaxAsync(context.Cancel))
.ToList();

var taskResults = await Task.WhenAll(classDeclarationTasks).ConfigureAwait(false);
Expand All @@ -60,7 +60,7 @@ protected override async Task RegisterCodeFixesAsync(SyntaxNode root, SonarCodeF
foreach (var classes in mapping)
{
var document = currentSolution.GetDocument(classes.Key);
var docRoot = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
var docRoot = await document.GetSyntaxRootAsync(context.Cancel).ConfigureAwait(false);
var newDocRoot = GetNewDocumentRoot(docRoot, typeParameterSymbol, classes);
currentSolution = currentSolution.WithDocumentSyntaxRoot(classes.Key, newDocRoot);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override async Task RegisterCodeFixesAsync(SyntaxNode root, SonarCodeF
? binary.Right
: binary.Left;

var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await context.Document.GetSemanticModelAsync(context.Cancel).ConfigureAwait(false);
var typeSymbol = (ITypeParameterSymbol)semanticModel.GetTypeInfo(otherNode).Type;
var defaultExpression = SyntaxFactory.DefaultExpression(SyntaxFactory.ParseTypeName(typeSymbol.Name));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ protected override async Task RegisterCodeFixesAsync(SyntaxNode root, SonarCode
}

var semanticModel = await context.Document
.GetSemanticModelAsync(context.CancellationToken)
.GetSemanticModelAsync(context.Cancel)
.ConfigureAwait(false);
var allFieldDeclarationTasks = identifiersToFix.Select(identifier =>
GetFieldDeclarationSyntaxAsync(semanticModel, identifier, context.CancellationToken));
GetFieldDeclarationSyntaxAsync(semanticModel, identifier, context.Cancel));
var allFieldDeclarations = await Task.WhenAll(allFieldDeclarationTasks).ConfigureAwait(false);
allFieldDeclarations = allFieldDeclarations.WhereNotNull().ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override async Task RegisterCodeFixesAsync(SyntaxNode root, SonarCodeF
return;
}

var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await context.Document.GetSemanticModelAsync(context.Cancel).ConfigureAwait(false);
var parameterSymbol = semanticModel.GetDeclaredSymbol(parameter);
if (!(parameterSymbol?.ContainingSymbol is IMethodSymbol methodSymbol))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ protected override async Task RegisterCodeFixesAsync(SyntaxNode root, SonarCodeF
var diagnosticSpan = diagnostic.Location.SourceSpan;
var node = root.FindNode(diagnosticSpan, getInnermostNodeForTie: true);

var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await context.Document.GetSemanticModelAsync(context.Cancel).ConfigureAwait(false);
var operation = semanticModel.GetSymbolInfo(node).Symbol as IMethodSymbol;

if (!(operation?.ReturnType?.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax(context.CancellationToken) is EnumDeclarationSyntax enumDeclaration))
if (!(operation?.ReturnType?.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax(context.Cancel) is EnumDeclarationSyntax enumDeclaration))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override async Task RegisterCodeFixesAsync(SyntaxNode root, SonarCodeF
return;
}

var semanticModel = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
var semanticModel = await context.Document.GetSemanticModelAsync(context.Cancel).ConfigureAwait(false);
var methodParameterLookup = new CSharpMethodParameterLookup(invocation, semanticModel);
var argumentMappings = methodParameterLookup.GetAllArgumentParameterMappings().ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override SyntaxNode ReplaceConstructorWithField(SyntaxNode root, Synta
ExpressionSyntax typeNode;
if (node.IsKind(SyntaxKindEx.ImplicitObjectCreationExpression))
{
var semanticModel = context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false).GetAwaiter().GetResult();
var semanticModel = context.Document.GetSemanticModelAsync(context.Cancel).ConfigureAwait(false).GetAwaiter().GetResult();
typeNode = SyntaxFactory.IdentifierName(semanticModel.GetTypeInfo(node).Type.Name);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public readonly struct SonarCodeFixContext
{
private readonly CodeFixContext context;

public readonly CancellationToken CancellationToken => context.CancellationToken;
public readonly CancellationToken Cancel => context.CancellationToken;
public readonly Document Document => context.Document;
public readonly ImmutableArray<Diagnostic> Diagnostics => context.Diagnostics;
public readonly TextSpan Span => context.Span;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task SonarCodeFixContext_Properties_ReturnRoslynCodeFixContextPrope
var diagnostic = Diagnostic.Create(new DiagnosticDescriptor("1", "title", "format", "category", DiagnosticSeverity.Hidden, false), literal.GetLocation());
var sonarCodefix = new SonarCodeFixContext(new CodeFixContext(document, diagnostic, (_, _) => { }, cancel));

sonarCodefix.CancellationToken.Should().Be(cancel);
sonarCodefix.Cancel.Should().Be(cancel);
sonarCodefix.Document.Should().Be(document);
sonarCodefix.Diagnostics.Should().Contain(diagnostic);
sonarCodefix.Span.Should().Be(new TextSpan(18, 13));
Expand Down

0 comments on commit a11f629

Please sign in to comment.