本文整理汇总了C#中Microsoft.CodeAnalysis.Document.GetTextChangesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Document.GetTextChangesAsync方法的具体用法?C# Document.GetTextChangesAsync怎么用?C# Document.GetTextChangesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Document
的用法示例。
在下文中一共展示了Document.GetTextChangesAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyDocumentChanges
/// <summary>
/// Update the workspace so that the document with the Id of <paramref name="newDocument"/>
/// has the text of newDocument. If the document is open, then this method will determine a
/// minimal set of changes to apply to the document.
/// </summary>
internal static void ApplyDocumentChanges (this Workspace workspace, Document newDocument, CancellationToken cancellationToken)
{
var oldSolution = workspace.CurrentSolution;
var oldDocument = oldSolution.GetDocument (newDocument.Id);
var changes = newDocument.GetTextChangesAsync (oldDocument, cancellationToken).WaitAndGetResult (cancellationToken);
var newSolution = oldSolution.UpdateDocument (newDocument.Id, changes, cancellationToken);
workspace.TryApplyChanges (newSolution);
}
示例2: AddDocumentMergeChangesAsync
private static async Task<List<TextChange>> AddDocumentMergeChangesAsync(
Document oldDocument,
Document newDocument,
List<TextChange> cumulativeChanges,
List<UnmergedDocumentChanges> unmergedChanges,
LinkedFileGroupSessionInfo groupSessionInfo,
CancellationToken cancellationToken)
{
var unmergedDocumentChanges = new List<TextChange>();
var successfullyMergedChanges = new List<TextChange>();
int cumulativeChangeIndex = 0;
foreach (var change in await newDocument.GetTextChangesAsync(oldDocument).ConfigureAwait(false))
{
while (cumulativeChangeIndex < cumulativeChanges.Count && cumulativeChanges[cumulativeChangeIndex].Span.End < change.Span.Start)
{
// Existing change that does not overlap with the current change in consideration
successfullyMergedChanges.Add(cumulativeChanges[cumulativeChangeIndex]);
cumulativeChangeIndex++;
groupSessionInfo.IsolatedDiffs++;
}
if (cumulativeChangeIndex < cumulativeChanges.Count)
{
var cumulativeChange = cumulativeChanges[cumulativeChangeIndex];
if (!cumulativeChange.Span.IntersectsWith(change.Span))
{
// The current change in consideration does not intersect with any existing change
successfullyMergedChanges.Add(change);
groupSessionInfo.IsolatedDiffs++;
}
else
{
if (change.Span != cumulativeChange.Span || change.NewText != cumulativeChange.NewText)
{
// The current change in consideration overlaps an existing change but
// the changes are not identical.
unmergedDocumentChanges.Add(change);
groupSessionInfo.OverlappingDistinctDiffs++;
if (change.Span == cumulativeChange.Span)
{
groupSessionInfo.OverlappingDistinctDiffsWithSameSpan++;
if (change.NewText.Contains(cumulativeChange.NewText) || cumulativeChange.NewText.Contains(change.NewText))
{
groupSessionInfo.OverlappingDistinctDiffsWithSameSpanAndSubstringRelation++;
}
}
}
else
{
// The current change in consideration is identical to an existing change
successfullyMergedChanges.Add(change);
cumulativeChangeIndex++;
groupSessionInfo.IdenticalDiffs++;
}
}
}
else
{
// The current change in consideration does not intersect with any existing change
successfullyMergedChanges.Add(change);
groupSessionInfo.IsolatedDiffs++;
}
}
while (cumulativeChangeIndex < cumulativeChanges.Count)
{
// Existing change that does not overlap with the current change in consideration
successfullyMergedChanges.Add(cumulativeChanges[cumulativeChangeIndex]);
cumulativeChangeIndex++;
groupSessionInfo.IsolatedDiffs++;
}
if (unmergedDocumentChanges.Any())
{
unmergedChanges.Add(new UnmergedDocumentChanges(
unmergedDocumentChanges.AsEnumerable(),
await oldDocument.GetTextAsync(cancellationToken).ConfigureAwait(false),
oldDocument.Project.Name));
}
return successfullyMergedChanges;
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:88,代码来源:Solution.LinkedFileDiffMergingSession.cs
示例3: TryAddDocumentMergeChangesAsync
/// <summary>
/// Try to merge the changes between <paramref name="newDocument"/> and <paramref name="oldDocument"/> into <paramref name="cumulativeChanges"/>.
/// If there is any conflicting change in <paramref name="newDocument"/> with existing <paramref name="cumulativeChanges"/>, then the original <paramref name="cumulativeChanges"/> are returned.
/// Otherwise, the newly merged changes are returned.
/// </summary>
/// <param name="oldDocument">Base document on which FixAll was invoked.</param>
/// <param name="newDocument">New document with a code fix that is being merged.</param>
/// <param name="cumulativeChanges">Existing merged changes from other batch fixes into which newDocument changes are being merged.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
private static async Task<List<TextChange>> TryAddDocumentMergeChangesAsync(
Document oldDocument,
Document newDocument,
List<TextChange> cumulativeChanges,
CancellationToken cancellationToken)
{
var successfullyMergedChanges = new List<TextChange>();
int cumulativeChangeIndex = 0;
foreach (var change in await newDocument.GetTextChangesAsync(oldDocument, cancellationToken).ConfigureAwait(false))
{
cancellationToken.ThrowIfCancellationRequested();
while (cumulativeChangeIndex < cumulativeChanges.Count && cumulativeChanges[cumulativeChangeIndex].Span.End < change.Span.Start)
{
cancellationToken.ThrowIfCancellationRequested();
// Existing change that does not overlap with the current change in consideration
successfullyMergedChanges.Add(cumulativeChanges[cumulativeChangeIndex]);
cumulativeChangeIndex++;
}
if (cumulativeChangeIndex < cumulativeChanges.Count)
{
var cumulativeChange = cumulativeChanges[cumulativeChangeIndex];
if (!cumulativeChange.Span.IntersectsWith(change.Span))
{
// The current change in consideration does not intersect with any existing change
successfullyMergedChanges.Add(change);
}
else
{
if (change.Span != cumulativeChange.Span || change.NewText != cumulativeChange.NewText)
{
// The current change in consideration overlaps an existing change but
// the changes are not identical.
// Bail out merge efforts and return the original 'cumulativeChanges'.
return cumulativeChanges;
}
else
{
// The current change in consideration is identical to an existing change
successfullyMergedChanges.Add(change);
cumulativeChangeIndex++;
}
}
}
else
{
// The current change in consideration does not intersect with any existing change
successfullyMergedChanges.Add(change);
}
}
while (cumulativeChangeIndex < cumulativeChanges.Count)
{
cancellationToken.ThrowIfCancellationRequested();
// Existing change that does not overlap with the current change in consideration
successfullyMergedChanges.Add(cumulativeChanges[cumulativeChangeIndex]);
cumulativeChangeIndex++;
}
return successfullyMergedChanges;
}
示例4: GetTextChangesAsync
public async Task<IEnumerable<TextChange>> GetTextChangesAsync(Document oldDocument, Document newDocument, CancellationToken cancellationToken)
{
return await newDocument.GetTextChangesAsync(oldDocument, cancellationToken).ConfigureAwait(false);
}