Пример #1
0
        public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
        {
            var(document, span, cancellationToken) = context;

            // Ensure rename can still be invoked in this document. We reanalyze the document for
            // diagnostics when rename tracking is manually dismissed, but the existence of our
            // diagnostic may still be cached, so we have to double check before actually providing
            // any fixes.
            if (!RenameTrackingTaggerProvider.CanInvokeRename(document))
            {
                return;
            }

            var diagnostic = await TryGetDiagnosticAsync(document, cancellationToken).ConfigureAwait(false);

            if (diagnostic == null)
            {
                return;
            }

            // user needs to be on the same line as the diagnostic location.
            var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);

            if (!text.AreOnSameLine(span.Start, diagnostic.Location.SourceSpan.Start))
            {
                return;
            }

            var action = RenameTrackingTaggerProvider.CreateCodeAction(
                document, diagnostic, _refactorNotifyServices, _undoHistoryRegistry);

            context.RegisterRefactoring(action);
        }
Пример #2
0
        internal async Task <Diagnostic?> TryGetDiagnosticAsync(Document document, CancellationToken cancellationToken)
        {
            var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);

            return(RenameTrackingTaggerProvider.TryGetDiagnostic(
                       syntaxTree, DiagnosticDescriptor, cancellationToken));
        }
Пример #3
0
        private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
        {
            var diagnostics = RenameTrackingTaggerProvider.GetDiagnosticsAsync(context.Tree, DiagnosticDescriptor, context.CancellationToken).WaitAndGetResult(context.CancellationToken);

            foreach (var diagnostic in diagnostics)
            {
                context.ReportDiagnostic(diagnostic);
            }
        }
Пример #4
0
        public override async Task <ImmutableArray <Diagnostic> > AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
        {
            var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);

            var diagnostic = RenameTrackingTaggerProvider.TryGetDiagnostic(syntaxTree, DiagnosticDescriptor, cancellationToken);

            if (diagnostic is null)
            {
                return(ImmutableArray <Diagnostic> .Empty);
            }

            return(ImmutableArray.Create(diagnostic));
        }
Пример #5
0
        public override Task ComputeRefactoringsAsync(CodeRefactoringContext context)
        {
            var(document, span, cancellationToken) = context;

            var(action, renameSpan) = RenameTrackingTaggerProvider.TryGetCodeAction(
                document, span, _refactorNotifyServices, _undoHistoryRegistry, cancellationToken);

            if (action != null)
            {
                context.RegisterRefactoring(action, renameSpan);
            }

            return(Task.CompletedTask);
        }
        public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var document   = context.Document;
            var diagnostic = context.Diagnostics.Single();

            var action1 = RenameTrackingTaggerProvider.CreateCodeAction(document, diagnostic, _waitIndicator, _refactorNotifyServices, _undoHistoryRegistry, showPreview: false);

            context.RegisterCodeFix(action1, diagnostic);

            var action2 = RenameTrackingTaggerProvider.CreateCodeAction(document, diagnostic, _waitIndicator, _refactorNotifyServices, _undoHistoryRegistry, showPreview: true);

            context.RegisterCodeFix(action2, diagnostic);

            return(SpecializedTasks.EmptyTask);
        }
        public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var document   = context.Document;
            var diagnostic = context.Diagnostics.Single();

            // Ensure rename can still be invoked in this document. We reanalyze the document for
            // diagnostics when rename tracking is manually dismissed, but the existence of our
            // diagnostic may still be cached, so we have to double check before actually providing
            // any fixes.
            if (RenameTrackingTaggerProvider.CanInvokeRename(document))
            {
                var action = RenameTrackingTaggerProvider.CreateCodeAction(document, diagnostic, _refactorNotifyServices, _undoHistoryRegistry);
                context.RegisterCodeFix(action, diagnostic);
            }

            return(Task.CompletedTask);
        }