未验证 提交 686e478a 编写于 作者: I Ivan Basov 提交者: GitHub

completion leaking cancellation exception (#38526)

* completion leaking cancellation exception

* code review feedback

* feedback addressed

* fixing more merge conflicts

* Update CommitManager.cs
上级 64a37600
......@@ -164,16 +164,13 @@ internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager
// Commit with completion service assumes that null is provided is case of invoke. VS provides '\0' in the case.
var commitChar = typeChar == '\0' ? null : (char?)typeChar;
var commitBehavior = Commit(
return Commit(
triggerDocument, completionService, session.TextView, subjectBuffer,
roslynItem, completionListSpan, commitChar, triggerLocation.Snapshot, serviceRules,
filterText, cancellationToken);
_recentItemsManager.MakeMostRecentItem(roslynItem.FilterText);
return new AsyncCompletionData.CommitResult(isHandled: true, commitBehavior);
}
private AsyncCompletionData.CommitBehavior Commit(
private AsyncCompletionData.CommitResult Commit(
Document document,
CompletionService completionService,
ITextView view,
......@@ -193,22 +190,37 @@ internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager
{
// We are on the wrong thread.
FatalError.ReportWithoutCrash(new InvalidOperationException("Subject buffer did not provide Edit Access"));
return AsyncCompletionData.CommitBehavior.None;
return new AsyncCompletionData.CommitResult(isHandled: true, AsyncCompletionData.CommitBehavior.None);
}
if (subjectBuffer.EditInProgress)
{
FatalError.ReportWithoutCrash(new InvalidOperationException("Subject buffer is editing by someone else."));
return AsyncCompletionData.CommitBehavior.None;
return new AsyncCompletionData.CommitResult(isHandled: true, AsyncCompletionData.CommitBehavior.None);
}
CompletionChange change;
// We met an issue when external code threw an OperationCanceledException and the cancellationToken is not cancelled.
// Catching this scenario for further investigations.
// See https://github.com/dotnet/roslyn/issues/38455.
try
{
change = completionService.GetChangeAsync(document, roslynItem, completionListSpan, commitCharacter, cancellationToken).WaitAndGetResult(cancellationToken);
}
catch (OperationCanceledException e) when (e.CancellationToken != cancellationToken && FatalError.ReportWithoutCrash(e))
{
return CommitResultUnhandled;
}
cancellationToken.ThrowIfCancellationRequested();
if (GetCompletionProvider(completionService, roslynItem) is ICustomCommitCompletionProvider provider)
{
provider.Commit(roslynItem, view, subjectBuffer, triggerSnapshot, commitCharacter);
return AsyncCompletionData.CommitBehavior.None;
return new AsyncCompletionData.CommitResult(isHandled: true, AsyncCompletionData.CommitBehavior.None);
}
var change = completionService.GetChangeAsync(document, roslynItem, completionListSpan, commitCharacter, cancellationToken).WaitAndGetResult(cancellationToken);
var textChange = change.TextChange;
var triggerSnapshotSpan = new SnapshotSpan(triggerSnapshot, textChange.Span.ToSpan());
var mappedSpan = triggerSnapshotSpan.TranslateTo(subjectBuffer.CurrentSnapshot, SpanTrackingMode.EdgeInclusive);
......@@ -267,17 +279,19 @@ internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager
}
}
_recentItemsManager.MakeMostRecentItem(roslynItem.FilterText);
if (includesCommitCharacter)
{
return AsyncCompletionData.CommitBehavior.SuppressFurtherTypeCharCommandHandlers;
return new AsyncCompletionData.CommitResult(isHandled: true, AsyncCompletionData.CommitBehavior.SuppressFurtherTypeCharCommandHandlers);
}
if (commitCharacter == '\n' && SendEnterThroughToEditor(rules, roslynItem, filterText))
{
return AsyncCompletionData.CommitBehavior.RaiseFurtherReturnKeyAndTabKeyCommandHandlers;
return new AsyncCompletionData.CommitResult(isHandled: true, AsyncCompletionData.CommitBehavior.RaiseFurtherReturnKeyAndTabKeyCommandHandlers);
}
return AsyncCompletionData.CommitBehavior.None;
return new AsyncCompletionData.CommitResult(isHandled: true, AsyncCompletionData.CommitBehavior.None);
}
internal static bool IsCommitCharacter(CompletionRules completionRules, CompletionItem item, char ch, string textTypedSoFar)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册