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