未验证 提交 79ae6bcf 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #26339 from sharwell/use-clone-service

Use ITextBufferCloneService if available in AsText
......@@ -37,7 +37,10 @@ internal static TextLine AsTextLine(this ITextSnapshotLine line)
=> line.Snapshot.AsText().Lines[line.LineNumber];
public static SourceText AsText(this ITextSnapshot textSnapshot)
=> SnapshotSourceText.From(textBufferCloneServiceOpt: null, textSnapshot);
{
textSnapshot.TextBuffer.Properties.TryGetProperty<ITextBufferCloneService>(typeof(ITextBufferCloneService), out var textBufferCloneServiceOpt);
return SnapshotSourceText.From(textBufferCloneServiceOpt, textSnapshot);
}
internal static SourceText AsRoslynText(this ITextSnapshot textSnapshot, ITextBufferCloneService textBufferCloneServiceOpt, Encoding encoding)
=> new SnapshotSourceText.ClosedSnapshotSourceText(textBufferCloneServiceOpt, ((ITextSnapshot2)textSnapshot).TextImage, encoding);
......
......@@ -23,6 +23,7 @@
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Projection;
using Roslyn.Utilities;
using VSLangProj;
using VSLangProj140;
......@@ -39,6 +40,7 @@ internal abstract partial class VisualStudioWorkspaceImpl : VisualStudioWorkspac
private const string AppCodeFolderName = "App_Code";
private readonly ITextBufferFactoryService _textBufferFactoryService;
private readonly IProjectionBufferFactoryService _projectionBufferFactoryService;
private readonly ITextBufferCloneService _textBufferCloneService;
// document worker coordinator
......@@ -66,7 +68,9 @@ public VisualStudioWorkspaceImpl(ExportProvider exportProvider)
{
_textBufferCloneService = exportProvider.GetExportedValue<ITextBufferCloneService>();
_textBufferFactoryService = exportProvider.GetExportedValue<ITextBufferFactoryService>();
_projectionBufferFactoryService = exportProvider.GetExportedValue<IProjectionBufferFactoryService>();
_textBufferFactoryService.TextBufferCreated += AddTextBufferCloneServiceToBuffer;
_projectionBufferFactoryService.ProjectionBufferCreated += AddTextBufferCloneServiceToBuffer;
exportProvider.GetExportedValue<PrimaryWorkspace>().Register(this);
}
......@@ -1138,6 +1142,7 @@ protected override void Dispose(bool finalize)
if (!finalize)
{
_textBufferFactoryService.TextBufferCreated -= AddTextBufferCloneServiceToBuffer;
_projectionBufferFactoryService.ProjectionBufferCreated -= AddTextBufferCloneServiceToBuffer;
}
// workspace is going away. unregister this workspace from work coordinator
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册