コード例 #1
0
 public SuggestedActionWithNestedActions(
     SuggestedActionsSourceProvider sourceProvider, Workspace workspace, 
     ITextBuffer subjectBuffer, object provider, 
     CodeAction codeAction, SuggestedActionSet nestedActionSet) 
     : base(sourceProvider, workspace, subjectBuffer, provider, codeAction)
 {
     NestedActionSet = nestedActionSet;
 }
コード例 #2
0
 public CodeRefactoringSuggestedAction(
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     ITextBuffer subjectBuffer,
     CodeRefactoringProvider provider,
     CodeAction codeAction)
     : base(sourceProvider, workspace, subjectBuffer, provider, codeAction)
 {
 }
コード例 #3
0
 private PreviewChangesSuggestedAction(
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     ITextBuffer subjectBuffer,
     object provider,
     PreviewChangesCodeAction codeAction)
     : base(sourceProvider, workspace, subjectBuffer, provider, codeAction)
 {
 }
コード例 #4
0
 public SuggestedActionWithNestedFlavors(
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace, ITextBuffer subjectBuffer,
     object provider, CodeAction codeAction, 
     SuggestedActionSet additionalFlavors = null) 
     : base(sourceProvider, workspace, subjectBuffer, 
            provider, codeAction)
 {
     _additionalFlavors = additionalFlavors;
 }
コード例 #5
0
        internal SuggestedAction(
            IThreadingContext threadingContext,
            SuggestedActionsSourceProvider sourceProvider,
            Workspace workspace,
            ITextBuffer subjectBuffer,
            object provider,
            CodeAction codeAction)
            : base(threadingContext)
        {
            Contract.ThrowIfNull(provider);
            Contract.ThrowIfNull(codeAction);

            SourceProvider = sourceProvider;
            Workspace      = workspace;
            SubjectBuffer  = subjectBuffer;
            Provider       = provider;
            CodeAction     = codeAction;
        }
コード例 #6
0
 public FixAllCodeRefactoringSuggestedAction(
     IThreadingContext threadingContext,
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     Solution originalSolution,
     ITextBuffer subjectBuffer,
     IFixAllState fixAllState,
     CodeAction originalCodeAction)
     : base(threadingContext,
            sourceProvider,
            workspace,
            originalSolution,
            subjectBuffer,
            fixAllState,
            originalCodeAction,
            new FixAllCodeRefactoringCodeAction(fixAllState))
 {
 }
コード例 #7
0
 private PreviewChangesSuggestedAction(
     IThreadingContext threadingContext,
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     ITextBuffer subjectBuffer,
     object provider,
     PreviewChangesCodeAction codeAction
     )
     : base(
         threadingContext,
         sourceProvider,
         workspace,
         subjectBuffer,
         provider,
         codeAction
         )
 {
 }
コード例 #8
0
 public SuggestedActionWithNestedFlavors(
     IThreadingContext threadingContext,
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     Solution originalSolution,
     ITextBuffer subjectBuffer,
     object provider,
     CodeAction codeAction,
     SuggestedActionSet additionalFlavors)
     : base(threadingContext,
            sourceProvider,
            workspace,
            originalSolution,
            subjectBuffer,
            provider,
            codeAction)
 {
     _additionalFlavors = additionalFlavors;
 }
コード例 #9
0
 protected AbstractFixAllSuggestedAction(
     IThreadingContext threadingContext,
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     Solution originalSolution,
     ITextBuffer subjectBuffer,
     IFixAllState fixAllState,
     CodeAction originalCodeAction,
     AbstractFixAllCodeAction fixAllCodeAction)
     : base(threadingContext,
            sourceProvider,
            workspace,
            originalSolution,
            subjectBuffer,
            fixAllState.FixAllProvider,
            fixAllCodeAction)
 {
     OriginalCodeAction = originalCodeAction;
     FixAllState        = fixAllState;
 }
コード例 #10
0
 public SuggestedActionWithNestedActions(
     IThreadingContext threadingContext,
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     ITextBuffer subjectBuffer,
     object provider,
     CodeAction codeAction,
     SuggestedActionSet nestedActionSet
     )
     : this(
         threadingContext,
         sourceProvider,
         workspace,
         subjectBuffer,
         provider,
         codeAction,
         ImmutableArray.Create(nestedActionSet)
         )
 {
 }
コード例 #11
0
            protected SuggestedActionsSource(
                IThreadingContext threadingContext,
                IGlobalOptionService globalOptions,
                SuggestedActionsSourceProvider owner,
                ITextView textView,
                ITextBuffer textBuffer,
                ISuggestedActionCategoryRegistryService suggestedActionCategoryRegistry)
                : base(threadingContext)
            {
                GlobalOptions = globalOptions;

                _suggestedActionCategoryRegistry = suggestedActionCategoryRegistry;
                _state = new ReferenceCountedDisposable <State>(new State(this, owner, textView, textBuffer));

                _state.Target.TextView.Closed += OnTextViewClosed;

                RegisterEventsToWorkspace(_state, _state.Target.Registration.Workspace);

                _state.Target.Registration.WorkspaceChanged += OnWorkspaceChanged;
            }
コード例 #12
0
            protected SuggestedActionsSource(
                IThreadingContext threadingContext,
                SuggestedActionsSourceProvider owner,
                ITextView textView,
                ITextBuffer textBuffer,
                ISuggestedActionCategoryRegistryService suggestedActionCategoryRegistry)
                : base(threadingContext)
            {
                _suggestedActionCategoryRegistry = suggestedActionCategoryRegistry;
                _state = new ReferenceCountedDisposable <State>(new State(this, owner, textView, textBuffer));

                _state.Target.TextView.Closed += OnTextViewClosed;

                var updateSource = (IDiagnosticUpdateSource)owner._diagnosticService;

                updateSource.DiagnosticsUpdated += OnDiagnosticsUpdated;

                RegisterEventsToWorkspace(_state, _state.Target.Registration.Workspace);

                _state.Target.Registration.WorkspaceChanged += OnWorkspaceChanged;
            }
コード例 #13
0
            public Source(SuggestedActionsSourceProvider owner, ITextView textView, ITextBuffer textBuffer)
            {
                _owner = owner;
                _textView = textView;
                _textView.Closed += OnTextViewClosed;

                _subjectBuffer = textBuffer;
                _registration = Workspace.GetWorkspaceRegistration(textBuffer.AsTextContainer());

                _lastSolutionVersionReported = InvalidSolutionVersion;
                var updateSource = (IDiagnosticUpdateSource)_owner._diagnosticService;
                updateSource.DiagnosticsUpdated += OnDiagnosticsUpdated;

                if (_registration.Workspace != null)
                {
                    _workspace = _registration.Workspace;
                    _workspace.DocumentActiveContextChanged += OnActiveContextChanged;
                }

                _registration.WorkspaceChanged += OnWorkspaceChanged;
            }
コード例 #14
0
 public CodeFixSuggestedAction(
     IThreadingContext threadingContext,
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     Solution originalSolution,
     ITextBuffer subjectBuffer,
     CodeFix fix,
     object provider,
     CodeAction action,
     SuggestedActionSet fixAllFlavors)
     : base(threadingContext,
            sourceProvider,
            workspace,
            originalSolution,
            subjectBuffer,
            provider,
            action,
            fixAllFlavors)
 {
     CodeFix = fix;
 }
コード例 #15
0
            public SuggestedActionsSource(SuggestedActionsSourceProvider owner, ITextView textView, ITextBuffer textBuffer)
            {
                _owner            = owner;
                _textView         = textView;
                _textView.Closed += OnTextViewClosed;
                _subjectBuffer    = textBuffer;
                _registration     = Workspace.GetWorkspaceRegistration(textBuffer.AsTextContainer());

                _lastSolutionVersionReported = InvalidSolutionVersion;
                var updateSource = (IDiagnosticUpdateSource)_owner._diagnosticService;

                updateSource.DiagnosticsUpdated += OnDiagnosticsUpdated;

                if (_registration.Workspace != null)
                {
                    _workspace = _registration.Workspace;
                    _workspace.DocumentActiveContextChanged += OnActiveContextChanged;
                }

                _registration.WorkspaceChanged += OnWorkspaceChanged;
            }
コード例 #16
0
ファイル: FixAllSuggestedAction.cs プロジェクト: belav/roslyn
 internal FixAllSuggestedAction(
     IThreadingContext threadingContext,
     SuggestedActionsSourceProvider sourceProvider,
     Workspace workspace,
     ITextBuffer subjectBuffer,
     FixAllState fixAllState,
     Diagnostic originalFixedDiagnostic,
     CodeAction originalCodeAction
     )
     : base(
         threadingContext,
         sourceProvider,
         workspace,
         subjectBuffer,
         fixAllState.FixAllProvider,
         new FixAllCodeAction(fixAllState)
         )
 {
     Diagnostic         = originalFixedDiagnostic;
     OriginalCodeAction = originalCodeAction;
     FixAllState        = fixAllState;
 }
コード例 #17
0
            public SuggestedActionsSource(
                IThreadingContext threadingContext,
                SuggestedActionsSourceProvider owner,
                ITextView textView,
                ITextBuffer textBuffer,
                ISuggestedActionCategoryRegistryService suggestedActionCategoryRegistry)
                : base(threadingContext)
            {
                _owner            = owner;
                _textView         = textView;
                _textView.Closed += OnTextViewClosed;
                _subjectBuffer    = textBuffer;
                _suggestedActionCategoryRegistry = suggestedActionCategoryRegistry;
                _registration = Workspace.GetWorkspaceRegistration(textBuffer.AsTextContainer());

                _lastSolutionVersionReported = InvalidSolutionVersion;
                var updateSource = (IDiagnosticUpdateSource)_owner._diagnosticService;

                updateSource.DiagnosticsUpdated += OnDiagnosticsUpdated;

                RegisterEventsToWorkspace(_registration.Workspace);

                _registration.WorkspaceChanged += OnWorkspaceChanged;
            }
コード例 #18
0
            private SuggestedActionSet?ConvertToSuggestedActionSet(UnifiedSuggestedActionSet?unifiedSuggestedActionSet, SuggestedActionsSourceProvider owner, ITextBuffer subjectBuffer)
            {
                // May be null in cases involving CodeFixSuggestedActions since FixAllFlavors may be null.
                if (unifiedSuggestedActionSet == null)
                {
                    return(null);
                }

                return(new SuggestedActionSet(
                           unifiedSuggestedActionSet.CategoryName,
                           unifiedSuggestedActionSet.Actions.SelectAsArray(set => ConvertToSuggestedAction(set)),
                           unifiedSuggestedActionSet.Title,
                           ConvertToSuggestedActionSetPriority(unifiedSuggestedActionSet.Priority),
                           unifiedSuggestedActionSet.ApplicableToSpan?.ToSpan()));

                // Local functions
                ISuggestedAction ConvertToSuggestedAction(IUnifiedSuggestedAction unifiedSuggestedAction)
                => unifiedSuggestedAction switch
                {
                    UnifiedCodeFixSuggestedAction codeFixAction => new CodeFixSuggestedAction(
                        ThreadingContext, owner, codeFixAction.Workspace, subjectBuffer,
                        codeFixAction.CodeFix, codeFixAction.Provider, codeFixAction.OriginalCodeAction,
                        ConvertToSuggestedActionSet(codeFixAction.FixAllFlavors, owner, subjectBuffer)),
                    UnifiedCodeRefactoringSuggestedAction codeRefactoringAction => new CodeRefactoringSuggestedAction(
                        ThreadingContext, owner, codeRefactoringAction.Workspace, subjectBuffer,
                        codeRefactoringAction.CodeRefactoringProvider, codeRefactoringAction.OriginalCodeAction,
                        ConvertToSuggestedActionSet(codeRefactoringAction.FixAllFlavors, owner, subjectBuffer)),
                    UnifiedFixAllCodeFixSuggestedAction fixAllAction => new FixAllCodeFixSuggestedAction(
                        ThreadingContext, owner, fixAllAction.Workspace, subjectBuffer,
                        fixAllAction.FixAllState, fixAllAction.Diagnostic, fixAllAction.OriginalCodeAction),
                    UnifiedFixAllCodeRefactoringSuggestedAction fixAllCodeRefactoringAction => new FixAllCodeRefactoringSuggestedAction(
                        ThreadingContext, owner, fixAllCodeRefactoringAction.Workspace, subjectBuffer,
                        fixAllCodeRefactoringAction.FixAllState, fixAllCodeRefactoringAction.OriginalCodeAction),
                    UnifiedSuggestedActionWithNestedActions nestedAction => new SuggestedActionWithNestedActions(
                        ThreadingContext, owner, nestedAction.Workspace, subjectBuffer,
                        nestedAction.Provider ?? this, nestedAction.OriginalCodeAction,
                        nestedAction.NestedActionSets.SelectAsArray((s, arg) => ConvertToSuggestedActionSet(s, arg.owner, arg.subjectBuffer), (owner, subjectBuffer))),
                    _ => throw ExceptionUtilities.Unreachable
                };
コード例 #19
0
            public void Dispose()
            {
                if (_owner != null)
                {
                    var updateSource = (IDiagnosticUpdateSource)_owner._diagnosticService;
                    updateSource.DiagnosticsUpdated -= OnDiagnosticsUpdated;
                    _owner = null;
                }

                if (_workspace != null)
                {
                    _workspace.DocumentActiveContextChanged -= OnActiveContextChanged;
                    _workspace = null;
                }

                if (_registration != null)
                {
                    _registration.WorkspaceChanged -= OnWorkspaceChanged;
                    _registration = null;
                }

                if (_textView != null)
                {
                    _textView.Closed -= OnTextViewClosed;
                    _textView = null;
                }

                if (_subjectBuffer != null)
                {
                    _subjectBuffer = null;
                }
            }
コード例 #20
0
            private async Task<bool> HasRefactoringsAsync(
                IDocumentSupportsFeatureService supportsFeatureService,
                ISuggestedActionCategorySet requestedActionCategories,
                SuggestedActionsSourceProvider provider,
                Document document,
                ITextBuffer buffer,
                ITextView view,
                SnapshotSpan range,
                CancellationToken cancellationToken)
            {
                var optionService = document.Project.Solution.Workspace.Services.GetService<IOptionService>();

                if (optionService.GetOption(EditorComponentOnOffOptions.CodeRefactorings) &&
                    provider._codeRefactoringService != null &&
                    supportsFeatureService.SupportsRefactorings(document) &&
                    requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring))
                {
                    TextSpan? selection = null;
                    if (IsForeground())
                    {
                        // This operation needs to happen on UI thread because it needs to access textView.Selection.
                        selection = TryGetCodeRefactoringSelection(buffer, view, range);
                    }
                    else
                    {
                        await InvokeBelowInputPriority(() =>
                        {
                            // This operation needs to happen on UI thread because it needs to access textView.Selection.
                            selection = TryGetCodeRefactoringSelection(buffer, view, range);
                        }).ConfigureAwait(false);
                    }

                    if (!selection.HasValue)
                    {
                        // this is here to fail test and see why it is failed.
                        Trace.WriteLine("given range is not current");
                        return false;
                    }

                    return await Task.Run(
                        async () => await provider._codeRefactoringService.HasRefactoringsAsync(
                            document, selection.Value, cancellationToken).ConfigureAwait(false),
                        cancellationToken).ConfigureAwait(false);
                }

                return false;
            }
コード例 #21
0
            private async Task<bool> HasFixesAsync(
                IDocumentSupportsFeatureService supportsFeatureService,
                ISuggestedActionCategorySet requestedActionCategories,
                SuggestedActionsSourceProvider provider,
                Document document, SnapshotSpan range,
                CancellationToken cancellationToken)
            {
                if (provider._codeFixService != null && supportsFeatureService.SupportsCodeFixes(document) &&
                    requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.CodeFix))
                {
                    // We only consider suppressions if lightbulb is asking for everything.
                    // If the light bulb is only asking for code fixes, then we don't consider suppressions.
                    var considerSuppressionFixes = requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Any);
                    var result = await Task.Run(
                        async () => await provider._codeFixService.GetFirstDiagnosticWithFixAsync(
                            document, range.Span.ToTextSpan(), considerSuppressionFixes, cancellationToken).ConfigureAwait(false),
                        cancellationToken).ConfigureAwait(false);

                    if (result.HasFix)
                    {
                        Logger.Log(FunctionId.SuggestedActions_HasSuggestedActionsAsync);
                        return true;
                    }

                    if (result.PartialResult)
                    {
                        // reset solution version number so that we can raise suggested action changed event
                        Volatile.Write(ref _lastSolutionVersionReported, InvalidSolutionVersion);
                        return false;
                    }
                }

                return false;
            }
コード例 #22
0
            private async Task<bool> HasRefactoringsAsync(
                IDocumentSupportsFeatureService supportsFeatureService,
                ISuggestedActionCategorySet requestedActionCategories,
                SuggestedActionsSourceProvider provider,
                Document document,
                ITextBuffer buffer,
                ITextView view,
                SnapshotSpan range,
                CancellationToken cancellationToken)
            {
                if (!requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring))
                {
                    // See if we should still show the light bulb, even if we weren't explicitly 
                    // asked for refactorings.  We'll show the lightbulb if we're currently
                    // flighting the "Refactoring" A/B test, or if a special option is set
                    // enabling this internally.

                    var workspace = document.Project.Solution.Workspace;
                    var experimentationService = workspace.Services.GetService<IExperimentationService>();
                    if (!experimentationService.IsExperimentEnabled("Refactoring") &&
                        !workspace.Options.GetOption(EditorComponentOnOffOptions.ShowCodeRefactoringsWhenQueriedForCodeFixes))
                    {
                        return false;
                    }
                }

                if (document.Project.Solution.Options.GetOption(EditorComponentOnOffOptions.CodeRefactorings) &&
                    provider._codeRefactoringService != null &&
                    supportsFeatureService.SupportsRefactorings(document))
                {
                    TextSpan? selection = null;
                    if (IsForeground())
                    {
                        // This operation needs to happen on UI thread because it needs to access textView.Selection.
                        selection = TryGetCodeRefactoringSelection(buffer, view, range);
                    }
                    else
                    {
                        await InvokeBelowInputPriority(() =>
                        {
                            // This operation needs to happen on UI thread because it needs to access textView.Selection.
                            selection = TryGetCodeRefactoringSelection(buffer, view, range);
                        }).ConfigureAwait(false);
                    }

                    if (!selection.HasValue)
                    {
                        // this is here to fail test and see why it is failed.
                        Trace.WriteLine("given range is not current");
                        return false;
                    }

                    return await Task.Run(
                        () => provider._codeRefactoringService.HasRefactoringsAsync(
                            document, selection.Value, cancellationToken),
                        cancellationToken).ConfigureAwait(false);
                }

                return false;
            }