Esempio n. 1
0
        public static async Task <QuickInfoItem> CreateQuickInfoItemAsync(
            HostSolutionServices services,
            SemanticModel semanticModel,
            TextSpan span,
            ImmutableArray <ISymbol> symbols,
            SupportedPlatformData?supportedPlatforms,
            bool showAwaitReturn,
            NullableFlowState flowState,
            SymbolDescriptionOptions options,
            CancellationToken cancellationToken)
        {
            var descriptionService = services.GetRequiredLanguageService <ISymbolDisplayService>(semanticModel.Language);
            var groups             = await descriptionService.ToDescriptionGroupsAsync(semanticModel, span.Start, symbols, options, cancellationToken).ConfigureAwait(false);

            using var _1 = ArrayBuilder <QuickInfoSection> .GetInstance(out var sections);

            var symbol = symbols.First();

            if (showAwaitReturn)
            {
                // We show a special message if the Task being awaited has no return
                if (symbol is INamedTypeSymbol {
                    SpecialType : SpecialType.System_Void
                })
Esempio n. 2
0
        public static async Task <CompletionDescription> CreateDescriptionAsync(
            HostSolutionServices workspaceServices, SemanticModel semanticModel, int position, ISymbol symbol, int overloadCount, SymbolDescriptionOptions options, SupportedPlatformData?supportedPlatforms, CancellationToken cancellationToken)
        {
            var symbolDisplayService = workspaceServices.GetRequiredLanguageService <ISymbolDisplayService>(semanticModel.Language);
            var formatter            = workspaceServices.GetRequiredLanguageService <IDocumentationCommentFormattingService>(semanticModel.Language);

            // TODO(cyrusn): Figure out a way to cancel this.
            var sections = await symbolDisplayService.ToDescriptionGroupsAsync(semanticModel, position, ImmutableArray.Create(symbol), options, cancellationToken).ConfigureAwait(false);

            if (!sections.ContainsKey(SymbolDescriptionGroups.MainDescription))
            {
                return(CompletionDescription.Empty);
            }

            var textContentBuilder = new List <TaggedText>();

            textContentBuilder.AddRange(sections[SymbolDescriptionGroups.MainDescription]);

            switch (symbol.Kind)
            {
            case SymbolKind.Method:
            case SymbolKind.Property:
            case SymbolKind.NamedType:
                if (overloadCount > 0)
                {
                    var isGeneric = symbol.GetArity() > 0;

                    textContentBuilder.AddSpace();
                    textContentBuilder.AddPunctuation("(");
                    textContentBuilder.AddPunctuation("+");
                    textContentBuilder.AddText(NonBreakingSpaceString + overloadCount.ToString());

                    AddOverloadPart(textContentBuilder, overloadCount, isGeneric);

                    textContentBuilder.AddPunctuation(")");
                }

                break;
            }

            AddDocumentationPart(textContentBuilder, symbol, semanticModel, position, formatter, cancellationToken);

            if (sections.TryGetValue(SymbolDescriptionGroups.AwaitableUsageText, out var parts))
            {
                textContentBuilder.AddRange(parts);
            }

            if (sections.TryGetValue(SymbolDescriptionGroups.StructuralTypes, out parts))
            {
                if (!parts.IsDefaultOrEmpty)
                {
                    textContentBuilder.AddLineBreak();
                    textContentBuilder.AddLineBreak();
                    textContentBuilder.AddRange(parts);
                }
            }

            if (supportedPlatforms != null)
            {
                textContentBuilder.AddLineBreak();
                textContentBuilder.AddRange(supportedPlatforms.ToDisplayParts().ToTaggedText());
            }

            return(CompletionDescription.Create(textContentBuilder.AsImmutable()));
        }