Ejemplo n.º 1
0
            private async Task <Compilation> GetOrBuildDeclarationCompilationAsync(Solution solution, CancellationToken cancellationToken)
            {
                try
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    using (await _buildLock.DisposableWaitAsync(cancellationToken).ConfigureAwait(false))
                    {
                        var state = this.ReadState();

                        // we are already in the final stage. just return it.
                        var compilation = state.FinalCompilation.GetValue(cancellationToken);
                        if (compilation != null)
                        {
                            return(compilation);
                        }

                        compilation = state.Compilation.GetValue(cancellationToken);
                        if (compilation == null)
                        {
                            // let's see whether we have declaration only compilation
                            if (state.DeclarationOnlyCompilation != null)
                            {
                                // okay, move to full declaration state. do this so that declaration only compilation never
                                // realize symbols.
                                var declarationOnlyCompilation = state.DeclarationOnlyCompilation.Clone();
                                this.WriteState(new FullDeclarationState(declarationOnlyCompilation), solution);
                                return(declarationOnlyCompilation);
                            }

                            // We've got nothing.  Build it from scratch :(
                            return(await BuildDeclarationCompilationFromScratchAsync(solution, cancellationToken).ConfigureAwait(false));
                        }
                        else if (state is FullDeclarationState)
                        {
                            // we have full declaration, just use it.
                            return(state.Compilation.GetValue(cancellationToken));
                        }
                        else if (state is InProgressState)
                        {
                            // We have an in progress compilation.  Build off of that.
                            return(await BuildDeclarationCompilationFromInProgressAsync(solution, state as InProgressState, compilation, cancellationToken).ConfigureAwait(false));
                        }
                        else
                        {
                            throw ExceptionUtilities.Unreachable;
                        }
                    }
                }
                catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
Ejemplo n.º 2
0
 private async Task <MSB.Execution.BuildResult> BuildAsync(MSB.Execution.BuildParameters parameters, MSB.Execution.BuildRequestData requestData, CancellationToken cancellationToken)
 {
     // only allow one build to use the default build manager at a time
     using (await s_buildManagerLock.DisposableWaitAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false))
     {
         return(await BuildAsync(MSB.Execution.BuildManager.DefaultBuildManager, parameters, requestData, cancellationToken).ConfigureAwait(continueOnCapturedContext: false));
     }
 }
Ejemplo n.º 3
0
        private async Task PopulateMapsForSymbolInputNodeAsync(GraphNode inputNode)
        {
            using (await _gate.DisposableWaitAsync(_cancellationToken).ConfigureAwait(false))
            {
                var projectId = (ProjectId)inputNode[RoslynGraphProperties.ContextProjectId];
                if (projectId == null)
                {
                    return;
                }

                var project = _solution.GetProject(projectId);
                if (project == null)
                {
                    return;
                }

                _nodeToContextProjectMap.Add(inputNode, project);

                var compilation = await project.GetCompilationAsync(_cancellationToken).ConfigureAwait(false);

                var symbolId = inputNode[RoslynGraphProperties.SymbolId] as SymbolKey;
                var symbol   = symbolId.Resolve(compilation).Symbol;
                if (symbol != null)
                {
                    _nodeToSymbolMap.Add(inputNode, symbol);
                }

                var documentId = (DocumentId)inputNode[RoslynGraphProperties.ContextDocumentId];
                if (documentId != null)
                {
                    var document = project.GetDocument(documentId);
                    if (document != null)
                    {
                        _nodeToContextDocumentMap.Add(inputNode, document);
                    }
                }
            }
        }