public SolutionPreviewResult GetPreviews( Workspace workspace, ImmutableArray <CodeActionOperation> operations, CancellationToken cancellationToken) { if (operations.IsDefaultOrEmpty) { return(null); } SolutionPreviewResult currentResult = null; foreach (var op in operations) { cancellationToken.ThrowIfCancellationRequested(); var applyChanges = op as ApplyChangesOperation; if (applyChanges != null) { var oldSolution = workspace.CurrentSolution; var newSolution = applyChanges.ChangedSolution.WithMergedLinkedFileChangesAsync(oldSolution, cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken); var preview = _previewService.GetSolutionPreviews( oldSolution, newSolution, cancellationToken); if (preview != null && !preview.IsEmpty) { currentResult = SolutionPreviewResult.Merge(currentResult, preview); continue; } } var previewOp = op as PreviewOperation; if (previewOp != null) { currentResult = SolutionPreviewResult.Merge(currentResult, new SolutionPreviewResult(new SolutionPreviewItem( projectId: null, documentId: null, lazyPreview: c => previewOp.GetPreviewAsync(c)))); continue; } var title = op.Title; if (title != null) { currentResult = SolutionPreviewResult.Merge(currentResult, new SolutionPreviewResult(new SolutionPreviewItem( projectId: null, documentId: null, text: title))); continue; } } return(currentResult); }
public async Task <SolutionPreviewResult?> GetPreviewsAsync( Workspace workspace, ImmutableArray <CodeActionOperation> operations, CancellationToken cancellationToken) { if (operations.IsDefaultOrEmpty) { return(null); } SolutionPreviewResult?currentResult = null; foreach (var op in operations) { cancellationToken.ThrowIfCancellationRequested(); if (op is ApplyChangesOperation applyChanges) { var oldSolution = workspace.CurrentSolution; var newSolution = await applyChanges.ChangedSolution.WithMergedLinkedFileChangesAsync( oldSolution, cancellationToken : cancellationToken).ConfigureAwait(false); var preview = _previewService.GetSolutionPreviews( oldSolution, newSolution, cancellationToken); if (preview != null && !preview.IsEmpty) { currentResult = SolutionPreviewResult.Merge(currentResult, preview); continue; } } if (op is PreviewOperation previewOp) { currentResult = SolutionPreviewResult.Merge(currentResult, new SolutionPreviewResult(ThreadingContext, new SolutionPreviewItem( projectId: null, documentId: null, lazyPreview: c => previewOp.GetPreviewAsync(c)))); continue; } var title = op.Title; if (title != null) { currentResult = SolutionPreviewResult.Merge(currentResult, new SolutionPreviewResult(ThreadingContext, new SolutionPreviewItem( projectId: null, documentId: null, text: title))); continue; } } return(currentResult); }