示例#1
0
        public static async Task<IEnumerable<TaggedText>> GetDescriptionAsync(
            this ISymbol symbol,
            TextDocument document,
            CancellationToken cancellationToken
        )
        {
            if (symbol == null)
            {
                return Enumerable.Empty<TaggedText>();
            }

            var codeProject = document.GetCodeProject();
            var formatter =
                codeProject.LanguageServices.GetService<IDocumentationCommentFormattingService>();
            if (formatter == null)
            {
                return Enumerable.Empty<TaggedText>();
            }

            var symbolDisplayService =
                codeProject.LanguageServices.GetService<ISymbolDisplayService>();
            if (symbolDisplayService == null)
            {
                return Enumerable.Empty<TaggedText>();
            }

            // Any code document will do
            var codeDocument = codeProject.Documents.FirstOrDefault();
            if (codeDocument == null)
            {
                return Enumerable.Empty<TaggedText>();
            }

            var semanticModel = await codeDocument
                .GetSemanticModelAsync(cancellationToken)
                .ConfigureAwait(false);
            if (semanticModel == null)
            {
                return Enumerable.Empty<TaggedText>();
            }

            var quickInfo = await QuickInfoUtilities
                .CreateQuickInfoItemAsync(
                    codeProject.Solution.Workspace,
                    semanticModel,
                    span: default,
示例#2
0
        public static async Task <IEnumerable <TaggedText> > GetDescriptionAsync(this ISymbol symbol, TextDocument document, int offset, CancellationToken cancellationToken)
        {
            if (symbol == null)
            {
                return(Enumerable.Empty <TaggedText>());
            }

            var codeProject = document.GetCodeProject();
            var formatter   = codeProject.LanguageServices.GetService <IDocumentationCommentFormattingService>();

            if (formatter == null)
            {
                return(Enumerable.Empty <TaggedText>());
            }

            // TODO: Should we get this from the code-behind document instead?
            var codeDocument = codeProject.Documents.FirstOrDefault();

            if (codeDocument == null)
            {
                return(Enumerable.Empty <TaggedText>());
            }

            var semanticModel = await codeDocument.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            if (semanticModel == null)
            {
                return(Enumerable.Empty <TaggedText>());
            }

            var textContentBuilder = new List <TaggedText>();

            textContentBuilder.AddRange(symbol.ToDisplayParts(s_descriptionStyle).ToTaggedText());

            var documentation = symbol.GetDocumentationParts(semanticModel, offset, formatter, cancellationToken);

            if (documentation.Any())
            {
                textContentBuilder.AddLineBreak();
                textContentBuilder.AddRange(documentation);
            }
            return(textContentBuilder);
        }