public SuggestedActionWithNestedActions( SuggestedActionsSourceProvider sourceProvider, Workspace workspace, ITextBuffer subjectBuffer, object provider, CodeAction codeAction, SuggestedActionSet nestedActionSet) : base(sourceProvider, workspace, subjectBuffer, provider, codeAction) { NestedActionSet = nestedActionSet; }
public CodeRefactoringSuggestedAction( SuggestedActionsSourceProvider sourceProvider, Workspace workspace, ITextBuffer subjectBuffer, CodeRefactoringProvider provider, CodeAction codeAction) : base(sourceProvider, workspace, subjectBuffer, provider, codeAction) { }
private PreviewChangesSuggestedAction( SuggestedActionsSourceProvider sourceProvider, Workspace workspace, ITextBuffer subjectBuffer, object provider, PreviewChangesCodeAction codeAction) : base(sourceProvider, workspace, subjectBuffer, provider, codeAction) { }
public SuggestedActionWithNestedFlavors( SuggestedActionsSourceProvider sourceProvider, Workspace workspace, ITextBuffer subjectBuffer, object provider, CodeAction codeAction, SuggestedActionSet additionalFlavors = null) : base(sourceProvider, workspace, subjectBuffer, provider, codeAction) { _additionalFlavors = additionalFlavors; }
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; }
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)) { }
private PreviewChangesSuggestedAction( IThreadingContext threadingContext, SuggestedActionsSourceProvider sourceProvider, Workspace workspace, ITextBuffer subjectBuffer, object provider, PreviewChangesCodeAction codeAction ) : base( threadingContext, sourceProvider, workspace, subjectBuffer, provider, codeAction ) { }
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; }
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; }
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) ) { }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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 };
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; } }
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; }
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; }
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; }