Пример #1
0
        static async Task FixAll(TextEditor editor, ValidCodeDiagnosticAction fix, FixAllProvider provider, DiagnosticAnalyzer diagnosticAnalyzer)
        {
            var diagnosticIds = diagnosticAnalyzer.SupportedDiagnostics.Select(d => d.Id).ToImmutableHashSet();

            var analyzers = new [] { diagnosticAnalyzer }.ToImmutableArray();

            var dict        = ImmutableDictionary <Document, ImmutableArray <Diagnostic> > .Empty;
            var doc         = editor.DocumentContext.AnalysisDocument;
            var diagnostics = await GetDiagnosticsForDocument(analyzers, doc, diagnosticIds, CancellationToken.None);

            dict = dict.Add(doc, diagnostics);
            var fixAllDiagnosticProvider = new FixAllState.FixMultipleDiagnosticProvider(dict);

            var ctx = new FixAllContext(
                editor.DocumentContext.AnalysisDocument,
                fix.Diagnostic.GetCodeFixProvider(),
                FixAllScope.Document,
                fix.CodeAction.EquivalenceKey,
                diagnosticIds,
                fixAllDiagnosticProvider,
                default(CancellationToken)
                );

            var fixAll = await provider.GetFixAsync(ctx);

            using (var undo = editor.OpenUndoGroup()) {
                await CodeDiagnosticDescriptor.RunAction(editor.DocumentContext, fixAll, default(CancellationToken));
            }
        }
Пример #2
0
        static async Task FixAll(TextEditor editor, ValidCodeDiagnosticAction fix, FixAllProvider provider, DiagnosticAnalyzer diagnosticAnalyzer)
        {
            var diagnosticIds = diagnosticAnalyzer.SupportedDiagnostics.Select(d => d.Id).ToImmutableHashSet();

            var analyzers = new [] { diagnosticAnalyzer }.ToImmutableArray();

            var fixAllDiagnosticProvider = new FixAllState.FixAllDiagnosticProvider(
                diagnosticIds,
                async(doc, diagnostics, token) => await GetDiagnosticsForDocument(analyzers, doc, diagnostics, token).ConfigureAwait(false),
                (Project arg1, bool arg2, ImmutableHashSet <string> arg3, CancellationToken arg4) => {
                return(Task.FromResult((IEnumerable <Diagnostic>) new Diagnostic [] { }));
            });

            var ctx = new FixAllContext(
                editor.DocumentContext.AnalysisDocument,
                fix.Diagnostic.GetCodeFixProvider(),
                FixAllScope.Document,
                fix.CodeAction.EquivalenceKey,
                diagnosticIds,
                fixAllDiagnosticProvider,
                default(CancellationToken)
                );

            var fixAll = await provider.GetFixAsync(ctx);

            using (var undo = editor.OpenUndoGroup()) {
                await CodeDiagnosticDescriptor.RunAction(editor.DocumentContext, fixAll, default(CancellationToken));
            }
        }