未验证 提交 36f90767 编写于 作者: J Jason Malinowski 提交者: GitHub

Merge pull request #27547 from jasonmalinowski/dont-ensure-file-watching-during-load

Only call EnsureSubcription for text loaders when we are actually reading
......@@ -5,6 +5,8 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
......@@ -82,7 +84,7 @@ private class StandardTextDocument : ForegroundThreadAffinitizedObject, IVisualS
// The project system does not tell us the CodePage specified in the proj file, so
// we use null to auto-detect.
_doNotAccessDirectlyLoader = new FileTextLoader(documentKey.Moniker, defaultEncoding: null);
_doNotAccessDirectlyLoader = new FileChangeTrackingTextLoader(_fileChangeTracker, new FileTextLoader(documentKey.Moniker, defaultEncoding: null));
// If we aren't already open in the editor, then we should create a file change notification
if (openTextBuffer == null)
......@@ -135,7 +137,6 @@ public TextLoader Loader
{
get
{
_fileChangeTracker.EnsureSubscription();
return _doNotAccessDirectlyLoader;
}
}
......@@ -237,6 +238,33 @@ public uint GetItemId()
return Project.Hierarchy.TryGetItemId(_itemMoniker);
}
/// <summary>
/// A wrapper for a <see cref="TextLoader"/> that ensures we are watching file contents prior to reading the file.
/// </summary>
private sealed class FileChangeTrackingTextLoader : TextLoader
{
private readonly FileChangeTracker _fileChangeTracker;
private readonly TextLoader _innerTextLoader;
public FileChangeTrackingTextLoader(FileChangeTracker fileChangeTracker, TextLoader innerTextLoader)
{
_fileChangeTracker = fileChangeTracker;
_innerTextLoader = innerTextLoader;
}
public override Task<TextAndVersion> LoadTextAndVersionAsync(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken)
{
_fileChangeTracker.EnsureSubscription();
return _innerTextLoader.LoadTextAndVersionAsync(workspace, documentId, cancellationToken);
}
internal override TextAndVersion LoadTextAndVersionSynchronously(Workspace workspace, DocumentId documentId, CancellationToken cancellationToken)
{
_fileChangeTracker.EnsureSubscription();
return _innerTextLoader.LoadTextAndVersionSynchronously(workspace, documentId, cancellationToken);
}
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册