提交 249da8f6 编写于 作者: M Manish Vasani

Ensure that we generated a CompilationCompletedEvent for compilations with no...

Ensure that we generated a CompilationCompletedEvent for compilations with no source files (example an empty VSIX projects).
上级 e3840c1f
......@@ -1709,9 +1709,7 @@ private void CompleteTree(SyntaxTree tree)
if (_lazyCompilationUnitCompletedTrees.Count == this.SyntaxTrees.Length)
{
// if that was the last tree, signal the end of compilation
EventQueue.TryEnqueue(new CompilationCompletedEvent(this));
EventQueue.PromiseNotToEnqueue();
EventQueue.TryComplete();
EnsureCompilationCompleted();
}
}
}
......@@ -1950,6 +1948,11 @@ internal ImmutableArray<Diagnostic> GetDiagnostics(CompilationStage stage, bool
cancellationToken.ThrowIfCancellationRequested();
builder.AddRange(GetSourceDeclarationDiagnostics(cancellationToken: cancellationToken));
if (this.EventQueue != null && this.SyntaxTrees.Length == 0)
{
EnsureCompilationCompleted();
}
}
cancellationToken.ThrowIfCancellationRequested();
......
......@@ -6,6 +6,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests
......@@ -287,5 +288,16 @@ private static bool DequeueCompilationEvents(AsyncQueue<CompilationEvent> eventQ
return true;
}
[Fact]
public void TestEventQueueCompletionForEmptyCompilation()
{
var compilation = CreateCompilationWithMscorlib45(SpecializedCollections.EmptyEnumerable<SyntaxTree>()).WithEventQueue(new AsyncQueue<CompilationEvent>());
// Force complete compilation event queue
var unused = compilation.GetDiagnostics();
Assert.True(compilation.EventQueue.IsCompleted);
}
}
}
......@@ -851,6 +851,22 @@ public INamedTypeSymbol GetTypeByMetadataName(string fullyQualifiedMetadataName)
/// </summary>
public abstract ImmutableArray<Diagnostic> GetDiagnostics(CancellationToken cancellationToken = default(CancellationToken));
internal void EnsureCompilationCompleted()
{
Debug.Assert(this.EventQueue != null);
lock (this.EventQueue)
{
if (!this.EventQueue.IsCompleted)
{
// Signal the end of compilation.
EventQueue.TryEnqueue(new CompilationCompletedEvent(this));
EventQueue.PromiseNotToEnqueue();
EventQueue.TryComplete();
}
}
}
internal abstract CommonMessageProvider MessageProvider { get; }
/// <param name="accumulator">Bag to which filtered diagnostics will be added.</param>
......
......@@ -1644,9 +1644,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
If _lazyCompilationUnitCompletedTrees.Count = SyntaxTrees.Length Then
' if that was the last tree, signal the end of compilation
EventQueue.TryEnqueue(New CompilationCompletedEvent(Me))
EventQueue.PromiseNotToEnqueue()
EventQueue.TryComplete()
EnsureCompilationCompleted()
End If
End If
End SyncLock
......@@ -1925,6 +1923,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
builder.AddRange(GetBoundReferenceManager().Diagnostics)
builder.AddRange(SourceAssembly.GetAllDeclarationErrors(cancellationToken))
builder.AddRange(GetClsComplianceDiagnostics(cancellationToken))
If Me.EventQueue IsNot Nothing AndAlso Me.SyntaxTrees.Length = 0 Then
EnsureCompilationCompleted()
End If
End If
' Add method body compilation errors.
......
......@@ -255,5 +255,15 @@ End Namespace
Return True
End Function
<Fact>
Public Sub TestEventQueueCompletionForEmptyCompilation()
Dim compilation = CreateCompilationWithMscorlib45(SpecializedCollections.EmptyEnumerable(Of SyntaxTree)()).WithEventQueue(New AsyncQueue(Of CompilationEvent)())
' Force complete compilation event queue
Dim unused = compilation.GetDiagnostics()
Assert.True(compilation.EventQueue.IsCompleted)
End Sub
End Class
End Namespace
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册