private static async Task <DocumentAnalysisResults> AnalyzeDocumentAsync( Project oldProject, Document newDocument, ActiveStatementsMap activeStatementMap = null, EditAndContinueCapabilities capabilities = EditAndContinueTestHelpers.Net5RuntimeCapabilities) { var analyzer = new CSharpEditAndContinueAnalyzer(); var baseActiveStatements = AsyncLazy.Create(activeStatementMap ?? ActiveStatementsMap.Empty); var lazyCapabilities = AsyncLazy.Create(capabilities); return(await analyzer.AnalyzeDocumentAsync(oldProject, baseActiveStatements, newDocument, ImmutableArray <LinePositionSpan> .Empty, lazyCapabilities, CancellationToken.None)); }
public async Task GetValueAsync() { var count = 0; var lazy = AsyncLazy.Create(async() => { Interlocked.Increment(ref count); await Task.Yield(); return(1); }); var a = lazy.GetValueAsync(); var value = await lazy.GetValueAsync(); Assert.AreEqual(1, value); Assert.AreEqual(1, count); }
private static async Task <ImmutableArray <Project> > GetDependentProjectsWorkerAsync( Solution solution, ISymbol symbol, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var symbolOrigination = GetSymbolOrigination(solution, symbol, cancellationToken); // If we can't find where the symbol came from, we can't determine what projects to search for references to it. if (symbolOrigination.assembly == null) { return(ImmutableArray <Project> .Empty); } // 1) Compute all the dependent projects (submission + non-submission) and their InternalsVisibleTo semantics to the definition project. var visibility = symbol.GetResultantVisibility(); if (visibility == SymbolVisibility.Private) { // For private symbols, we only need the current project (and related submissions). No need to cache // that, just simply compute and return the result. return(GetProjects(solution, await ComputeDependentProjectsAsync(solution, symbolOrigination, visibility, cancellationToken).ConfigureAwait(false))); } // Otherwise, for non-private symbols, we cache the dependent projects for non-private symbols to speed up // future calls. var dependentProjectsMap = s_dependentProjectsCache.GetValue(solution, _ => new DependentProjectMap()); var asyncLazy = dependentProjectsMap.GetOrAdd( new DefinitionProject(symbolOrigination.sourceProject?.Id, symbolOrigination.assembly.Name.ToLower()), _ => AsyncLazy.Create(c => ComputeDependentProjectsAsync(solution, symbolOrigination, visibility, c), cacheResult: true)); var dependentProjects = await asyncLazy.GetValueAsync(cancellationToken).ConfigureAwait(false); // 2) Filter the above computed dependent projects based on symbol visibility. return(GetProjects(solution, visibility == SymbolVisibility.Internal ? dependentProjects.WhereAsArray(dp => dp.HasInternalsAccess) : dependentProjects)); }
// Extract a local function to avoid creating a closure for code path of cache hit. static AsyncLazy <SyntaxContext> GetLazySyntaxContextWithSpeculativeModel(Document document, SharedSyntaxContextsWithSpeculativeModel self) { return(self._cache.GetOrAdd(document, d => AsyncLazy.Create(cancellationToken => CompletionHelper.CreateSyntaxContextWithExistingSpeculativeModelAsync(d, self._position, cancellationToken), cacheResult: true))); }