private static async Task <ImmutableArray <UnifiedSuggestedActionSet>?> GetActionSetsAsync( Document document, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, IThreadingContext threadingContext, LSP.Range selection, CancellationToken cancellationToken) { var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var textSpan = ProtocolConversions.RangeToTextSpan(selection, text); // The logic to filter code actions requires the UI thread await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var codeFixes = UnifiedSuggestedActionsSource.GetFilterAndOrderCodeFixes_MustBeCalledFromUIThread( document.Project.Solution.Workspace, codeFixService, document, textSpan, includeSuppressionFixes: true, isBlocking: false, addOperationScope: _ => null, cancellationToken); var codeRefactorings = UnifiedSuggestedActionsSource.GetFilterAndOrderCodeRefactorings_MustBeCalledFromUIThread( document.Project.Solution.Workspace, codeRefactoringService, document, textSpan, isBlocking: false, addOperationScope: _ => null, filterOutsideSelection: false, cancellationToken); var actionSets = UnifiedSuggestedActionsSource.FilterAndOrderActionSets(codeFixes, codeRefactorings, textSpan); return(actionSets); }
public IEnumerable <SuggestedActionSet>?GetSuggestedActions( ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, IUIThreadOperationContext?operationContext, CancellationToken cancellationToken) { AssertIsForeground(); if (IsDisposed) { return(null); } if (_workspaceStatusService != null) { using (operationContext?.AddScope(allowCancellation: true, description: EditorFeaturesWpfResources.Gathering_Suggestions_Waiting_for_the_solution_to_fully_load)) { // This needs to run under threading context otherwise, we can deadlock on VS ThreadingContext.JoinableTaskFactory.Run(() => _workspaceStatusService.WaitUntilFullyLoadedAsync(cancellationToken)); } } using (Logger.LogBlock(FunctionId.SuggestedActions_GetSuggestedActions, cancellationToken)) { var document = range.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document == null) { // this is here to fail test and see why it is failed. Trace.WriteLine("given range is not current"); return(null); } var workspace = document.Project.Solution.Workspace; var supportsFeatureService = workspace.Services.GetRequiredService <ITextBufferSupportsFeatureService>(); var selectionOpt = TryGetCodeRefactoringSelection(range); Func <string, IDisposable?> addOperationScope = description => operationContext?.AddScope(allowCancellation: true, string.Format(EditorFeaturesWpfResources.Gathering_Suggestions_0, description)); // We convert the code fixes and refactorings to UnifiedSuggestedActionSets instead of // SuggestedActionSets so that we can share logic between local Roslyn and LSP. var fixes = GetCodeFixes( supportsFeatureService, requestedActionCategories, workspace, document, range, addOperationScope, cancellationToken); var refactorings = GetRefactorings( supportsFeatureService, requestedActionCategories, workspace, document, selectionOpt, addOperationScope, cancellationToken); var filteredSets = UnifiedSuggestedActionsSource.FilterAndOrderActionSets(fixes, refactorings, selectionOpt); if (!filteredSets.HasValue) { return(null); } return(filteredSets.Value.Select(s => ConvertToSuggestedActionSet(s)).WhereNotNull()); } }
protected ImmutableArray <SuggestedActionSet> ConvertToSuggestedActionSets( ReferenceCountedDisposable <State> state, TextSpan?selection, ImmutableArray <UnifiedSuggestedActionSet> fixes, ImmutableArray <UnifiedSuggestedActionSet> refactorings, int currentActionCount) { var filteredSets = UnifiedSuggestedActionsSource.FilterAndOrderActionSets(fixes, refactorings, selection, currentActionCount); return(filteredSets.Select(s => ConvertToSuggestedActionSet(s, state.Target.Owner, state.Target.SubjectBuffer)).WhereNotNull().ToImmutableArray()); }
private static async Task <ImmutableArray <UnifiedSuggestedActionSet>?> GetActionSetsAsync( Document document, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, LSP.Range selection, CancellationToken cancellationToken) { var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var textSpan = ProtocolConversions.RangeToTextSpan(selection, text); var codeFixes = await UnifiedSuggestedActionsSource.GetFilterAndOrderCodeFixesAsync( document.Project.Solution.Workspace, codeFixService, document, textSpan, includeSuppressionFixes : true, isBlocking : false, addOperationScope : _ => null, cancellationToken).ConfigureAwait(false); var codeRefactorings = await UnifiedSuggestedActionsSource.GetFilterAndOrderCodeRefactoringsAsync( document.Project.Solution.Workspace, codeRefactoringService, document, textSpan, isBlocking : false, addOperationScope : _ => null, filterOutsideSelection : false, cancellationToken).ConfigureAwait(false); var actionSets = UnifiedSuggestedActionsSource.FilterAndOrderActionSets(codeFixes, codeRefactorings, textSpan); return(actionSets); }