public override Task <CompletionDescription> GetDescriptionAsync(Document document, CompletionItem item, CancellationToken cancellationToken)
        {
            if (!item.Properties.TryGetValue(DescriptionKey, out var description))
            {
                return(SpecializedTasks.Default <CompletionDescription>());
            }

            return(Task.FromResult(CompletionDescription.Create(
                                       ImmutableArray.Create(new TaggedText(TextTags.Text, description)))));
        }
        public static Task <RemoteHostClient> TryGetRemoteHostClientAsync(
            this Workspace workspace, Option <bool> featureOption, CancellationToken cancellationToken)
        {
            if (!workspace.IsOutOfProcessEnabled(featureOption))
            {
                return(SpecializedTasks.Default <RemoteHostClient>());
            }

            return(workspace.TryGetRemoteHostClientAsync(cancellationToken));
        }
Esempio n. 3
0
        private Task OnSettingChangedAsync(object sender, PropertyChangedEventArgs args)
        {
            IOption option;

            if (this.StorageKeyToOptionMap.TryGetValue(args.PropertyName, out option))
            {
                this.SetChangedOption(_optionService, option, LanguageName);
            }

            return(SpecializedTasks.Default <object>());
        }
Esempio n. 4
0
        public static Task <OptionSet> GetDocumentOptionSetAsync(this AnalyzerOptions analyzerOptions, SyntaxTree syntaxTree, CancellationToken cancellationToken)
        {
            var workspaceAnalyzerOptions = analyzerOptions as WorkspaceAnalyzerOptions;

            if (workspaceAnalyzerOptions == null)
            {
                return(SpecializedTasks.Default <OptionSet>());
            }

            return(workspaceAnalyzerOptions.GetDocumentOptionSetAsync(syntaxTree, cancellationToken));
        }
Esempio n. 5
0
        public static Task <RemoteHostClient?> TryGetClientAsync(Workspace workspace, CancellationToken cancellationToken)
        {
            var service = workspace.Services.GetService <IRemoteHostClientService>();

            if (service == null)
            {
                return(SpecializedTasks.Default <RemoteHostClient?>());
            }

            return(service.TryGetRemoteHostClientAsync(cancellationToken));
        }
Esempio n. 6
0
        public Task <string> GetSnippetExpansionNoteForCompletionItemAsync(CompletionItem completionItem, Workspace workspace)
        {
            var insertionText = completionItem.CompletionProvider.GetTextChange(completionItem, '\t').NewText;

            var snippetInfoService = workspace.Services.GetLanguageServices(GetLanguageName()).GetService <ISnippetInfoService>();

            if (snippetInfoService != null && snippetInfoService.SnippetShortcutExists_NonBlocking(insertionText))
            {
                return(Task.FromResult(string.Format(FeaturesResources.NoteTabTwiceToInsertTheSnippet, insertionText)));
            }

            return(SpecializedTasks.Default <string>());
        }
        public Task <Document> ImplementAbstractClassAsync(Document document, SemanticModel model, SyntaxNode node, CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.Refactoring_ImplementAbstractClass, cancellationToken))
            {
                var state = State.Generate(this, document, model, node, cancellationToken);
                if (state == null)
                {
                    return(SpecializedTasks.Default <Document>());
                }

                return(new Editor(document, model, state).GetEditAsync(cancellationToken));
            }
        }
Esempio n. 8
0
        public override Task <object?> HandleRequestAsync(
            LSP.DidCloseTextDocumentParams request,
            RequestContext context,
            CancellationToken cancellationToken
            )
        {
            // GetTextDocumentIdentifier returns null to avoid creating the solution, so the queue is not able to log the uri.
            context.TraceInformation($"didClose for {request.TextDocument.Uri}");

            context.StopTracking(request.TextDocument.Uri);

            return(SpecializedTasks.Default <object>());
        }
Esempio n. 9
0
 private static Task <CompletionItemGroup> GetGroupAsync(
     ICompletionProvider provider,
     Document documentOpt,
     SourceText text,
     int position,
     CompletionTriggerInfo triggerInfo,
     CancellationToken cancellationToken)
 {
     return(provider is ITextCompletionProvider
         ? Task.FromResult(((ITextCompletionProvider)provider).GetGroup(text, position, triggerInfo, cancellationToken))
         : documentOpt != null
             ? provider.GetGroupAsync(documentOpt, position, triggerInfo, cancellationToken)
             : SpecializedTasks.Default <CompletionItemGroup>());
 }
Esempio n. 10
0
 public Task <RemoteHostClient> CreateAsync(Workspace workspace, CancellationToken cancellationToken)
 {
     try
     {
         // this is the point where we can create different kind of remote host client in future (cloud or etc)
         return(ServiceHubRemoteHostClient.CreateAsync(workspace, cancellationToken));
     }
     catch
     {
         // currently there is so many moving parts that cause, in some branch/drop,
         // service hub not to work. in such places (ex, Jenkins), rather than crashing VS
         // right away, let VS run without service hub enabled.
         return(SpecializedTasks.Default <RemoteHostClient>());
     }
 }
Esempio n. 11
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));
                    }
                }
            }
Esempio n. 12
0
            protected override Task <IEnumerable <SymbolDisplayPart> > GetInitializerSourcePartsAsync(
                ISymbol symbol)
            {
                // Actually check for C# symbol types here.
                if (symbol is IParameterSymbol)
                {
                    return(GetInitializerSourcePartsAsync((IParameterSymbol)symbol));
                }
                else if (symbol is ILocalSymbol)
                {
                    return(GetInitializerSourcePartsAsync((ILocalSymbol)symbol));
                }
                else if (symbol is IFieldSymbol)
                {
                    return(GetInitializerSourcePartsAsync((IFieldSymbol)symbol));
                }

                return(SpecializedTasks.Default <IEnumerable <SymbolDisplayPart> >());
            }
Esempio n. 13
0
            public Task <RemoteHostClient> GetRemoteHostClientAsync(CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();

                Task <RemoteHostClient> instance;

                lock (_gate)
                {
                    instance = _instanceTask;
                }

                if (instance == null)
                {
                    // service is in shutdown mode or not enabled
                    return(SpecializedTasks.Default <RemoteHostClient>());
                }

                return(instance);
            }
Esempio n. 14
0
        protected override Task <SyntaxNode> GetNewRoot(
            SyntaxNode root,
            SyntaxNode oldNode,
            SemanticModel semanticModel,
            Diagnostic diagnostic,
            Document document,
            CancellationToken cancellationToken)
        {
            var expression = oldNode as ExpressionSyntax;

            if (expression == null)
            {
                return(SpecializedTasks.Default <SyntaxNode>());
            }

            switch (diagnostic.Id)
            {
            case CS4014:
                return(Task.FromResult(root.ReplaceNode(oldNode, ConvertToAwaitExpression(expression))));

            case CS4016:
                if (!DoesExpressionReturnTask(expression, semanticModel))
                {
                    return(SpecializedTasks.Default <SyntaxNode>());
                }

                return(Task.FromResult(root.ReplaceNode(oldNode, ConvertToAwaitExpression(expression))));

            case CS0029:
                if (!DoesExpressionReturnGenericTaskWhoseArgumentsMatchLeftSide(expression, semanticModel, document.Project, cancellationToken))
                {
                    return(SpecializedTasks.Default <SyntaxNode>());
                }

                return(Task.FromResult(root.ReplaceNode(oldNode, ConvertToAwaitExpression(expression))));

            default:
                return(SpecializedTasks.Default <SyntaxNode>());
            }
        }