未验证 提交 0bcb70c3 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #30868 from sharwell/content-type

Update ITextBufferCloneService
......@@ -618,7 +618,7 @@ private static async Task<IEnumerable<TextChange>> GetTextChangesFromTextDiffere
foreach (var replacement in relevantReplacements)
{
var buffer = snapshotSpanToClone.HasValue ? textBufferCloneService.Clone(snapshotSpanToClone.Value) : _textBufferFactoryService.CreateTextBuffer(preMergeDocumentTextString, contentType);
var buffer = snapshotSpanToClone.HasValue ? textBufferCloneService.CloneWithUnknownContentType(snapshotSpanToClone.Value) : _textBufferFactoryService.CreateTextBuffer(preMergeDocumentTextString, contentType);
var trackingSpan = buffer.CurrentSnapshot.CreateTrackingSpan(replacement.NewSpan.ToSpan(), SpanTrackingMode.EdgeExclusive, TrackingFidelityMode.Forward);
using (var edit = _subjectBuffer.CreateEdit(EditOptions.None, null, s_calculateMergedSpansEditTag))
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.Editor
{
internal static class ContentTypeNames
{
public const string CSharpContentType = "CSharp";
public const string CSharpSignatureHelpContentType = "CSharp Signature Help";
public const string RoslynContentType = "Roslyn Languages";
public const string VisualBasicContentType = "Basic";
public const string VisualBasicSignatureHelpContentType = "Basic Signature Help";
public const string XamlContentType = "XAML";
public const string JavaScriptContentTypeName = "JavaScript";
public const string TypeScriptContentTypeName = "TypeScript";
}
}
using System.Runtime.CompilerServices;
// Microsoft.CodeAnalysis.Editor.ContentTypeNames has been moved to Microsoft.CodeAnalysis.Editor.Text.dll
[assembly: TypeForwardedTo(typeof(Microsoft.CodeAnalysis.Editor.ContentTypeNames))]
......@@ -28,9 +28,9 @@ public void GetBufferTextFromTextContainerDoesNotThrow()
bufferMock.SetupGet(x => x.CurrentSnapshot).Returns(textSnapshotMock.Object);
bufferMock.SetupGet(x => x.Properties).Returns(new VisualStudio.Utilities.PropertyCollection());
var textContainer = Text.Extensions.TextBufferContainer.From(bufferMock.Object);
var textContainer = CodeAnalysis.Text.Extensions.TextBufferContainer.From(bufferMock.Object);
Text.Extensions.GetTextBuffer(textContainer);
CodeAnalysis.Text.Extensions.GetTextBuffer(textContainer);
}
}
}
......@@ -140,9 +140,14 @@ private void TestCreateTextInferredEncoding(byte[] bytes, Encoding defaultEncodi
private class FakeTextBufferCloneService : ITextBufferCloneService
{
public ITextBuffer Clone(SnapshotSpan span) => throw new NotImplementedException();
public ITextBuffer CloneWithUnknownContentType(SnapshotSpan span) => throw new NotImplementedException();
public ITextBuffer CloneWithUnknownContentType(ITextImage textImage) => throw new NotImplementedException();
public ITextBuffer CloneWithRoslynContentType(SourceText sourceText) => throw new NotImplementedException();
public ITextBuffer Clone(SourceText sourceText, IContentType contentType) => throw new NotImplementedException();
public ITextBuffer Clone(ITextImage textImage) => throw new NotImplementedException();
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.Editor
{
internal static class ContentTypeNames
{
public const string CSharpContentType = "CSharp";
public const string CSharpSignatureHelpContentType = "CSharp Signature Help";
public const string RoslynContentType = "Roslyn Languages";
public const string VisualBasicContentType = "Basic";
public const string VisualBasicSignatureHelpContentType = "Basic Signature Help";
public const string XamlContentType = "XAML";
public const string JavaScriptContentTypeName = "JavaScript";
public const string TypeScriptContentTypeName = "TypeScript";
}
}
......@@ -211,7 +211,7 @@ public override SourceText WithChanges(IEnumerable<TextChange> changes)
}
// otherwise, create a new cloned snapshot
var buffer = factory.Clone(TextImage);
var buffer = factory.CloneWithUnknownContentType(TextImage);
var baseSnapshot = buffer.CurrentSnapshot;
// apply the change to the buffer
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Host;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Utilities;
namespace Microsoft.CodeAnalysis.Text
{
internal interface ITextBufferCloneService : IWorkspaceService
{
ITextBuffer Clone(SnapshotSpan span);
ITextBuffer Clone(ITextImage textImage);
/// <summary>
/// get new <see cref="ITextBuffer"/> from <see cref="SnapshotSpan"/> with <see cref="IContentTypeRegistryService.UnknownContentType"/>
///
/// it is explicitly marked with unknown content type so that it can't be used with editor directly
/// </summary>
ITextBuffer CloneWithUnknownContentType(SnapshotSpan span);
/// <summary>
/// get new <see cref="ITextBuffer"/> from <see cref="ITextImage"/> with <see cref="IContentTypeRegistryService.UnknownContentType"/>
///
/// it is explicitly marked with unknown content type so that it can't be used with editor directly
/// </summary>
ITextBuffer CloneWithUnknownContentType(ITextImage textImage);
/// <summary>
/// get new <see cref="ITextBuffer"/> from <see cref="SourceText"/> with <see cref="ContentTypeNames.RoslynContentType"/>
/// </summary>
ITextBuffer CloneWithRoslynContentType(SourceText sourceText);
/// <summary>
/// get new <see cref="ITextBuffer"/> from <see cref="SourceText"/> with <see cref="IContentType"/>
/// </summary>
ITextBuffer Clone(SourceText sourceText, IContentType contentType);
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Text;
......@@ -30,20 +31,42 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
private class TextBufferCloneService : ITextBufferCloneService
{
private readonly ITextBufferFactoryService3 _textBufferFactoryService;
private readonly IContentType _roslynContentType;
private readonly IContentType _unknownContentType;
[ImportingConstructor]
public TextBufferCloneService(ITextBufferFactoryService3 textBufferFactoryService, IContentTypeRegistryService contentTypeRegistryService)
{
_textBufferFactoryService = textBufferFactoryService;
_roslynContentType = contentTypeRegistryService.GetContentType(ContentTypeNames.RoslynContentType);
_unknownContentType = contentTypeRegistryService.UnknownContentType;
}
public ITextBuffer Clone(SnapshotSpan span)
public ITextBuffer CloneWithUnknownContentType(SnapshotSpan span)
=> _textBufferFactoryService.CreateTextBuffer(span, _unknownContentType);
public ITextBuffer Clone(ITextImage textImage)
=> _textBufferFactoryService.CreateTextBuffer(textImage, _unknownContentType);
public ITextBuffer CloneWithUnknownContentType(ITextImage textImage)
=> Clone(textImage, _unknownContentType);
public ITextBuffer CloneWithRoslynContentType(SourceText sourceText)
=> Clone(sourceText, _roslynContentType);
public ITextBuffer Clone(SourceText sourceText, IContentType contentType)
{
// see whether we can do it cheaply
var textImage = sourceText.TryFindCorrespondingEditorTextImage();
if (textImage != null)
{
return Clone(textImage, contentType);
}
// we can't, so do it more expensive way
return _textBufferFactoryService.CreateTextBuffer(sourceText.ToString(), contentType);
}
private ITextBuffer Clone(ITextImage textImage, IContentType contentType)
=> _textBufferFactoryService.CreateTextBuffer(textImage, contentType);
}
}
}
......@@ -33,6 +33,8 @@
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.EditorFeatures" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.EditorFeatures.Wpf" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.EditorFeatures" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.CSharp.Repl" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.InteractiveServices" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.CSharp" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.VisualBasic" />
......@@ -41,6 +43,7 @@
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.InteractiveEditorFeatures" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.VisualBasic.InteractiveEditorFeatures" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.TypeScript.EditorFeatures" Key="$(TypeScriptKey)" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.Implementation" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.TypeScript" Key="$(TypeScriptKey)" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.Remote" Key="$(RemoteLanguageServiceKey)" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.Remote.15.7" Key="$(RemoteLanguageServiceKey)" />
......@@ -48,6 +51,8 @@
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.Remote.CSharp" Key="$(RemoteLanguageServiceKey)" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.Remote.CSharp.15.7" Key="$(RemoteLanguageServiceKey)" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.Remote.CSharp.15.8" Key="$(RemoteLanguageServiceKey)" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.Xaml" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.VisualBasic.Repl" />
<InternalsVisibleTo Include="FSharp.Editor" Key="$(FSharpKey)" />
<InternalsVisibleTo Include="FSharp.LanguageService" Key="$(FSharpKey)" />
<!-- The rest are for test purposes only. -->
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册