Пример #1
0
        private void PopulateMapsForFileInputNode(GraphNode inputNode)
        {
            using (_gate.DisposableWait())
            {
                var projectPath = inputNode.Id.GetNestedValueByName <Uri>(CodeGraphNodeIdName.Assembly);
                var filePath    = inputNode.Id.GetNestedValueByName <Uri>(CodeGraphNodeIdName.File);

                if (projectPath == null || filePath == null)
                {
                    return;
                }

                var project = _solution.Projects.FirstOrDefault(
                    p => string.Equals(p.FilePath, projectPath.OriginalString, StringComparison.OrdinalIgnoreCase));
                if (project == null)
                {
                    return;
                }

                _nodeToContextProjectMap.Add(inputNode, project);

                var document = project.Documents.FirstOrDefault(
                    d => string.Equals(d.FilePath, filePath.OriginalString, StringComparison.OrdinalIgnoreCase));
                if (document == null)
                {
                    return;
                }

                _nodeToContextDocumentMap.Add(inputNode, document);
            }
        }
Пример #2
0
        public async Task OnCompilationEventsGeneratedAsync(ImmutableArray <CompilationEvent> compilationEvents, AnalyzerDriver driver, CancellationToken cancellationToken)
        {
            await EnsureAnalyzerActionCountsInitializedAsync(driver, cancellationToken).ConfigureAwait(false);

            using (_gate.DisposableWait(cancellationToken))
            {
                OnCompilationEventsGenerated_NoLock(compilationEvents, filterTreeOpt: null, driver: driver, cancellationToken: cancellationToken);
            }
        }
 internal void HookAutoRestartEvent()
 {
     using (_disposeSemaphore.DisposableWait())
     {
         // hook the event only once per process:
         if (_processExitHandlerStatus == ProcessExitHandlerStatus.Uninitialized)
         {
             Process.Exited           += ProcessExitedHandler;
             _processExitHandlerStatus = ProcessExitHandlerStatus.Hooked;
         }
     }
 }
Пример #4
0
        private void GenerateSimulatedCompilationSourceEvents(
            SyntaxTree tree,
            Compilation compilation,
            Func <SyntaxTree, Compilation, CancellationToken, SemanticModel> getCachedSemanticModel,
            AnalyzerDriver driver,
            CancellationToken cancellationToken)
        {
            using (_gate.DisposableWait(cancellationToken))
            {
                if (_treesWithGeneratedSourceEvents.Contains(tree))
                {
                    return;
                }
            }

            var globalNs          = compilation.Assembly.GlobalNamespace;
            var symbols           = GetDeclaredSymbolsInTree(tree, compilation, getCachedSemanticModel, cancellationToken);
            var compilationEvents = CreateCompilationEventsForTree(symbols.Concat(globalNs), tree, compilation);

            using (_gate.DisposableWait(cancellationToken))
            {
                if (_treesWithGeneratedSourceEvents.Contains(tree))
                {
                    return;
                }

                OnCompilationEventsGenerated_NoLock(compilationEvents, tree, driver, cancellationToken);

                var added = _treesWithGeneratedSourceEvents.Add(tree);
                Debug.Assert(added);
            }
        }
Пример #5
0
        public async Task OnCompilationEventsGeneratedAsync(ImmutableArray <CompilationEvent> compilationEvents, AnalyzerDriver driver, CancellationToken cancellationToken)
        {
            try
            {
                await EnsureAnalyzerActionCountsInitializedAsync(driver, cancellationToken).ConfigureAwait(false);

                using (_gate.DisposableWait(cancellationToken))
                {
                    OnCompilationEventsGenerated_NoLock(compilationEvents, filterTreeOpt: null);
                }
            }
            catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
Пример #6
0
        public async Task OnCompilationEventsGeneratedAsync(
            Func <
                AsyncQueue <CompilationEvent>,
                ImmutableArray <AdditionalText>,
                ImmutableArray <CompilationEvent>
                > getCompilationEvents,
            AsyncQueue <CompilationEvent> eventQueue,
            ImmutableArray <AdditionalText> additionalFiles,
            AnalyzerDriver driver,
            CancellationToken cancellationToken
            )
        {
            try
            {
                await EnsureAnalyzerActionCountsInitializedAsync(driver, cancellationToken)
                .ConfigureAwait(false);

                using (_gate.DisposableWait(cancellationToken))
                {
                    // Defer the call to 'getCompilationEvents' until we know cancellation is no longer possible
                    OnCompilationEventsGenerated_NoLock(
                        getCompilationEvents(eventQueue, additionalFiles)
                        );
                }
            }
            catch (Exception e)
                when(FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
                {
                    throw ExceptionUtilities.Unreachable;
                }
        }
        public void EndSession()
        {
            _session = null;
            _vsFolderWorkspaceService.OnActiveWorkspaceChanged -= OnActiveWorkspaceChangedAsync;
            StopSolutionCrawler();

            // Clear the remote paths on end of session.  Live share handles closing all the files.
            using (s_RemotePathsGate.DisposableWait())
            {
                _remoteWorkspaceRootPaths = ImmutableHashSet <string> .Empty;
                _registeredExternalPaths  = ImmutableHashSet <string> .Empty;
            }
        }
Пример #8
0
            public override void Initialize(AnalysisContext context)
            {
                SemaphoreSlim gate = new SemaphoreSlim(initialCount: registeredActionCounts);

                for (var i = 0; i < registeredActionCounts; i++)
                {
                    context.RegisterSymbolAction(symbolContext =>
                    {
                        using (gate.DisposableWait(symbolContext.CancellationToken))
                        {
                            ReportDiagnosticIfActionInvokedConcurrently(gate, symbolContext);
                        }
                    }, SymbolKind.NamedType);
                }
            }
Пример #9
0
        protected void OnDocumentTextChanged(DocumentId documentId, SourceText newText)
        {
            using (_serializationLock.DisposableWait())
            {
                CheckDocumentIsInCurrentSolution(documentId);

                var oldSolution = this.CurrentDocuments;
                var newSolution = this.SetCurrentDocuments(oldSolution.WithDocumentText(documentId, newText));

                var newDocument = newSolution.GetDocument(documentId);
                this.OnDocumentTextChanged(newDocument);

                DocumentChanged?.Invoke(this, new DocumentEventArgs(newDocument));
            }
        }
Пример #10
0
        public void Shutdown()
        {
            using (_gate.DisposableWait(_cancellationToken))
            {
                if (_client != null)
                {
                    _client.StatusChanged -= OnStatusChanged;
                }

                _connection?.Dispose();

                _client     = null;
                _connection = null;
            }
        }
Пример #11
0
            public override void Shutdown()
            {
                base.Shutdown();

                // stop listening workspace change event
                _service.Workspace.WorkspaceChanged -= OnWorkspaceChanged;

                CancelAndDispose(_globalOperationCancellationSource);

                using (_gate.DisposableWait(CancellationToken.None))
                {
                    // release last snapshot
                    _lastSnapshot?.Dispose();
                    _lastSnapshot = null;
                }
            }