Example #1
0
        private void AddReferenceLine(MetadataReference reference, ToggleButton coreReferencesButton, ToggleButton additionalReferencesButton)
        {
            bool isCore = IsCoreReference(reference.Display);

            Grid referenceGrid = new Grid();

            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition(32, GridUnitType.Pixel));
            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Pixel));
            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition(32, GridUnitType.Pixel));
            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Pixel));
            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition(32, GridUnitType.Pixel));
            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Pixel));
            referenceGrid.ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Star));

            Button removeButton = new Button()
            {
                Content = new DiagnosticIcons.MinusIcon(), Width = 20, Height = 20, Margin = new Thickness(6, 0, 6, 0)
            };

            removeButton.Classes.Add("AddRemove");
            referenceGrid.Children.Add(removeButton);

            Control icon;

            if (isCore)
            {
                icon = new DiagnosticIcons.CoreReferenceIcon();
                referenceGrid.Bind <bool>(Grid.IsVisibleProperty, coreReferencesButton.GetBindingObservable(ToggleButton.IsCheckedProperty).Select(x => x.Value.Value));
            }
            else
            {
                icon = new DiagnosticIcons.AssemblyReferenceIcon();
                referenceGrid.Bind <bool>(Grid.IsVisibleProperty, additionalReferencesButton.GetBindingObservable(ToggleButton.IsCheckedProperty).Select(x => x.Value.Value));
            }

            icon.Margin = new Thickness(6, 0, 6, 0);

            Grid.SetColumn(icon, 2);
            referenceGrid.Children.Add(icon);

            Canvas nameBackground = new Canvas()
            {
                Margin = new Thickness(5, 2, 5, 2), Height = 20, VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center, ClipToBounds = true
            };

            TextBlock nameBlock = new TextBlock()
            {
                Text = reference.Display, ClipToBounds = true
            };

            nameBackground.Children.Add(nameBlock);
            Grid.SetColumn(nameBackground, 6);
            referenceGrid.Children.Add(nameBackground);

            Canvas documentationIcon = new Canvas()
            {
                Width = 16, Height = 16
            };

            Button documentationStatus = new Button()
            {
                Content = documentationIcon, Width = 20, Height = 20, HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center
            };

            documentationStatus.Classes.Add("AddRemove");

            DocumentationProvider documentationProvider = GetDocumentationProvider(reference);

            string typeName = documentationProvider.GetType().Name;

            if (documentationProvider is XmlDocumentationProvider && typeName != "NullXmlDocumentationProvider")
            {
                documentationIcon.Children.Add(new DiagnosticIcons.TickIcon());
                ToolTip.SetTip(documentationStatus, "XML documentation available");
            }
            else if (isCore)
            {
                documentationIcon.Children.Add(new DiagnosticIcons.BlueTickIcon());
                ToolTip.SetTip(documentationStatus, "Core assembly documentation");
            }
            else
            {
                documentationIcon.Children.Add(new DiagnosticIcons.ErrorIcon());
                ToolTip.SetTip(documentationStatus, "XML documentation not available");
            }

            Grid.SetColumn(documentationStatus, 4);
            referenceGrid.Children.Add(documentationStatus);

            this.FindControl <StackPanel>("ReferencesContainer").Children.Add(referenceGrid);

            referenceGrid.Tag = reference;

            removeButton.Click += async(s, e) =>
            {
                this.FindControl <StackPanel>("ReferencesContainer").Children.Remove(referenceGrid);


                if (!(referenceGrid.Tag is MetadataReference referenceToRemove))
                {
                    referenceToRemove = (MetadataReference)(CachedMetadataReference)referenceGrid.Tag;
                }

                this.References = this.References.Remove(referenceToRemove);

                Editor editor = this.FindAncestorOfType <Editor>();

                await editor.SetReferences(References, false);
            };

            documentationStatus.Click += async(s, e) =>
            {
                await DocumentationButtonClicked(reference, documentationIcon, referenceGrid);
            };
        }
Example #2
0
        public void SetContent(SourceText source, IEnumerable <Diagnostic> diagnostics, int linesToIgnore)
        {
            this.FindControl <StackPanel>("ErrorContainer").Children.Clear();

            int errors   = 0;
            int warnings = 0;
            int infos    = 0;

            ToggleButton errorButton   = this.FindControl <ToggleButton>("ErrorButton");
            ToggleButton warningButton = this.FindControl <ToggleButton>("WarningButton");
            ToggleButton messageButton = this.FindControl <ToggleButton>("MessageButton");
            Editor       editor        = this.FindAncestorOfType <Editor>();
            //editor.ErrorMarkerService.RemoveAll(m => true);

            List <(TextSpan, Diagnostic)> errorSpans = new List <(TextSpan, Diagnostic)>();

            List <(TextSpan, Diagnostic)> warningSpans = new List <(TextSpan, Diagnostic)>();

            foreach (Diagnostic diag in diagnostics)
            {
                if (diag.Severity != DiagnosticSeverity.Hidden)
                {
                    TextSpan?span    = null;
                    string   lineNum = "";

                    try
                    {
                        LinePosition startPos = diag.Location.GetLineSpan().StartLinePosition;
                        LinePosition endPos   = diag.Location.GetLineSpan().EndLinePosition;

                        LinePosition correctedStartPos = new LinePosition(startPos.Line - linesToIgnore, startPos.Character);
                        LinePosition correctedEndPos   = new LinePosition(endPos.Line - linesToIgnore, endPos.Character);
                        span = source.Lines.GetTextSpan(new LinePositionSpan(correctedStartPos, correctedEndPos));

                        lineNum = (diag.Location.GetLineSpan().StartLinePosition.Line - linesToIgnore + 1).ToString();
                    }
                    catch { }

                    Grid errorGrid = new Grid();

                    errorGrid.Classes.Add("ErrorLine");

                    errorGrid.ColumnDefinitions.Add(new ColumnDefinition(32, GridUnitType.Pixel));
                    errorGrid.ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Pixel));
                    errorGrid.ColumnDefinitions.Add(new ColumnDefinition(64, GridUnitType.Pixel));
                    errorGrid.ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Pixel));
                    errorGrid.ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Star));
                    errorGrid.ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Pixel));
                    errorGrid.ColumnDefinitions.Add(new ColumnDefinition(64, GridUnitType.Pixel));
                    errorGrid.ColumnDefinitions.Add(new ColumnDefinition(18, GridUnitType.Pixel));

                    switch (diag.Severity)
                    {
                    case DiagnosticSeverity.Error:
                        errorGrid.Children.Add(new DiagnosticIcons.ErrorIcon());
                        errorGrid.Bind <bool>(Grid.IsVisibleProperty, errorButton.GetBindingObservable(ToggleButton.IsCheckedProperty).Select(x => x.Value.Value));
                        errors++;
                        if (span != null)
                        {
                            errorSpans.Add((new TextSpan(span.Value.Start, span.Value.Length), diag));
                        }

                        break;

                    case DiagnosticSeverity.Info:
                        errorGrid.Children.Add(new DiagnosticIcons.InfoIcon());
                        errorGrid.Bind <bool>(Grid.IsVisibleProperty, messageButton.GetBindingObservable(ToggleButton.IsCheckedProperty).Select(x => x.Value.Value));
                        infos++;
                        break;

                    case DiagnosticSeverity.Warning:
                        errorGrid.Children.Add(new DiagnosticIcons.WarningIcon());
                        errorGrid.Bind <bool>(Grid.IsVisibleProperty, warningButton.GetBindingObservable(ToggleButton.IsCheckedProperty).Select(x => x.Value.Value));
                        warnings++;
                        if (span != null)
                        {
                            warningSpans.Add((new TextSpan(span.Value.Start, span.Value.Length), diag));
                        }
                        break;
                    }

                    TextBlock codeBlock = new TextBlock()
                    {
                        Text = diag.Id, Margin = new Thickness(5, 2, 5, 2), VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center
                    };
                    Grid.SetColumn(codeBlock, 2);
                    errorGrid.Children.Add(codeBlock);

                    TextBlock descriptionBlock = new TextBlock()
                    {
                        Text = diag.GetMessage(System.Globalization.CultureInfo.InvariantCulture), Margin = new Thickness(5, 2, 5, 2), VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center, TextWrapping = Avalonia.Media.TextWrapping.Wrap
                    };
                    Grid.SetColumn(descriptionBlock, 4);
                    errorGrid.Children.Add(descriptionBlock);

                    TextBlock lineBlock = new TextBlock()
                    {
                        Text = lineNum, Margin = new Thickness(5, 2, 5, 2), VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center
                    };
                    Grid.SetColumn(lineBlock, 6);
                    errorGrid.Children.Add(lineBlock);

                    this.FindControl <StackPanel>("ErrorContainer").Children.Add(errorGrid);

                    errorGrid.PointerPressed += (s, e) =>
                    {
                        if (span != null)
                        {
                            editor.EditorControl.SetSelection(span.Value.Start, span.Value.Length);
                        }
                    };
                }
            }

            List <MarkerRange> markers = new List <MarkerRange>();

            foreach ((TextSpan, List <Diagnostic>)span in errorSpans.Join())
            {
                /*try
                 * {
                 *  ITextMarker marker = editor.ErrorMarkerService.Create(span.Start, span.Length);
                 *  marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
                 *  marker.MarkerColor = Color.FromRgb(255, 72, 72);
                 * }
                 * catch { }*/

                markers.Add(new MarkerRange(span.Item1, ErrorPen, span.Item2));
            }

            foreach ((TextSpan, List <Diagnostic>)span in warningSpans.Join())
            {
                /*try
                 * {
                 *  ITextMarker marker = editor.ErrorMarkerService.Create(span.Start, span.Length);
                 *  marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
                 *  marker.MarkerColor = Color.FromRgb(64, 160, 64);
                 * }
                 * catch { }*/

                markers.Add(new MarkerRange(span.Item1, WarningPen, span.Item2));
            }

            if (editor != null)
            {
                editor.EditorControl.Markers = ImmutableList.Create(markers.ToArray());

                editor.StatusBar.ErrorCount   = errors;
                editor.StatusBar.WarningCount = warnings;
                editor.StatusBar.InfoCount    = infos;

                this.FindControl <TextBlock>("ErrorText").Text   = errors.ToString() + " Error" + (errors == 1 ? "" : "s");
                this.FindControl <TextBlock>("WarningText").Text = warnings.ToString() + " Warning" + (warnings == 1 ? "" : "s");
                this.FindControl <TextBlock>("MessageText").Text = infos.ToString() + " Message" + (infos == 1 ? "" : "s");
            }
        }