コード例 #1
0
        protected static object CreateToolTipContent(Workspace workspace, DiagnosticData diagnostic)
        {
            Action?navigationAction = null;
            string?tooltip          = null;

            if (workspace != null)
            {
                var helpLinkUri = diagnostic.GetValidHelpLinkUri();
                if (helpLinkUri != null)
                {
                    navigationAction = new QuickInfoHyperLink(workspace, helpLinkUri).NavigationAction;
                    tooltip          = diagnostic.HelpLink;
                }
            }

            var diagnosticIdTextRun = navigationAction is null
                ? new ClassifiedTextRun(ClassificationTypeNames.Text, diagnostic.Id)
                : new ClassifiedTextRun(ClassificationTypeNames.Text, diagnostic.Id, navigationAction, tooltip);

            return(new ContainerElement(
                       ContainerElementStyle.Wrapped,
                       new ClassifiedTextElement(
                           diagnosticIdTextRun,
                           new ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"),
                           new ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "),
                           new ClassifiedTextRun(ClassificationTypeNames.Text, diagnostic.Message))));
        }
コード例 #2
0
ファイル: PreviewPaneService.cs プロジェクト: ryzngard/roslyn
        object IPreviewPaneService.GetPreviewPane(DiagnosticData data, IReadOnlyList <object> previewContent)
        {
            var title = data?.Message;

            if (string.IsNullOrWhiteSpace(title))
            {
                if (previewContent == null)
                {
                    // Bail out in cases where there is nothing to put in the header section
                    // of the preview pane and no preview content (i.e. no diff view) either.
                    return(null);
                }

                return(new PreviewPane(
                           severityIcon: null, id: null, title: null, description: null, helpLink: null, helpLinkToolTipText: null,
                           previewContent: previewContent, logIdVerbatimInTelemetry: false, uiShell: _uiShell));
            }

            Guid optionPageGuid = default;

            if (data.Properties.TryGetValue("OptionName", out var optionName))
            {
                data.Properties.TryGetValue("OptionLanguage", out var optionLanguage);
                optionPageGuid = GetOptionPageGuidForOptionName(optionName, optionLanguage);
            }

            var helpLinkUri = data.GetValidHelpLinkUri();

            return(new PreviewPane(
                       severityIcon: GetSeverityIconForDiagnostic(data),
                       id: data.Id, title: title,
                       description: data.Description.ToString(CultureInfo.CurrentUICulture),
                       helpLink: helpLinkUri,
                       helpLinkToolTipText: (helpLinkUri != null) ? string.Format(EditorFeaturesResources.Get_help_for_0, data.Id) : null,
                       previewContent: previewContent,
                       logIdVerbatimInTelemetry: data.CustomTags.Contains(WellKnownDiagnosticTags.Telemetry),
                       uiShell: _uiShell,
                       optionPageGuid: optionPageGuid));
        }
コード例 #3
0
        /// <summary>
        /// Creates a GraphicsResult object which is the error block based on the geometry and formatting set for the item.
        /// </summary>
        public override GraphicsResult GetGraphics(IWpfTextView view, Geometry unused, TextFormattingRunProperties format)
        {
            var block = new TextBlock
            {
                FontFamily = format.Typeface.FontFamily,
                FontSize   = 0.75 * format.FontRenderingEmSize,
                FontStyle  = FontStyles.Normal,
                Foreground = format.ForegroundBrush,
                Padding    = new Thickness(left: 2, top: 0, right: 2, bottom: 0),
            };

            var idRun = GetRunForId(out var hyperlink);

            if (hyperlink is null)
            {
                block.Inlines.Add(idRun);
            }
            else
            {
                // Match the hyperlink color to what the classification is set to by the user
                var linkColor = _classificationFormatMap.GetTextProperties(_classificationType);
                hyperlink.Foreground = linkColor.ForegroundBrush;

                block.Inlines.Add(hyperlink);
                hyperlink.RequestNavigate += HandleRequestNavigate;
            }

            block.Inlines.Add(": " + _diagnostic.Message);

            var lineHeight = Math.Floor(format.Typeface.FontFamily.LineSpacing * block.FontSize);
            var image      = new CrispImage
            {
                Moniker   = GetMoniker(),
                MaxHeight = lineHeight,
                Margin    = new Thickness(1, 0, 5, 0)
            };

            var border = new Border
            {
                BorderBrush     = format.BackgroundBrush,
                BorderThickness = new Thickness(1),
                Background      = Brushes.Transparent,
                Child           = new StackPanel
                {
                    Height      = lineHeight,
                    Orientation = Orientation.Horizontal,
                    Children    = { image, block }
                },
                CornerRadius = new CornerRadius(2),
                // Highlighting lines are 2px buffer. So shift us up by one from the bottom so we feel centered between them.
                Margin  = new Thickness(10, top: 0, right: 0, bottom: 1),
                Padding = new Thickness(1)
            };

            // This is used as a workaround to the moniker issues in blue theme
            var editorBackground = (Color)_editorFormatMap.GetProperties("TextView Background")["BackgroundColor"];

            ImageThemingUtilities.SetImageBackgroundColor(border, editorBackground);

            border.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            view.LayoutChanged += View_LayoutChanged;

            return(new GraphicsResult(border, dispose:
                                      () =>
            {
                if (hyperlink is not null)
                {
                    hyperlink.RequestNavigate -= HandleRequestNavigate;
                }

                view.LayoutChanged -= View_LayoutChanged;
            }));

            void View_LayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
            {
                if (Location is InlineDiagnosticsLocations.PlacedAtEndOfEditor)
                {
                    Canvas.SetLeft(border, view.ViewportRight - border.DesiredSize.Width);
                }
            }

            void HandleRequestNavigate(object sender, RoutedEventArgs e)
            {
                var uri = hyperlink.NavigateUri;

                _         = _navigateToLinkService.TryNavigateToLinkAsync(uri, CancellationToken.None);
                e.Handled = true;
            }

            Run GetRunForId(out Hyperlink?link)
            {
                var id = new Run(_diagnostic.Id);

                link = null;

                var helpLinkUri = _diagnostic.GetValidHelpLinkUri();

                if (helpLinkUri != null)
                {
                    link = new Hyperlink(id)
                    {
                        NavigateUri = helpLinkUri
                    };
                }

                return(id);
            }
        }