提交 8e1ec594 编写于 作者: C Cyrus Najmabadi

Tweak

上级 390e7917
......@@ -61,11 +61,16 @@ public override async Task AnalyzeDocumentAsync(Document document, SyntaxNode bo
}
var statusService = document.Project.Solution.Workspace.Services.GetRequiredService<IWorkspaceStatusService>();
// If we're not fully loaded, then we don't want to cache classifications. The classifications we have
// will likely not be accurate. And, if we shutdown after that, we'll have cached incomplete classifications.
var isFullyLoaded = await statusService.IsFullyLoadedAsync(cancellationToken).ConfigureAwait(false);
if (!isFullyLoaded)
return;
await client.TryInvokeAsync<IRemoteSemanticClassificationCacheService>(
document.Project.Solution,
(service, solutionInfo, cancellationToken) => service.CacheSemanticClassificationsAsync(solutionInfo, document.Id, isFullyLoaded, cancellationToken),
(service, solutionInfo, cancellationToken) => service.CacheSemanticClassificationsAsync(solutionInfo, document.Id, cancellationToken),
callbackTarget: null,
cancellationToken).ConfigureAwait(false);
}
......
......@@ -19,7 +19,7 @@ namespace Microsoft.CodeAnalysis.Classification
internal interface IRemoteSemanticClassificationCacheService
{
ValueTask CacheSemanticClassificationsAsync(
PinnedSolutionInfo solutionInfo, DocumentId documentId, bool isFullyLoaded, CancellationToken cancellationToken);
PinnedSolutionInfo solutionInfo, DocumentId documentId, CancellationToken cancellationToken);
/// <summary>
/// Tries to get cached semantic classifications for the specified document and the specified <paramref
......
......@@ -73,17 +73,14 @@ private static async Task<Checksum> GetChecksumAsync(Document document, Cancella
public ValueTask CacheSemanticClassificationsAsync(
PinnedSolutionInfo solutionInfo,
DocumentId documentId,
bool isFullyLoaded,
CancellationToken cancellationToken)
{
return RunServiceAsync(async cancellationToken =>
{
// Once fully loaded, we can clear any of the cached information we stored during load.
if (isFullyLoaded)
{
lock (_cachedData)
_cachedData.Clear();
}
// We only get called to cache classifications once we're fully loaded. At that point there's no need
// for us to keep around any of the data we cached in-memory during the time the solution was loading.
lock (_cachedData)
_cachedData.Clear();
var solution = await GetSolutionAsync(solutionInfo, cancellationToken).ConfigureAwait(false);
var document = solution.GetRequiredDocument(documentId);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册