提交 4bf65986 编写于 作者: C CyrusNajmabadi

Get symbol-tree persistence working in OOP.

上级 f9d55112
// 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 System.IO;
using Microsoft.CodeAnalysis.Host.Mef;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Serialization
{
[ExportWorkspaceService(typeof(IAssemblySerializationInfoService), ServiceLayer.Host)]
[Shared]
internal class AssemblySerializationInfoService : IAssemblySerializationInfoService
{
public bool Serializable(Solution solution, string assemblyFilePath)
{
if (assemblyFilePath == null || !File.Exists(assemblyFilePath))
{
return false;
}
// if solution is not from a disk, just create one.
if (solution.FilePath == null || !File.Exists(solution.FilePath))
{
return false;
}
return true;
}
public bool TryGetSerializationPrefix(Solution solution, string assemblyFilePath, out string prefix)
{
prefix = PathUtilities.GetRelativePath(solution.FilePath, assemblyFilePath);
return true;
}
}
}
\ No newline at end of file
//// 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.Host.Mef;
//namespace Microsoft.CodeAnalysis.Serialization
//{
// [ExportWorkspaceService(typeof(IAssemblySerializationInfoService), ServiceLayer.Host), Shared]
// internal class VisualStudioAssemblySerializationInfoService : SimpleAssemblySerializationInfoService
// {
// }
//}
\ No newline at end of file
......@@ -10,6 +10,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Collections;
using Microsoft.CodeAnalysis.Serialization;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Utilities;
using Roslyn.Utilities;
......@@ -132,13 +133,8 @@ private static Metadata GetMetadataNoThrow(PortableExecutableReference reference
CancellationToken cancellationToken)
{
var filePath = reference.FilePath;
var checksum = IOUtilities.PerformIO(() =>
{
using (var stream = File.OpenRead(filePath))
{
return Checksum.Create(stream);
}
}, null);
var serializer = new Serializer(solution.Workspace);
var checksum = serializer.CreateChecksum(reference, cancellationToken);
return LoadOrCreateAsync(
solution,
......
......@@ -85,7 +85,7 @@ internal partial class SymbolTreeInfo
{
// See if we can even use serialization. If not, we'll just have to make the value
// from scratch.
if (checksum == null || ShouldCreateFromScratch(solution, filePath, out var prefix, cancellationToken))
if (checksum == null) // || ShouldCreateFromScratch(solution, filePath, out var prefix, cancellationToken))
{
return loadOnly ? null : create();
}
......@@ -97,7 +97,7 @@ internal partial class SymbolTreeInfo
using (var storage = persistentStorageService.GetStorage(solution, checkBranchId: false))
{
// Get the unique key to identify our data.
var key = PrefixMetadataSymbolTreeInfo + prefix + keySuffix;
var key = PrefixMetadataSymbolTreeInfo + keySuffix;
using (var stream = await storage.ReadStreamAsync(key, cancellationToken).ConfigureAwait(false))
using (var reader = ObjectReader.TryGetReader(stream))
{
......@@ -142,33 +142,33 @@ internal partial class SymbolTreeInfo
return result;
}
private static bool ShouldCreateFromScratch(
Solution solution,
string filePath,
out string prefix,
CancellationToken cancellationToken)
{
prefix = null;
//private static bool ShouldCreateFromScratch(
// Solution solution,
// string filePath,
// out string prefix,
// CancellationToken cancellationToken)
//{
// prefix = null;
var service = solution.Workspace.Services.GetService<IAssemblySerializationInfoService>();
if (service == null)
{
return true;
}
// var service = solution.Workspace.Services.GetService<IAssemblySerializationInfoService>();
// if (service == null)
// {
// return true;
// }
// check whether the assembly that belong to a solution is something we can serialize
if (!service.Serializable(solution, filePath))
{
return true;
}
// // check whether the assembly that belong to a solution is something we can serialize
// if (!service.Serializable(solution, filePath))
// {
// return true;
// }
if (!service.TryGetSerializationPrefix(solution, filePath, out prefix))
{
return true;
}
// if (!service.TryGetSerializationPrefix(solution, filePath, out prefix))
// {
// return true;
// }
return false;
}
// return false;
//}
public void WriteTo(ObjectWriter writer)
{
......
......@@ -4,6 +4,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Collections;
using Microsoft.CodeAnalysis.Serialization;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.FindSymbols
......@@ -28,7 +29,10 @@ private static void FreeSymbolMap(MultiDictionary<string, ISymbol> symbolMap)
Project project, CancellationToken cancellationToken)
{
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var checksum = await project.State.GetChecksumAsync(cancellationToken).ConfigureAwait(false);
var stateChecksums = await project.State.GetStateChecksumsAsync(cancellationToken).ConfigureAwait(false);
var checksum = Checksum.Create("SymbolTree",
new Checksum[] { stateChecksums.Documents.Checksum, stateChecksums.CompilationOptions, stateChecksums.ParseOptions });
return await LoadOrCreateSourceSymbolTreeInfoAsync(
project.Solution, compilation.Assembly, checksum, project.FilePath,
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
//// 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.Host.Mef;
//using System.Composition;
//using System.IO;
//using Microsoft.CodeAnalysis.Host.Mef;
//using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Serialization
{
[ExportWorkspaceService(typeof(IAssemblySerializationInfoService), ServiceLayer.Default)]
[Shared]
internal class AssemblySerializationInfoService : IAssemblySerializationInfoService
{
public bool Serializable(Solution solution, string assemblyFilePath)
{
return false;
}
//namespace Microsoft.CodeAnalysis.Serialization
//{
// [ExportWorkspaceService(typeof(IAssemblySerializationInfoService), ServiceLayer.Default), Shared]
// internal class DefaultAssemblySerializationInfoService : IAssemblySerializationInfoService
// {
// public bool Serializable(Solution solution, string assemblyFilePath)
// {
// return false;
// }
public bool TryGetSerializationPrefix(Solution solution, string assemblyFilePath, out string prefix)
{
prefix = string.Empty;
return false;
}
}
}
// public bool TryGetSerializationPrefix(Solution solution, string assemblyFilePath, out string prefix)
// {
// prefix = string.Empty;
// return false;
// }
// }
// internal class SimpleAssemblySerializationInfoService : IAssemblySerializationInfoService
// {
// public bool Serializable(Solution solution, string assemblyFilePath)
// {
// if (assemblyFilePath == null || !File.Exists(assemblyFilePath))
// {
// return false;
// }
// // if solution is not from a disk, just create one.
// if (solution.FilePath == null || !File.Exists(solution.FilePath))
// {
// return false;
// }
// return true;
// }
// public bool TryGetSerializationPrefix(Solution solution, string assemblyFilePath, out string prefix)
// {
// prefix = PathUtilities.GetRelativePath(solution.FilePath, assemblyFilePath);
// return true;
// }
// }
//}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
//// 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.Host;
//using Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis.Serialization
{
internal interface IAssemblySerializationInfoService : IWorkspaceService
{
bool Serializable(Solution solution, string assemblyFilePath);
bool TryGetSerializationPrefix(Solution solution, string assemblyFilePath, out string prefix);
}
}
//namespace Microsoft.CodeAnalysis.Serialization
//{
// internal interface IAssemblySerializationInfoService : IWorkspaceService
// {
// bool Serializable(Solution solution, string assemblyFilePath);
// bool TryGetSerializationPrefix(Solution solution, string assemblyFilePath, out string prefix);
// }
//}
......@@ -64,6 +64,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Diagnostics\DiagnosticComputer.cs" />
<Compile Include="Services\RemoteAssemblySerializationInfoService.cs" />
<Compile Include="Services\AssetSource.cs" />
<Compile Include="Services\AssetService.cs" />
<Compile Include="Services\AssetStorage.cs" />
......
//// 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.Host.Mef;
//namespace Microsoft.CodeAnalysis.Serialization
//{
// [ExportWorkspaceService(typeof(IAssemblySerializationInfoService), layer: WorkspaceKind.RemoteWorkspace), Shared]
// internal class RemoteAssemblySerializationInfoService : SimpleAssemblySerializationInfoService
// {
// }
//}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册