Преглед изворни кода

Improved CheckScriptStatus to include warnings

Kenric Nugteren пре 4 недеља
родитељ
комит
37a8949787
1 измењених фајлова са 71 додато и 31 уклоњено
  1. 71 31
      prs.desktop/Forms/Issues/IssuesGrid.cs

+ 71 - 31
prs.desktop/Forms/Issues/IssuesGrid.cs

@@ -16,6 +16,7 @@ using System.Windows;
 using InABox.Clients;
 using InABox.Scripting;
 using Microsoft.Win32;
+using Microsoft.CodeAnalysis;
 
 namespace PRSDesktop.Forms.Issues;
 
@@ -126,10 +127,8 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
         scriptButton.Margin = new Thickness(20, scriptButton.Margin.Top, scriptButton.Margin.Right, scriptButton.Margin.Bottom);
     }
 
-    private bool CheckScriptStatus(Button button, CoreRow[] rows)
+    private List<Tuple<CustomModule, string>> CheckCustomModules(bool showHidden, bool showWarnings)
     {
-        var showHidden = MessageWindow.ShowYesNo("Include Hidden Scripts?", "Confirm");
-
         var results = new List<Tuple<CustomModule, string>>();
         Progress.ShowModal("Loading Data", progress =>
         {
@@ -152,9 +151,10 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
                     progress.Report($"{module.Section} -> {module.Name}");
 
                     var scriptDocument = new ScriptDocument(module.Script);
-                    if (!scriptDocument.Compile())
+                    var ok = scriptDocument.Compile();
+                    if (!ok || (showWarnings && scriptDocument.Diagnostics.Any(x => x.Severity == DiagnosticSeverity.Error || x.Severity == DiagnosticSeverity.Warning)))
                     {
-                        var errors = scriptDocument.Result.Split(Environment.NewLine);
+                        var errors = scriptDocument.Diagnostics.Select(x => x.Contents);
                         results.Add(new(module, string.Join('\n', errors.Select(x => $"- {x}"))));
                     }
                 }
@@ -164,8 +164,16 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
                 }
             }
         });
+        return results;
+    }
+
+    private bool CheckScriptStatus(Button button, CoreRow[] rows)
+    {
+        var showHidden = MessageWindow.ShowYesNo("Include Hidden Scripts?", "Confirm");
+        var showWarnings = MessageWindow.ShowYesNo("Include Warnings?", "Confirm");
+        var results = CheckCustomModules(showHidden, showWarnings);
 
-        if (results.Any())
+        if (results.Count != 0)
         {
             var grid = new Grid();
             grid.AddRow(GridUnitType.Auto);
@@ -177,40 +185,53 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
             }, 0, 0);
 
             var list = new ListBox();
-            foreach(var (module, errors) in results)
+
+            var label = new Label
             {
-                var itemGrid = new Grid
-                {
+                HorizontalContentAlignment = HorizontalAlignment.Center,
+                VerticalAlignment = VerticalAlignment.Center
+            };
 
-                };
-                itemGrid.AddColumn(GridUnitType.Auto);
-                itemGrid.AddColumn(GridUnitType.Star);
-                var itemBtn = new Button
+            void RebuildList()
+            {
+                list.Items.Clear();
+                foreach(var (module, errors) in results)
                 {
-                    Content = new Image
+                    var itemGrid = new Grid
                     {
-                        Source = PRSDesktop.Resources.pencil.AsBitmapImage(),
-                    },
-                    Width = 30,
-                    Height = 30,
-                    Padding = new(5),
-                    Margin = new(0, 0, 5, 0),
-                    Tag = module
-                };
-                itemBtn.VerticalAlignment = VerticalAlignment.Top;
-                itemBtn.Click += ModuleOpen_Click;
-                itemGrid.AddChild(itemBtn, 0, 0);
-                itemGrid.AddChild(new Label
-                {
-                    Content = $"{module.Section}/{module.Name}:\n{errors}"
-                }, 0, 1);
-                list.Items.Add(itemGrid);
+
+                    };
+                    itemGrid.AddColumn(GridUnitType.Auto);
+                    itemGrid.AddColumn(GridUnitType.Star);
+                    var itemBtn = new Button
+                    {
+                        Content = new Image
+                        {
+                            Source = PRSDesktop.Resources.pencil.AsBitmapImage(),
+                        },
+                        Width = 30,
+                        Height = 30,
+                        Padding = new(5),
+                        Margin = new(0, 0, 5, 0),
+                        Tag = module
+                    };
+                    itemBtn.VerticalAlignment = VerticalAlignment.Top;
+                    itemBtn.Click += ModuleOpen_Click;
+                    itemGrid.AddChild(itemBtn, 0, 0);
+                    itemGrid.AddChild(new Label
+                    {
+                        Content = $"{module.Section}/{module.Name}:\n{errors}"
+                    }, 0, 1);
+                    list.Items.Add(itemGrid);
+                }
+
+                label.Content = $"{list.Items.Count} items";
             }
             grid.AddChild(list, 1, 0);
 
             var dockPanel = new DockPanel
             {
-                LastChildFill = false
+                LastChildFill = true
             };
 
             var exportButton = new Button
@@ -236,8 +257,27 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
             DockPanel.SetDock(exportButton, Dock.Left);
             dockPanel.Children.Add(exportButton);
 
+            var refreshButton = new Button
+            {
+                Content = "Refresh",
+                Padding = new(5),
+                Margin = new(5, 5, 0, 0)
+            };
+            refreshButton.Click += (o, e) =>
+            {
+                results = CheckCustomModules(showHidden, showWarnings);
+                RebuildList();
+            };
+            DockPanel.SetDock(refreshButton, Dock.Left);
+            dockPanel.Children.Add(refreshButton);
+
+            DockPanel.SetDock(label, Dock.Right);
+            dockPanel.Children.Add(label);
+
             grid.AddChild(dockPanel, 2, 0);
 
+            RebuildList();
+
             var window = new DynamicContentDialog(grid, buttonsVisible: false)
             {
                 Title = "Custom Module Errors"