示例#1
0
        public override async Task <TooltipInformation> CreateTooltipInformation(bool smartWrap, CancellationToken cancelToken)
        {
            var description = await Task.Run(() => completionService.GetDescriptionAsync(doc, CompletionItem)).ConfigureAwait(false);

            var markup      = new StringBuilder();
            var theme       = SyntaxHighlightingService.GetIdeFittingTheme(DefaultSourceEditorOptions.Instance.GetEditorTheme());
            var taggedParts = description.TaggedParts;
            int i           = 0;

            while (i < taggedParts.Length)
            {
                if (taggedParts [i].Tag == "LineBreak")
                {
                    break;
                }
                i++;
            }
            if (i + 1 >= taggedParts.Length)
            {
                markup.AppendTaggedText(theme, taggedParts);
            }
            else
            {
                markup.AppendTaggedText(theme, taggedParts.Take(i));
                markup.Append("<span font='" + FontService.SansFontName + "' size='small'>");
                markup.AppendLine();
                markup.AppendLine();
                markup.AppendTaggedText(theme, taggedParts.Skip(i + 1));
                markup.Append("</span>");
            }
            return(new TooltipInformation {
                SignatureMarkup = markup.ToString()
            });
        }
示例#2
0
        public override async Task <TooltipItem> GetItem(TextEditor editor, DocumentContext ctx, int offset, CancellationToken token = default(CancellationToken))
        {
            if (ctx == null)
            {
                return(null);
            }
            var analysisDocument = ctx.AnalysisDocument;

            if (analysisDocument == null)
            {
                return(null);
            }
            var unit = await analysisDocument.GetSemanticModelAsync(token);

            if (unit == null)
            {
                return(null);
            }

            int         caretOffset = editor.CaretOffset;
            EditorTheme theme       = SyntaxHighlightingService.GetIdeFittingTheme(editor.Options.GetEditorTheme());

            return(await Task.Run(async() => {
                var root = unit.SyntaxTree.GetRoot(token);
                SyntaxToken syntaxToken;
                try {
                    syntaxToken = root.FindToken(offset);
                } catch (ArgumentOutOfRangeException) {
                    return null;
                }
                if (!syntaxToken.Span.Contains(offset))
                {
                    return null;
                }
                var node = GetBestFitResolveableNode(syntaxToken.Parent);
                var symbolInfo = unit.GetSymbolInfo(node, token);
                var symbol = symbolInfo.Symbol;
                if (symbol == null && syntaxToken.IsKind(SyntaxKind.IdentifierToken))
                {
                    symbol = unit.GetDeclaredSymbol(node, token);
                }
                var tooltipInformation = await CreateTooltip(symbol, syntaxToken, caretOffset, theme, ctx, offset);
                if (tooltipInformation == null || string.IsNullOrEmpty(tooltipInformation.SignatureMarkup))
                {
                    return null;
                }
                return new TooltipItem(tooltipInformation, syntaxToken.Span.Start, syntaxToken.Span.Length);
            }));
        }
        public override Task <TooltipInformation> CreateTooltipInformation(TextEditor editor, DocumentContext ctx, int currentParameter, bool smartWrap, CancellationToken cancelToken)
        {
            var tt     = new TooltipInformation();
            var markup = new StringBuilder();
            var theme  = SyntaxHighlightingService.GetIdeFittingTheme(DefaultSourceEditorOptions.Instance.GetEditorTheme());

            markup.AppendTaggedText(theme, Item.PrefixDisplayParts);
            var prefixLength    = Item.PrefixDisplayParts.GetFullText().Length;
            var prefixSpacer    = new string (' ', prefixLength);
            var col             = 0;
            var separatorLength = Item.SeparatorDisplayParts.GetFullText().Length;

            for (int i = 0; i < Item.Parameters.Length; i++)
            {
                if (i > 0)
                {
                    markup.AppendTaggedText(theme, Item.SeparatorDisplayParts);
                    col += separatorLength;
                }

                if (col > MaxParamColumnCount)
                {
                    markup.AppendLine();
                    markup.Append(prefixSpacer);
                    col = 0;
                }

                var p = Item.Parameters [i];
                if (i == currentParameter)
                {
                    markup.Append("<b>");
                }
                if (p.IsOptional)
                {
                    markup.Append("[");
                    col++;
                }
                markup.AppendTaggedText(theme, p.DisplayParts);
                col += p.DisplayParts.GetFullText().Length;
                if (p.IsOptional)
                {
                    markup.Append("]");
                    col++;
                }
                if (i == currentParameter)
                {
                    markup.Append("</b>");
                }
            }

            markup.AppendTaggedText(theme, Item.SuffixDisplayParts);

            List <TaggedText> documentation;

            try {
                documentation = Item.DocumentationFactory(cancelToken).ToList();
            } catch (Exception e) {
                documentation = EmptyTaggedTextList;
                LoggingService.LogError("Error while getting parameter documentation", e);
            }

            if (documentation.Count > 0)
            {
                markup.Append("<span font='" + FontService.SansFontName + "' size='small'>");
                markup.AppendLine();
                markup.AppendLine();
                markup.AppendTaggedText(theme, documentation, 0, MaxParamColumnCount);
                markup.Append("</span>");
            }

            if (currentParameter >= 0 && currentParameter < Item.Parameters.Length)
            {
                var p = Item.Parameters [currentParameter];
                if (p.DocumentationFactory != null)
                {
                    try {
                        documentation = p.DocumentationFactory(cancelToken).ToList();
                    } catch (Exception e) {
                        documentation = EmptyTaggedTextList;
                        LoggingService.LogError("Error while getting parameter documentation", e);
                    }
                    if (documentation.Count > 0)
                    {
                        markup.Append("<span font='" + FontService.SansFontName + "' size='small'>");
                        markup.AppendLine();
                        markup.AppendLine();
                        markup.Append("<b>");
                        markup.Append(p.Name);
                        markup.Append(": </b>");
                        markup.AppendTaggedText(theme, documentation, p.Name.Length + 2, MaxParamColumnCount);
                        markup.Append("</span>");
                    }
                }
            }

            tt.SignatureMarkup = markup.ToString();
            return(Task.FromResult(tt));
        }