> GetColorSchemeRegistryItemsAsync(CancellationToken arg) => SpecializedTasks.FromResult( _colorSchemes.ToImmutableDictionary( kvp => kvp.Key, kvp => RegistryItemConverter.Convert(kvp.Value) ) );
/// <summary> /// Formats the whitespace in areas of a document corresponding to multiple non-overlapping spans. /// </summary> /// <param name="document">The document to format.</param> /// <param name="spans">The spans of the document's text to format.</param> /// <param name="options">An optional set of formatting options. If these options are not supplied the current set of options from the document's workspace will be used.</param> /// <param name="cancellationToken">An optional cancellation token.</param> /// <returns>The formatted document.</returns> public static Task <Document> FormatAsync(Document document, IEnumerable <TextSpan> spans, OptionSet options = null, CancellationToken cancellationToken = default) { var formattingService = document.GetLanguageService <IFormattingService>(); return(formattingService == null ? SpecializedTasks.FromResult(document) : formattingService.FormatAsync(document, spans, options, cancellationToken)); }
public Task <Compilation> GetCompilationAsync(SolutionState solution, CancellationToken cancellationToken) { if (this.TryGetCompilation(out var compilation)) { // PERF: This is a hot code path and Task<TResult> isn't cheap, // so cache the completed tasks to reduce allocations. We also // need to avoid keeping a strong reference to the Compilation, // so use a ConditionalWeakTable. return(SpecializedTasks.FromResult(compilation)); } else { return(GetCompilationSlowAsync(solution, cancellationToken)); } }
public Task <Compilation> GetCompilationAsync(SolutionState solution, CancellationToken cancellationToken) { if (this.TryGetCompilation(out var compilation)) { // PERF: This is a hot code path and Task<TResult> isn't cheap, // so cache the completed tasks to reduce allocations. We also // need to avoid keeping a strong reference to the Compilation, // so use a ConditionalWeakTable. return(SpecializedTasks.FromResult(compilation)); } else { return(GetOrBuildCompilationInfoAsync(solution, lockGate: true, cancellationToken: cancellationToken) .ContinueWith(t => t.Result.Compilation, cancellationToken, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default)); } }
/// <summary> /// Builds the compilation matching the project state. In the process of building, also /// produce in progress snapshots that can be accessed from other threads. /// </summary> private Task <Compilation> BuildCompilationAsync( Solution solution, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var state = this.ReadState(); // if we already have a compilation, we must be already done! This can happen if two // threads were waiting to build, and we came in after the other succeeded. var compilation = state.FinalCompilation.GetValue(cancellationToken); if (compilation != null) { return(SpecializedTasks.FromResult(compilation)); } compilation = state.Compilation.GetValue(cancellationToken); if (compilation == null) { // this can happen if compilation is already kicked out from the cache. // check whether the state we have support declaration only compilation if (state.DeclarationOnlyCompilation != null) { // we have declaration only compilation. build final one from it. return(FinalizeCompilationAsync(solution, state.DeclarationOnlyCompilation, cancellationToken)); } // We've got nothing. Build it from scratch :( return(BuildCompilationFromScratchAsync(solution, state, cancellationToken)); } else if (state is FullDeclarationState) { // We have a declaration compilation, use it to reconstruct the final compilation return(this.FinalizeCompilationAsync(solution, compilation, cancellationToken)); } else if (state is InProgressState) { // We have an in progress compilation. Build off of that. return(BuildFinalStateFromInProgressStateAsync(solution, state as InProgressState, compilation, cancellationToken)); } else { throw ExceptionUtilities.Unreachable; } }
private Task <ImmutableDictionary <SchemeName, ImmutableArray <RegistryItem> > > GetColorSchemeRegistryItemsAsync(CancellationToken arg) { return(SpecializedTasks.FromResult(_colorSchemes.ToImmutableDictionary(kvp => kvp.Key, kvp => RegistryItemConverter.Convert(kvp.Value)))); }