private static async Task <IntentSource?> ConvertToIntelliCodeResultAsync( IntentProcessorResult processorResult, Document originalDocument, Document currentDocument, CancellationToken cancellationToken) { var newSolution = processorResult.Solution; // Merge linked file changes so all linked files have the same text changes. newSolution = await newSolution.WithMergedLinkedFileChangesAsync(originalDocument.Project.Solution, cancellationToken : cancellationToken).ConfigureAwait(false); // For now we only support changes to the current document. Everything else is dropped. var changedDocument = newSolution.GetRequiredDocument(currentDocument.Id); var textDiffService = newSolution.Workspace.Services.GetRequiredService <IDocumentTextDifferencingService>(); // Compute changes against the current version of the document. var textDiffs = await textDiffService.GetTextChangesAsync(currentDocument, changedDocument, cancellationToken).ConfigureAwait(false); if (textDiffs.IsEmpty) { return(null); } return(new IntentSource(processorResult.Title, textDiffs, processorResult.ActionName)); }
private static async Task <IntentSource?> ConvertToIntelliCodeResultAsync( IntentProcessorResult processorResult, Document originalDocument, Document currentDocument, CancellationToken cancellationToken) { var newSolution = processorResult.Solution; // Merge linked file changes so all linked files have the same text changes. newSolution = await newSolution.WithMergedLinkedFileChangesAsync(originalDocument.Project.Solution, cancellationToken : cancellationToken).ConfigureAwait(false); using var _ = PooledDictionary <DocumentId, ImmutableArray <TextChange> > .GetInstance(out var results); foreach (var changedDocumentId in processorResult.ChangedDocuments) { // Calculate the text changes by comparing the solution with intent applied to the current solution (not to be confused with the original solution, the one prior to intent detection). var docChanges = await GetTextChangesForDocumentAsync(newSolution, currentDocument.Project.Solution, changedDocumentId, cancellationToken).ConfigureAwait(false); if (docChanges != null) { results[changedDocumentId] = docChanges.Value; } } return(new IntentSource(processorResult.Title, results[originalDocument.Id], processorResult.ActionName, results.ToImmutableDictionary())); }