Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Threading;

namespace Microsoft.AspNetCore.Razor.LanguageServer;

Expand All @@ -11,7 +14,37 @@ internal partial class ProjectConfigurationStateSynchronizer

internal sealed class TestAccessor(ProjectConfigurationStateSynchronizer instance)
{
public Task WaitUntilCurrentBatchCompletesAsync()
=> instance._workQueue.WaitUntilCurrentBatchCompletesAsync();
public Task WaitForProjectUpdatesToDrainAsync(CancellationToken cancellationToken)
{
return Task.Run(async () =>
{
while (UpdatesRemaining() > 0)
{
await Task.Yield();
}

int UpdatesRemaining()
{
lock (instance._projectUpdates)
{
var count = instance._projectUpdates.Count;

if (count > 0)
{
foreach (var (_, updateItem) in instance._projectUpdates)
{
if (updateItem.Task is null || updateItem.Task.IsCompleted)
{
count--;
}
}
}

return count;
}
}
},
cancellationToken);
}
}
}
Loading