public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var node = await context.GetFixableNodeAsync <SyntaxNode>(n => n is BinaryExpressionSyntax || n is InvocationExpressionSyntax); if (node == null) { return; } Func <CancellationToken, Task <Document> > action = null; switch (node) { case BinaryExpressionSyntax bes: action = ct => ReplaceBinaryExpressionAsync(context.Document, bes, ct); break; case InvocationExpressionSyntax ies: action = ct => ReplaceInvocationExpressionAsync(context.Document, ies, ct); break; } context.RegisterCodeFix( CodeAction.Create( Strings.TagComparisonCodeFixTitle, action, node.ToFullString()), context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var methodDeclaration = await context.GetFixableNodeAsync<MethodDeclarationSyntax>(); if (methodDeclaration == null) return; context.RegisterCodeFix( CodeAction.Create( Strings.InitializeOnLoadMethodCodeFixTitle, ct => FixMethodAsync(context.Document, methodDeclaration, ct), methodDeclaration.ToFullString()), context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var expression = await context.GetFixableNodeAsync <SyntaxNode>(c => c is BinaryExpressionSyntax || c is AssignmentExpressionSyntax || c is ConditionalAccessExpressionSyntax); if (expression == null) { return; } CodeAction action; switch (expression) { // Null coalescing case BinaryExpressionSyntax bes: if (HasSideEffect(bes.Left)) { return; } action = CodeAction.Create(Strings.UnityObjectNullCoalescingCodeFixTitle, ct => ReplaceNullCoalescingAsync(context.Document, bes, ct), bes.ToFullString()); break; // Null propagation case ConditionalAccessExpressionSyntax caes: if (HasSideEffect(caes.Expression) && caes.WhenNotNull is MemberBindingExpressionSyntax) { return; } action = CodeAction.Create(Strings.UnityObjectNullPropagationCodeFixTitle, ct => ReplaceNullPropagationAsync(context.Document, caes, ct), caes.ToFullString()); break; // Coalescing assignment case AssignmentExpressionSyntax aes: if (HasSideEffect(aes.Left)) { return; } action = CodeAction.Create(Strings.UnityObjectCoalescingAssignmentCodeFixTitle, ct => ReplaceCoalescingAssignmentAsync(context.Document, aes, ct), aes.ToFullString()); break; default: return; } context.RegisterCodeFix(action, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var declaration = await context.GetFixableNodeAsync <MemberDeclarationSyntax>(); if (declaration is not(PropertyDeclarationSyntax or FieldDeclarationSyntax)) { return; } context.RegisterCodeFix( CodeAction.Create( Strings.ImproperSerializeFieldCodeFixTitle, ct => RemoveSerializeFieldAttributeAsync(context.Document, declaration, ct), declaration.ToFullString()), context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var declaration = await context.GetFixableNodeAsync <MethodDeclarationSyntax>(); if (declaration == null) { return; } context.RegisterCodeFix( CodeAction.Create( Strings.EmptyUnityMessageCodeFixTitle, ct => DeleteEmptyMessageAsync(context.Document, declaration, ct), declaration.ToFullString()), context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var expression = await context.GetFixableNodeAsync <AssignmentExpressionSyntax>(); if (expression == null) { return; } context.RegisterCodeFix( CodeAction.Create( Strings.SetPositionAndRotationCodeFixTitle, ct => ReplaceWithInvocationAsync(context.Document, expression, ct), expression.ToFullString()), context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var invocation = await context.GetFixableNodeAsync <InvocationExpressionSyntax>(); if (invocation == null) { return; } context.RegisterCodeFix( CodeAction.Create( Strings.InputGetKeyCodeFixTitle, ct => UseKeyCodeMemberAsArgumentAsync(context.Document, invocation, ct), invocation.ToFullString()), context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var access = await context.GetFixableNodeAsync <MemberAccessExpressionSyntax>(); if (access == null) { return; } context.RegisterCodeFix( CodeAction.Create( Strings.IndirectionMessageCodeFixTitle, ct => DeleteIndirectionAsync(context.Document, access, ct), access.Expression.ToFullString()), context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var classDeclaration = await context.GetFixableNodeAsync <ClassDeclarationSyntax>(); if (classDeclaration == null) { return; } context.RegisterCodeFix( CodeAction.Create( Strings.InitializeOnLoadStaticCtorCodeFixTitle, ct => CreateStaticCtorAsync(context.Document, classDeclaration, ct), classDeclaration.ToFullString()), context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var node = await context.GetFixableNodeAsync <BinaryExpressionSyntax>(); if (node == null) { return; } context.RegisterCodeFix( CodeAction.Create( Strings.VectorMathCodeFixTitle, ct => FixOperandOrderAsync(context.Document, node, ct), node.ToFullString()), context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var creation = await context.GetFixableNodeAsync <ObjectCreationExpressionSyntax>(); if (creation == null) { return; } var diagnostic = context.Diagnostics.FirstOrDefault(); if (diagnostic == null) { return; } var model = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false); if (model == null) { return; } switch (diagnostic.Id) { case CreateInstanceAnalyzer.ScriptableObjectId: context.RegisterCodeFix( CodeAction.Create( Strings.CreateScriptableObjectInstanceCodeFixTitle, ct => ReplaceWithInvocationAsync(context.Document, creation, "ScriptableObject", "CreateInstance", ct), creation.ToFullString()), context.Diagnostics); break; case CreateInstanceAnalyzer.ComponentId when !IsInsideComponent(creation, model): return; case CreateInstanceAnalyzer.ComponentId: context.RegisterCodeFix( CodeAction.Create( Strings.CreateMonoBehaviourInstanceCodeFixTitle, ct => ReplaceWithInvocationAsync(context.Document, creation, "gameObject", "AddComponent", ct), creation.ToFullString()), context.Diagnostics); break; } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var invocation = await context.GetFixableNodeAsync <InvocationExpressionSyntax>(); if (invocation == null) { return; } if (!await IsRegistrableAsync(context, invocation)) { return; } context.RegisterCodeFix( CodeAction.Create( Title, ct => ChangeArgumentAsync(context.Document, invocation, ct), invocation.ToFullString()), context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var identifierName = await context.GetFixableNodeAsync <IdentifierNameSyntax>(); if (identifierName == null) { return; } var diagnostic = context.Diagnostics.FirstOrDefault(); if (diagnostic == null) { return; } switch (diagnostic.Id) { case UpdateDeltaTimeAnalyzer.UpdateId: context.RegisterCodeFix( CodeAction.Create( Strings.UpdateWithoutFixedDeltaTimeCodeFixTitle, ct => ReplaceDeltaTimeIdentifierAsync(context.Document, identifierName, "deltaTime", ct), identifierName.ToFullString()), context.Diagnostics); break; case UpdateDeltaTimeAnalyzer.FixedUpdateId: context.RegisterCodeFix( CodeAction.Create( Strings.FixedUpdateWithoutDeltaTimeCodeFixTitle, ct => ReplaceDeltaTimeIdentifierAsync(context.Document, identifierName, "fixedDeltaTime", ct), identifierName.ToFullString()), context.Diagnostics); break; } }