Beispiel #1
0
        private void UpdateEventsMap_NoLock(CompilationEvent compilationEvent, bool add)
        {
            var symbolEvent = compilationEvent as SymbolDeclaredCompilationEvent;

            if (symbolEvent != null)
            {
                // Add/remove symbol events.
                // Any diagnostics request for a tree should trigger symbol and syntax node analysis for symbols with at least one declaring reference in the tree.
                foreach (var location in symbolEvent.Symbol.Locations)
                {
                    if (location.SourceTree != null)
                    {
                        if (add)
                        {
                            AddPendingSourceEvent_NoLock(location.SourceTree, compilationEvent);
                        }
                        else
                        {
                            RemovePendingSourceEvent_NoLock(location.SourceTree, compilationEvent);
                        }
                    }
                }
            }
            else
            {
                // Add/remove compilation unit completed events.
                var compilationUnitCompletedEvent = compilationEvent as CompilationUnitCompletedEvent;
                if (compilationUnitCompletedEvent != null)
                {
                    var tree = compilationUnitCompletedEvent.SemanticModel.SyntaxTree;
                    if (add)
                    {
                        AddPendingSourceEvent_NoLock(tree, compilationEvent);
                    }
                    else
                    {
                        RemovePendingSourceEvent_NoLock(tree, compilationEvent);
                    }
                }
                else if (compilationEvent is CompilationStartedEvent || compilationEvent is CompilationCompletedEvent)
                {
                    // Add/remove compilation events.
                    if (add)
                    {
                        _pendingNonSourceEvents.Add(compilationEvent);
                    }
                    else
                    {
                        _pendingNonSourceEvents.Remove(compilationEvent);
                    }
                }
                else
                {
                    throw new InvalidOperationException("Unexpected compilation event of type " + compilationEvent.GetType().Name);
                }
            }
        }
Beispiel #2
0
        private void ProcessEventCore(CompilationEvent e, AnalysisScope analysisScope, AnalysisState analysisStateOpt, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var symbolEvent = e as SymbolDeclaredCompilationEvent;
            if (symbolEvent != null)
            {
                ProcessSymbolDeclared(symbolEvent, analysisScope, analysisStateOpt, cancellationToken);
                return;
            }

            var completedEvent = e as CompilationUnitCompletedEvent;
            if (completedEvent != null)
            {
                ProcessCompilationUnitCompleted(completedEvent, analysisScope, analysisStateOpt, cancellationToken);
                return;
            }

            var endEvent = e as CompilationCompletedEvent;
            if (endEvent != null)
            {
                ProcessCompilationCompleted(endEvent, analysisScope, analysisStateOpt, cancellationToken);
                return;
            }

            var startedEvent = e as CompilationStartedEvent;
            if (startedEvent != null)
            {
                ProcessCompilationStarted(startedEvent, analysisScope, analysisStateOpt, cancellationToken);
                return;
            }

            throw new InvalidOperationException("Unexpected compilation event of type " + e.GetType().Name);
        }
Beispiel #3
0
        private async Task ProcessEventAsync(CompilationEvent e, CancellationToken cancellationToken)
        {
            var symbolEvent = e as SymbolDeclaredCompilationEvent;

            if (symbolEvent != null)
            {
                await ProcessSymbolDeclaredAsync(symbolEvent, cancellationToken).ConfigureAwait(false);

                return;
            }

            var completedEvent = e as CompilationUnitCompletedEvent;

            if (completedEvent != null)
            {
                await ProcessCompilationUnitCompleted(completedEvent, cancellationToken).ConfigureAwait(false);

                return;
            }

            var endEvent = e as CompilationCompletedEvent;

            if (endEvent != null)
            {
                await ProcessCompilationCompletedAsync(endEvent, cancellationToken).ConfigureAwait(false);

                return;
            }

            if (e is CompilationStartedEvent)
            {
                // Ignore CompilationStartedEvent.
                return;
            }

            throw new InvalidOperationException("Unexpected compilation event of type " + e.GetType().Name);
        }
Beispiel #4
0
        private void UpdateEventsMap_NoLock(CompilationEvent compilationEvent, bool add)
        {
            switch (compilationEvent)
            {
            case SymbolDeclaredCompilationEvent symbolEvent:
                // Add/remove symbol events.
                // Any diagnostics request for a tree should trigger symbol and syntax node analysis for symbols with at least one declaring reference in the tree.
                foreach (var location in symbolEvent.Symbol.Locations)
                {
                    if (location.SourceTree != null)
                    {
                        if (add)
                        {
                            AddPendingSourceEvent_NoLock(location.SourceTree, compilationEvent);
                        }
                        else
                        {
                            RemovePendingSourceEvent_NoLock(location.SourceTree, compilationEvent);
                        }
                    }
                }

                break;

            case CompilationUnitCompletedEvent compilationUnitCompletedEvent:
                // Add/remove compilation unit completed events.
                var tree = compilationUnitCompletedEvent.CompilationUnit;
                if (add)
                {
                    AddPendingSourceEvent_NoLock(tree, compilationEvent);
                }
                else
                {
                    RemovePendingSourceEvent_NoLock(tree, compilationEvent);
                }

                break;

            case CompilationStartedEvent:
                compilationStartedOrCompletedEventCommon(compilationEvent, add);
                break;

            case CompilationCompletedEvent:
                compilationStartedOrCompletedEventCommon(compilationEvent, add);
                if (!add)
                {
                    _semanticModelProvider.ClearCache(compilationEvent.Compilation);
                }

                break;

            default:
                throw new InvalidOperationException("Unexpected compilation event of type " + compilationEvent.GetType().Name);
            }

            return;

            void compilationStartedOrCompletedEventCommon(CompilationEvent compilationEvent, bool add)
            {
                Debug.Assert(compilationEvent is CompilationStartedEvent || compilationEvent is CompilationCompletedEvent);

                if (add)
                {
                    _pendingNonSourceEvents.Add(compilationEvent);
                }
                else
                {
                    _pendingNonSourceEvents.Remove(compilationEvent);
                }
            }
        }
Beispiel #5
0
 private void UpdateEventsMap_NoLock(CompilationEvent compilationEvent, bool add)
 {
     var symbolEvent = compilationEvent as SymbolDeclaredCompilationEvent;
     if (symbolEvent != null)
     {
         // Add/remove symbol events.
         // Any diagnostics request for a tree should trigger symbol and syntax node analysis for symbols with at least one declaring reference in the tree.
         foreach (var location in symbolEvent.Symbol.Locations)
         {
             if (location.SourceTree != null)
             {
                 if (add)
                 {
                     AddPendingSourceEvent_NoLock(location.SourceTree, compilationEvent);
                 }
                 else
                 {
                     RemovePendingSourceEvent_NoLock(location.SourceTree, compilationEvent);
                 }
             }
         }
     }
     else
     {
         // Add/remove compilation unit completed events.
         var compilationUnitCompletedEvent = compilationEvent as CompilationUnitCompletedEvent;
         if (compilationUnitCompletedEvent != null)
         {
             var tree = compilationUnitCompletedEvent.SemanticModel.SyntaxTree;
             if (add)
             {
                 AddPendingSourceEvent_NoLock(tree, compilationEvent);
             }
             else
             {
                 RemovePendingSourceEvent_NoLock(tree, compilationEvent);
             }
         }
         else if (compilationEvent is CompilationStartedEvent || compilationEvent is CompilationCompletedEvent)
         {
             // Add/remove compilation events.
             if (add)
             {
                 _pendingNonSourceEvents.Add(compilationEvent);
             }
             else
             {
                 _pendingNonSourceEvents.Remove(compilationEvent);
             }
         }
         else
         {
             throw new InvalidOperationException("Unexpected compilation event of type " + compilationEvent.GetType().Name);
         }
     }
 }
        private async Task ProcessEventAsync(CompilationEvent e, CancellationToken cancellationToken)
        {
            var symbolEvent = e as SymbolDeclaredCompilationEvent;
            if (symbolEvent != null)
            {
                await ProcessSymbolDeclared(symbolEvent, cancellationToken).ConfigureAwait(false);
                return;
            }

            var completedEvent = e as CompilationUnitCompletedEvent;
            if (completedEvent != null)
            {
                await ProcessCompilationUnitCompleted(completedEvent, cancellationToken).ConfigureAwait(false);
                return;
            }

            var endEvent = e as CompilationCompletedEvent;
            if (endEvent != null)
            {
                await ProcessCompilationCompletedAsync(endEvent, cancellationToken).ConfigureAwait(false);
                return;
            }

            throw new InvalidOperationException("Unexpected compilation event of type " + e.GetType().Name);
        }
Beispiel #7
0
        private async Task ProcessEvent(CompilationEvent e, CancellationToken cancellationToken)
        {
            var symbolEvent = e as CompilationEvent.SymbolDeclared;

            if (symbolEvent != null)
            {
                await ProcessSymbolDeclared(symbolEvent, cancellationToken);

                return;
            }

            var completedEvent = e as CompilationEvent.CompilationUnitCompleted;

            if (completedEvent != null)
            {
                await ProcessCompilationUnitCompleted(completedEvent, cancellationToken);

                return;
            }

            var endEvent = e as CompilationEvent.CompilationCompleted;

            if (endEvent != null)
            {
                await ProcessCompilationCompleted(endEvent, cancellationToken);

                return;
            }

            throw new InvalidOperationException("Unexpected compilation event of type " + e.GetType().Name);
        }
        private Task ProcessEventCoreAsync(CompilationEvent e, CancellationToken cancellationToken)
        {
            var symbolEvent = e as SymbolDeclaredCompilationEvent;
            if (symbolEvent != null)
            {
                return ProcessSymbolDeclaredAsync(symbolEvent, cancellationToken);
            }

            var completedEvent = e as CompilationUnitCompletedEvent;
            if (completedEvent != null)
            {
                return ProcessCompilationUnitCompletedAsync(completedEvent, cancellationToken);
            }

            var endEvent = e as CompilationCompletedEvent;
            if (endEvent != null)
            {
                return ProcessCompilationCompletedAsync(endEvent, cancellationToken);
            }

            if (e is CompilationStartedEvent)
            {
                // Ignore CompilationStartedEvent.
                return null;
            }

            throw new InvalidOperationException("Unexpected compilation event of type " + e.GetType().Name);
        }