提交 35c5d3f0 编写于 作者: C Cyrus Najmabadi

Generate compilations on the fly to analyze metadata references.

上级 97e2c11f
......@@ -218,48 +218,52 @@ private async Task UpdateSymbolTreeInfoAsync(Project project, CancellationToken
private async Task UpdateReferencesAync(Project project, CancellationToken cancellationToken)
{
Compilation compilation = null;
foreach (var reference in project.MetadataReferences.OfType<PortableExecutableReference>())
{
compilation = await UpdateReferenceAsync(project, reference, compilation, cancellationToken).ConfigureAwait(false);
await UpdateReferenceAsync(project, reference, cancellationToken).ConfigureAwait(false);
}
}
private async Task<Compilation> UpdateReferenceAsync(
Project project, PortableExecutableReference reference, Compilation compilation, CancellationToken cancellationToken)
private async Task UpdateReferenceAsync(
Project project, PortableExecutableReference reference, CancellationToken cancellationToken)
{
var key = GetReferenceKey(reference);
if (key != null)
if (key == null)
{
DateTime lastWriteTime;
if (!TryGetLastWriteTime(key, out lastWriteTime))
{
// Couldn't get the write time. Just ignore this reference.
return compilation;
}
return;
}
MetadataInfo metadataInfo;
if (_metadataPathToInfo.TryGetValue(key, out metadataInfo) && metadataInfo.TimeStamp == lastWriteTime)
{
// We've already computed and cached the info for this reference.
return compilation;
}
DateTime lastWriteTime;
if (!TryGetLastWriteTime(key, out lastWriteTime))
{
// Couldn't get the write time. Just ignore this reference.
return;
}
compilation = compilation ?? await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var assembly = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol;
if (assembly != null)
{
var info = await SymbolTreeInfo.TryGetInfoForMetadataAssemblyAsync(project.Solution, assembly, reference, loadOnly: false, cancellationToken: cancellationToken).ConfigureAwait(false);
metadataInfo = metadataInfo ?? new MetadataInfo(lastWriteTime, info, new HashSet<ProjectId>());
MetadataInfo metadataInfo;
if (_metadataPathToInfo.TryGetValue(key, out metadataInfo) && metadataInfo.TimeStamp == lastWriteTime)
{
// We've already computed and cached the info for this reference.
return;
}
// Keep track that this dll is referenced by this project.
metadataInfo.ReferencingProjects.Add(project.Id);
var compilationService = project.LanguageServices.GetService<ICompilationFactoryService>();
var compilation = compilationService.CreateCompilation("TempAssembly", compilationService.GetDefaultCompilationOptions())
.WithReferences(reference);
_metadataPathToInfo.AddOrUpdate(key, metadataInfo, (_1, _2) => metadataInfo);
}
var assembly = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol;
if (assembly == null)
{
return;
}
return compilation;
var info = await SymbolTreeInfo.TryGetInfoForMetadataAssemblyAsync(project.Solution, assembly, reference, loadOnly: false, cancellationToken: cancellationToken).ConfigureAwait(false);
metadataInfo = metadataInfo ?? new MetadataInfo(lastWriteTime, info, new HashSet<ProjectId>());
// Keep track that this dll is referenced by this project.
metadataInfo.ReferencingProjects.Add(project.Id);
_metadataPathToInfo.AddOrUpdate(key, metadataInfo, (_1, _2) => metadataInfo);
}
public override void RemoveProject(ProjectId projectId)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册