提交 720f161b 编写于 作者: B brettv

Check Project.SupportsCompilation to prevent NRE. (changeset 1403553)

上级 da4dbf98
......@@ -384,11 +384,6 @@ public bool TryGetCompilation(out Compilation compilation)
/// </summary>
public Task<Compilation> GetCompilationAsync(CancellationToken cancellationToken = default(CancellationToken))
{
if (!this.SupportsCompilation)
{
return Task.FromResult<Compilation>(null);
}
return this.solution.GetCompilationAsync(this.Id, cancellationToken);
}
......
......@@ -1965,9 +1965,16 @@ internal bool TryGetCompilation(ProjectId projectId, out Compilation compilation
&& tracker.TryGetCompilation(out compilation);
}
/// <summary>
/// Returns the compilation for the specified project ID. Can return <code>null</code> when the project
/// does not support compilations.
/// </summary>
internal Task<Compilation> GetCompilationAsync(ProjectId projectId, CancellationToken cancellationToken)
{
return this.GetCompilationTracker(projectId).GetCompilationAsync(this, cancellationToken);
var project = GetProject(projectId);
return project.SupportsCompilation
? this.GetCompilationTracker(projectId).GetCompilationAsync(this, cancellationToken)
: SpecializedTasks.Default<Compilation>();
}
private static readonly ConditionalWeakTable<MetadataReference, ProjectId> metadataReferenceToProjectMap =
......@@ -2074,6 +2081,12 @@ internal async Task<bool> ContainsSymbolsWithNameAsync(ProjectId id, Func<string
// it looks like declaration compilation doesnt exist yet. we have to build full compilation
var compilation = await GetCompilationAsync(id, cancellationToken).ConfigureAwait(false);
if (compilation == null)
{
// some projects don't support compilations (e.g., TypeScript) so there's nothing to check
return false;
}
return compilation.ContainsSymbolsWithName(predicate, filter, cancellationToken);
}
......@@ -2088,6 +2101,12 @@ internal async Task<IEnumerable<Document>> GetDocumentsWithName(ProjectId id, Fu
// it looks like declaration compilation doesnt exist yet. we have to build full compilation
var compilation = await GetCompilationAsync(id, cancellationToken).ConfigureAwait(false);
if (compilation == null)
{
// some projects don't support compilations (e.g., TypeScript) so there's nothing to check
return SpecializedCollections.EmptyEnumerable<Document>();
}
return ConvertTreesToDocuments(
id, compilation.GetSymbolsWithName(predicate, filter, cancellationToken).SelectMany(s => s.DeclaringSyntaxReferences.Select(r => r.SyntaxTree)));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册