提交 548770c1 编写于 作者: S Sam Harwell

Pipe through ChecksumAlgorithm from serialization

上级 490dff63
......@@ -5,7 +5,6 @@
#nullable enable
using System.Composition;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
......@@ -40,11 +39,6 @@ internal class EditorTextFactoryService : ITextFactoryService
private static readonly Encoding s_throwingUtf8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
/// <summary>
/// The default algorithm used by <see cref="SourceText"/> is <see cref="SourceHashAlgorithm.Sha1"/>.
/// </summary>
public SourceHashAlgorithm ChecksumAlgorithm => SourceHashAlgorithm.Sha1;
public SourceText CreateText(Stream stream, Encoding? defaultEncoding, CancellationToken cancellationToken = default)
{
// this API is for a case where user wants us to figure out encoding from the given stream.
......
......@@ -49,8 +49,7 @@ private SerializableSourceText DeserializeSerializableSourceText(ObjectReader re
{
cancellationToken.ThrowIfCancellationRequested();
// REVIEW: why IDE services doesnt care about checksumAlgorithm?
_ = (SourceHashAlgorithm)reader.ReadInt32();
var checksumAlgorithm = (SourceHashAlgorithm)reader.ReadInt32();
var encoding = (Encoding)reader.ReadValue();
var kind = (SerializationKinds)reader.ReadInt32();
......@@ -62,7 +61,7 @@ private SerializableSourceText DeserializeSerializableSourceText(ObjectReader re
var offset = reader.ReadInt64();
var size = reader.ReadInt64();
var storage = storage2.AttachTemporaryTextStorage(name, offset, size, encoding, cancellationToken);
var storage = storage2.AttachTemporaryTextStorage(name, offset, size, checksumAlgorithm, encoding, cancellationToken);
if (storage is ITemporaryTextStorageWithName storageWithName)
{
return new SerializableSourceText(storageWithName);
......
......@@ -120,8 +120,8 @@ public TemporaryStorageService(ITextFactoryService textFactory)
public ITemporaryTextStorage CreateTemporaryTextStorage(CancellationToken cancellationToken)
=> new TemporaryTextStorage(this);
public ITemporaryTextStorage AttachTemporaryTextStorage(string storageName, long offset, long size, Encoding? encoding, CancellationToken cancellationToken)
=> new TemporaryTextStorage(this, storageName, offset, size, encoding);
public ITemporaryTextStorage AttachTemporaryTextStorage(string storageName, long offset, long size, SourceHashAlgorithm checksumAlgorithm, Encoding? encoding, CancellationToken cancellationToken)
=> new TemporaryTextStorage(this, storageName, offset, size, checksumAlgorithm, encoding);
public ITemporaryStreamStorage CreateTemporaryStreamStorage(CancellationToken cancellationToken)
=> new TemporaryStreamStorage(this);
......@@ -190,10 +190,10 @@ private sealed class TemporaryTextStorage : ITemporaryTextStorage, ITemporaryTex
public TemporaryTextStorage(TemporaryStorageService service)
=> _service = service;
public TemporaryTextStorage(TemporaryStorageService service, string storageName, long offset, long size, Encoding? encoding)
public TemporaryTextStorage(TemporaryStorageService service, string storageName, long offset, long size, SourceHashAlgorithm checksumAlgorithm, Encoding? encoding)
{
_service = service;
_checksumAlgorithm = service._textFactory.ChecksumAlgorithm;
_checksumAlgorithm = checksumAlgorithm;
_encoding = encoding;
_memoryMappedInfo = new MemoryMappedInfo(storageName, offset, size);
}
......
......@@ -6,6 +6,7 @@
using System.Text;
using System.Threading;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Host
{
......@@ -22,6 +23,6 @@ internal interface ITemporaryStorageService2 : ITemporaryStorageService
/// <summary>
/// Attach to existing <see cref="ITemporaryTextStorage"/> with given name.
/// </summary>
ITemporaryTextStorage AttachTemporaryTextStorage(string storageName, long offset, long size, Encoding? encoding, CancellationToken cancellationToken = default);
ITemporaryTextStorage AttachTemporaryTextStorage(string storageName, long offset, long size, SourceHashAlgorithm checksumAlgorithm, Encoding? encoding, CancellationToken cancellationToken = default);
}
}
......@@ -16,8 +16,6 @@ namespace Microsoft.CodeAnalysis.Host
/// </summary>
internal interface ITextFactoryService : IWorkspaceService
{
SourceHashAlgorithm ChecksumAlgorithm { get; }
/// <summary>
/// Creates <see cref="SourceText"/> from a stream.
/// </summary>
......
......@@ -24,11 +24,6 @@ public TextFactoryService()
{
}
/// <summary>
/// The default algorithm used by <see cref="SourceText"/> is <see cref="SourceHashAlgorithm.Sha1"/>.
/// </summary>
public SourceHashAlgorithm ChecksumAlgorithm => SourceHashAlgorithm.Sha1;
public SourceText CreateText(Stream stream, Encoding? defaultEncoding, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册