Пример #1
0
        /// <inheritdoc/>
        public override async Task RegisterCodeFixesAsync(
            CodeFixContext context)
        {
            var localize = Localizers.Of <R>(R.ResourceManager);
            var title    = localize(nameof(R.FixTitle))
                           .ToString(CultureInfo.CurrentCulture);

            var root = await context
                       .Document.GetSyntaxRootAsync(context.CancellationToken)
                       .ConfigureAwait(false);

            if (root is null)
            {
                return;
            }

            var diagnostic     = context.Diagnostics[0];
            var diagnosticSpan = diagnostic.Location.SourceSpan;

            var node = root.FindNodeOfType <AceSyntax>(diagnosticSpan);

            if (node is null)
            {
                return;
            }

            context.RegisterCodeFix(
                CodeAction.Create(
                    title: title,
                    createChangedSolution:
                    c => Replace(context.Document, node, c),
                    equivalenceKey: title),
                diagnostic);
        }
Пример #2
0
        /// <inheritdoc/>
        public override async Task RegisterCodeFixesAsync(
            CodeFixContext context)
        {
            var localize = Localizers.Of <R>(R.ResourceManager);
            var title    = localize(nameof(R.FixTitle))
                           .ToString(CultureInfo.CurrentCulture);

            var root = await context
                       .Document.GetSyntaxRootAsync(context.CancellationToken)
                       .ConfigureAwait(false);

            if (root is null)
            {
                return;
            }

            var diagnostic = context.Diagnostics[0];
            var span       = diagnostic.Location.SourceSpan;
            var token      = root.FindToken(span.Start, findInsideTrivia: true);

            context.RegisterCodeFix(
                CodeAction.Create(
                    title: title,
                    createChangedDocument:
                    c => FixTask(context.Document, root, token),
                    equivalenceKey: title),
                diagnostic);
        }
Пример #3
0
        /// <inheritdoc/>
        public override async Task RegisterCodeFixesAsync(
            CodeFixContext context)
        {
            var localize       = Localizers.Of <R>(R.ResourceManager);
            var insertFixTitle = localize(nameof(R.InsertFixTitle))
                                 .ToString(CultureInfo.CurrentCulture);
            var replaceFixTitle = localize(nameof(R.ReplaceFixTitle))
                                  .ToString(CultureInfo.CurrentCulture);

            var root = await context
                       .Document.GetSyntaxRootAsync(context.CancellationToken)
                       .ConfigureAwait(false);

            if (root is null)
            {
                return;
            }

            var diagnostic = context.Diagnostics[0];
            var span       = diagnostic.Location.SourceSpan;
            var token      = root.FindToken(span.Start, findInsideTrivia: true);

            if (token == default)
            {
                return;
            }
Пример #4
0
        private static DiagnosticDescriptor NewRule()
        {
            var localize = Localizers.Of <R>(R.ResourceManager);

            return(new DiagnosticDescriptor(
                       DiagnosticId,
                       localize(nameof(R.Title)),
                       localize(nameof(R.MessageFormat)),
                       Category,
                       DiagnosticSeverity.Warning,
                       isEnabledByDefault: true,
                       description: localize(nameof(R.Description)),
                       helpLinkUri: HelpLink.ToUri(DiagnosticId)));
        }
Пример #5
0
        /// <inheritdoc/>
        public override async Task RegisterCodeFixesAsync(
            CodeFixContext context)
        {
            var localize = Localizers.Of <R>(R.ResourceManager);
            var title    = localize(nameof(R.FixTitle))
                           .ToString(CultureInfo.CurrentCulture);

            var root = await context
                       .Document.GetSyntaxRootAsync(context.CancellationToken)
                       .ConfigureAwait(false);

            if (root is null)
            {
                return;
            }

            var diagnostic     = context.Diagnostics[0];
            var diagnosticSpan = diagnostic.Location.SourceSpan;

            string GetValue(string key)
            {
                var property = diagnostic.Properties[key];

                if (property is null)
                {
                    throw new NullReferenceException(nameof(property));
                }
                return(property);
            }

            var node = root.FindNodeOfType <ForStatementSyntax>(diagnosticSpan);

            if (node is null)
            {
                return;
            }

            context.RegisterCodeFix(
                CodeAction.Create(
                    title: title,
                    createChangedDocument:
                    c => Replace(context.Document, node, GetValue, c),
                    equivalenceKey: title),
                diagnostic);
        }
Пример #6
0
            static string FixTitle(string key)
            {
                var localize = Localizers.Of <R>(R.ResourceManager);

                return(localize(key).ToString(CultureInfo.CurrentCulture));
            }