Exemplo n.º 1
0
        public override async Task ProvideCompletionsAsync(CompletionContext context)
        {
            var document          = context.Document;
            var position          = context.Position;
            var cancellationToken = context.CancellationToken;
            var semanticModel     = await document.ReuseExistingSpeculativeModelAsync(position, cancellationToken).ConfigureAwait(false);

            var workspace     = document.Project.Solution.Workspace;
            var syntaxContext = CSharpSyntaxContext.CreateContext(workspace, semanticModel, position, cancellationToken);

            if (!syntaxContext.IsAwaitKeywordContext(position))
            {
                return;
            }

            var method = syntaxContext.TargetToken.GetAncestor(node => node.IsAsyncSupportingFunctionSyntax());
            var shouldMakeContainerAsync = method is not null && !method.GetModifiers().Any(SyntaxKind.AsyncKeyword);
            var completionItem           = CommonCompletionItem.Create(
                displayText: SyntaxFacts.GetText(SyntaxKind.AwaitKeyword),
                displayTextSuffix: "",
                rules: CompletionItemRules.Default,
                Glyph.Keyword,
                description: RecommendedKeyword.CreateDisplayParts(SyntaxFacts.GetText(SyntaxKind.AwaitKeyword), string.Empty),
                inlineDescription: shouldMakeContainerAsync ? CSharpFeaturesResources.Make_container_async : null,
                isComplexTextEdit: shouldMakeContainerAsync);

            context.AddItem(completionItem);
        }
Exemplo n.º 2
0
 public static ImmutableArray <SymbolDisplayPart> CreateRecommendedKeywordDisplayParts(
     string keyword,
     string toolTip
     ) => RecommendedKeyword.CreateDisplayParts(keyword, toolTip);