Repository: dotnet/roslyn
File: src/Features/Core/Portable/FullyQualify/AbstractFullyQualifyCodeFixProvider.cs (C#)

Code before:
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Shared.Extensions;

namespace Microsoft.CodeAnalysis.CodeFixes.FullyQualify;

internal abstract class AbstractFullyQualifyCodeFixProvider : CodeFixProvider
{
    public override FixAllProvider? GetFixAllProvider()
    {
        // Fix All is not supported by this code fix
        // https://github.com/dotnet/roslyn/issues/34465
        return null;
    }

    public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
    {
        var cancellationToken = context.CancellationToken;
        var document = context.Document;

        var service = document.GetRequiredLanguageService<IFullyQualifyService>();
        var optFixData = await service.GetFixDataAsync(document, context.Span, cancellationToken).ConfigureAwait(false);
        if (optFixData is null)
            return;

        var fixData = optFixData.Value;
        if (fixData.IndividualFixData.Length == 0)
            return;

        var codeActions = fixData.IndividualFixData.SelectAsArray(
            d => CodeAction.Create(
                d.Title,
                async cancellationToken =>
                {
                    var sourceText = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
                    var newText = sourceText.WithChanges(d.TextChanges);
                    return document.WithText(newText);
                },
                d.Title));

        if (codeActions.Length >= 2)
        {
            // Wrap the actions into a single top level suggestion so as to not clutter the list.
            context.RegisterCodeFix(CodeAction.Create(
                string.Format(FeaturesResources.Fully_qualify_0, fixData.Name),
                codeActions,
                isInlinable: true), context.Diagnostics);
        }
        else
        {

Review comment (bug):
this fixer is fairly special as it has its own remote service that it calls into.  this was crashing as the remote service was not expecting to be called ona  source-generated doc.  simplest fix is to just disable ourselves there since we can't offer anything useful anyways.

Code after:
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Shared.Extensions;

namespace Microsoft.CodeAnalysis.CodeFixes.FullyQualify;

internal abstract class AbstractFullyQualifyCodeFixProvider : CodeFixProvider
{
    public override FixAllProvider? GetFixAllProvider()
    {
        // Fix All is not supported by this code fix
        // https://github.com/dotnet/roslyn/issues/34465
        return null;
    }

    public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
    {
        var cancellationToken = context.CancellationToken;

        var document = context.Document;

        // Don't bother executing this within a source-generated document.  Changing the code here isn't actually
        // possible, and we don't need to make pointless calls to oop to compute things.
        if (document.Id.IsSourceGenerated)
            return;

        var service = document.GetRequiredLanguageService<IFullyQualifyService>();
        var optFixData = await service.GetFixDataAsync(document, context.Span, cancellationToken).ConfigureAwait(false);
        if (optFixData is null)
            return;

        var fixData = optFixData.Value;
        if (fixData.IndividualFixData.Length == 0)
            return;

        var codeActions = fixData.IndividualFixData.SelectAsArray(
            d => CodeAction.Create(
                d.Title,
                async cancellationToken =>
                {
                    var sourceText = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
                    var newText = sourceText.WithChanges(d.TextChanges);
                    return document.WithText(newText);
                },
                d.Title));

        if (codeActions.Length >= 2)
        {
            // Wrap the actions into a single top level suggestion so as to not clutter the list.
            context.RegisterCodeFix(CodeAction.Create(