Exemplo n.º 1
0
            public async Task <ISuggestedActionCategorySet> GetSuggestedActionCategoriesAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken)
            {
                var provider = _owner;

                using (var asyncToken = _owner.OperationListener.BeginAsyncOperation(nameof(GetSuggestedActionCategoriesAsync)))
                {
                    var document = range.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
                    using (var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
                    {
                        var linkedToken = linkedTokenSource.Token;

                        var errorTask = Task.Run(
                            () => GetFixLevelAsync(provider, document, range, linkedToken), linkedToken);

                        var selection = await GetSpanAsync(range).ConfigureAwait(false);

                        Task <string> refactoringTask = Task.FromResult((string)null);
                        if (selection != null && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring))
                        {
                            refactoringTask = Task.Run(
                                () => TryGetRefactoringSuggestedActionCategoryAsync(provider, document, selection, linkedToken),
                                linkedToken);
                        }

                        // If we happen to get the result of the error task before the refactoring task,
                        // and that result is non-null, we can just cancel the refactoring task.
                        var result = await errorTask.ConfigureAwait(false) ?? await refactoringTask.ConfigureAwait(false);

                        linkedTokenSource.Cancel();
                        return(result == null
                            ? null
                            : _suggestedActionCategoryRegistry.CreateSuggestedActionCategorySet(result));
                    }
                }
            }
Exemplo n.º 2
0
            public async Task <ISuggestedActionCategorySet> GetSuggestedActionCategoriesAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken)
            {
                if (_workspaceStatusService != null && !await _workspaceStatusService.IsFullyLoadedAsync(cancellationToken).ConfigureAwait(false))
                {
                    // never show light bulb if solution is not fully loaded yet
                    return(null);
                }

                var provider = _owner;

                using (var asyncToken = _owner.OperationListener.BeginAsyncOperation(nameof(GetSuggestedActionCategoriesAsync)))
                {
                    var document = range.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
                    if (document == null)
                    {
                        return(null);
                    }

                    using (var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
                    {
                        var linkedToken = linkedTokenSource.Token;

                        var errorTask = Task.Run(
                            () => GetFixLevelAsync(provider, document, range, linkedToken), linkedToken);

                        var selection = await GetSpanAsync(range, linkedToken).ConfigureAwait(false);

                        var refactoringTask = SpecializedTasks.Default <string>();
                        if (selection != null && requestedActionCategories.Contains(PredefinedSuggestedActionCategoryNames.Refactoring))
                        {
                            refactoringTask = Task.Run(
                                () => TryGetRefactoringSuggestedActionCategoryAsync(provider, document, selection, linkedToken), linkedToken);
                        }

                        // If we happen to get the result of the error task before the refactoring task,
                        // and that result is non-null, we can just cancel the refactoring task.
                        var result = await errorTask.ConfigureAwait(false) ?? await refactoringTask.ConfigureAwait(false);

                        linkedTokenSource.Cancel();

                        return(result == null
                            ? null
                            : _suggestedActionCategoryRegistry.CreateSuggestedActionCategorySet(result));
                    }
                }
            }