private ImmutableArray <SuggestedActionSet>?GetSuggestedActions( ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, IUIThreadOperationContext?operationContext, CancellationToken cancellationToken) { AssertIsForeground(); using var state = _state.TryAddReference(); if (state is null) { return(null); } if (state.Target.Workspace == null) { return(null); } using (operationContext?.AddScope(allowCancellation: true, description: EditorFeaturesResources.Gathering_Suggestions_Waiting_for_the_solution_to_fully_load)) { // This needs to run under threading context otherwise, we can deadlock on VS var statusService = state.Target.Workspace.Services.GetRequiredService <IWorkspaceStatusService>(); ThreadingContext.JoinableTaskFactory.Run(() => statusService.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 selection = TryGetCodeRefactoringSelection(state, range); Func <string, IDisposable?> addOperationScope = description => operationContext?.AddScope(allowCancellation: true, string.Format(EditorFeaturesResources.Gathering_Suggestions_0, description)); var options = GlobalOptions.GetBlockingCodeActionOptions(document.Project.Language); // We convert the code fixes and refactorings to UnifiedSuggestedActionSets instead of // SuggestedActionSets so that we can share logic between local Roslyn and LSP. var fixesTask = GetCodeFixesAsync( state, supportsFeatureService, requestedActionCategories, workspace, document, range, addOperationScope, CodeActionRequestPriority.None, options, cancellationToken); var refactoringsTask = GetRefactoringsAsync( state, supportsFeatureService, requestedActionCategories, GlobalOptions, workspace, document, selection, addOperationScope, CodeActionRequestPriority.None, options, cancellationToken); Task.WhenAll(fixesTask, refactoringsTask).WaitAndGetResult(cancellationToken); return(ConvertToSuggestedActionSets( state, selection, fixesTask.WaitAndGetResult(cancellationToken), refactoringsTask.WaitAndGetResult(cancellationToken), currentActionCount: 0)); } }