未验证 提交 dcc0f24f 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #44274 from CyrusNajmabadi/todoDelete

Ensure we clear out existing todo comments when a user deletes a file.
......@@ -127,7 +127,7 @@ private async Task StartWorkerAsync(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
using var _ = ArrayBuilder<DocumentAndComments>.GetInstance(out var filteredArray);
using var _1 = ArrayBuilder<DocumentAndComments>.GetInstance(out var filteredArray);
AddFilteredInfos(docAndCommentsArray, filteredArray);
foreach (var docAndComments in filteredArray)
......@@ -141,7 +141,14 @@ private async Task StartWorkerAsync(CancellationToken cancellationToken)
// only one thread can be executing ProcessTodoCommentInfosAsync at a time,
// so it's safe to remove/add here.
_documentToInfos[documentId] = newComments;
if (newComments.IsEmpty)
{
_documentToInfos.TryRemove(documentId, out _);
}
else
{
_documentToInfos[documentId] = newComments;
}
// If we have someone listening for updates, and our new items are different from
// our old ones, then notify them of the change.
......@@ -188,15 +195,6 @@ public ImmutableArray<TodoCommentData> GetTodoItems(Workspace workspace, Documen
return SpecializedCollections.EmptyEnumerable<UpdatedEventArgs>();
}
/// <summary>
/// Callback from the OOP service back into us.
/// </summary>
public Task OnDocumentRemovedAsync(DocumentId documentId, CancellationToken cancellationToken)
{
_documentToInfos.TryRemove(documentId, out _);
return Task.CompletedTask;
}
/// <summary>
/// Callback from the OOP service back into us.
/// </summary>
......
......@@ -11,12 +11,10 @@
namespace Microsoft.CodeAnalysis.TodoComments
{
/// <summary>
/// Callback the host (VS) passes to the OOP service to allow it to send batch notifications
/// about todo comments.
/// Callback the host (VS) passes to the OOP service to allow it to send batch notifications about todo comments.
/// </summary>
internal interface ITodoCommentsListener
{
Task OnDocumentRemovedAsync(DocumentId documentId, CancellationToken cancellationToken);
Task ReportTodoCommentDataAsync(DocumentId documentId, ImmutableArray<TodoCommentData> data, CancellationToken cancellationToken);
}
}
......@@ -4,6 +4,7 @@
#nullable enable
using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
......@@ -38,9 +39,10 @@ public override bool NeedsReanalysisOnOptionChanged(object sender, OptionChanged
public override Task RemoveDocumentAsync(DocumentId documentId, CancellationToken cancellationToken)
{
// Just report this back as there being no more comments for this document.
return _endPoint.InvokeAsync(
nameof(ITodoCommentsListener.OnDocumentRemovedAsync),
new object[] { documentId },
nameof(ITodoCommentsListener.ReportTodoCommentDataAsync),
new object[] { documentId, Array.Empty<TodoCommentData>() },
cancellationToken);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册