diff options
Diffstat (limited to 'main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeIssuePanelWidget.cs')
-rw-r--r-- | main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeIssuePanelWidget.cs | 128 |
1 files changed, 72 insertions, 56 deletions
diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeIssuePanelWidget.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeIssuePanelWidget.cs index 241f9281f6..b9d01f4337 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeIssuePanelWidget.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/CodeIssuePanelWidget.cs @@ -28,14 +28,14 @@ using MonoDevelop.Ide.Gui.Dialogs; using Gtk; using MonoDevelop.Core; using System.Linq; -using MonoDevelop.SourceEditor; using MonoDevelop.Refactoring; using System.Collections.Generic; -using Mono.TextEditor; -using ICSharpCode.NRefactory.Refactoring; using GLib; using MonoDevelop.Components; using Gdk; +using MonoDevelop.Ide.Editor; +using MonoDevelop.CodeActions; +using Microsoft.CodeAnalysis; using MonoDevelop.SourceEditor.QuickTasks; namespace MonoDevelop.CodeIssues @@ -73,19 +73,21 @@ namespace MonoDevelop.CodeIssues partial class CodeIssuePanelWidget : Bin { readonly string mimeType; - readonly TreeStore treeStore = new TreeStore (typeof(string), typeof(BaseCodeIssueProvider), typeof (string)); - readonly Dictionary<BaseCodeIssueProvider, Severity> severities = new Dictionary<BaseCodeIssueProvider, Severity> (); - readonly Dictionary<BaseCodeIssueProvider, bool> enableState = new Dictionary<BaseCodeIssueProvider, bool> (); + readonly TreeStore treeStore = new TreeStore (typeof(string), typeof(Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor>), typeof (string)); + readonly Dictionary<Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor>, DiagnosticSeverity?> severities = new Dictionary<Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor>, DiagnosticSeverity?> (); + readonly Dictionary<Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor>, bool> enableState = new Dictionary<Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor>, bool> (); void GetAllSeverities () { - foreach (var node in RefactoringService.GetInspectors (mimeType)) { - severities [node] = node.GetSeverity (); - enableState [node] = node.GetIsEnabled (); - if (node.HasSubIssues) { - foreach (var subIssue in node.SubIssues) { - severities [subIssue] = subIssue.GetSeverity (); - enableState [subIssue] = subIssue.GetIsEnabled (); + foreach (var node in BuiltInCodeDiagnosticProvider.GetBuiltInCodeDiagnosticDecsriptorsAsync (CodeRefactoringService.MimeTypeToLanguage (mimeType), true).Result) { + var root = new Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor> (node, null); + severities [root] = node.DiagnosticSeverity; + enableState [root] = node.IsEnabled; + if (node.GetProvider ().SupportedDiagnostics.Length > 1) { + foreach (var subIssue in node.GetProvider ().SupportedDiagnostics) { + var sub = new Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor> (node, subIssue); + severities [sub] = node.GetSeverity (subIssue); + enableState [sub] = node.GetIsEnabled (subIssue); } } } @@ -102,8 +104,8 @@ namespace MonoDevelop.CodeIssues bool SelectCodeIssue (string idString, TreeIter iter) { do { - var provider = treeStore.GetValue (iter, 1) as BaseCodeIssueProvider; - if (provider != null && provider.IdString == idString) { + var provider = (Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor>)treeStore.GetValue (iter, 1); + if (provider != null && idString == provider.Item1.IdString) { treeviewInspections.ExpandToPath (treeStore.GetPath (iter)); treeviewInspections.Selection.SelectIter (iter); return true; @@ -120,33 +122,30 @@ namespace MonoDevelop.CodeIssues return false; } - static string GetDescription (Severity severity) + static string GetDescription (DiagnosticSeverity severity) { switch (severity) { - case Severity.None: + case DiagnosticSeverity.Hidden: return GettextCatalog.GetString ("Do not show"); - case Severity.Error: + case DiagnosticSeverity.Error: return GettextCatalog.GetString ("Error"); - case Severity.Warning: + case DiagnosticSeverity.Warning: return GettextCatalog.GetString ("Warning"); - case Severity.Hint: - return GettextCatalog.GetString ("Hint"); - case Severity.Suggestion: - return GettextCatalog.GetString ("Suggestion"); + case DiagnosticSeverity.Info: + return GettextCatalog.GetString ("Info"); default: throw new ArgumentOutOfRangeException (); } } - Xwt.Drawing.Image GetIcon (Severity severity) + Xwt.Drawing.Image GetIcon (DiagnosticSeverity severity) { switch (severity) { - case Severity.Error: + case DiagnosticSeverity.Error: return QuickTaskOverviewMode.ErrorImage; - case Severity.Warning: + case DiagnosticSeverity.Warning: return QuickTaskOverviewMode.WarningImage; - case Severity.Hint: - case Severity.Suggestion: + case DiagnosticSeverity.Info: return QuickTaskOverviewMode.SuggestionImage; default: return QuickTaskOverviewMode.OkImage; @@ -157,25 +156,24 @@ namespace MonoDevelop.CodeIssues { categories.Clear (); treeStore.Clear (); - - var grouped = severities.Keys.OfType<CodeIssueProvider> () - .Where (node => string.IsNullOrEmpty (filter) || node.Title.IndexOf (filter, StringComparison.OrdinalIgnoreCase) > 0) - .GroupBy (node => node.Category) + var grouped = severities.Keys + .Where (node => node.Item2 == null && (string.IsNullOrEmpty (filter) || node.Item1.Name.IndexOf (filter, StringComparison.OrdinalIgnoreCase) > 0)) + .GroupBy (node => node.Item1.GetProvider ().SupportedDiagnostics.First ().Category) .OrderBy (g => g.Key, StringComparer.Ordinal); foreach (var g in grouped) { TreeIter categoryIter = treeStore.AppendValues ("<b>" + g.Key + "</b>", null, null); categories [g.Key] = categoryIter; - foreach (var node in g.OrderBy (n => n.Title, StringComparer.Ordinal)) { - var title = node.Title; + foreach (var node in g.OrderBy (n => n.Item1.Name, StringComparer.Ordinal)) { + var title = node.Item1.Name; MarkupSearchResult (filter, ref title); - var nodeIter = treeStore.AppendValues (categoryIter, title, node, node.Description); - if (node.HasSubIssues) { - foreach (var subIssue in node.SubIssues) { - title = subIssue.Title; + var nodeIter = treeStore.AppendValues (categoryIter, title, node, node.Item1.Name); + if (node.Item1.GetProvider ().SupportedDiagnostics.Length > 1) { + foreach (var subIssue in node.Item1.GetProvider ().SupportedDiagnostics) { + title = subIssue.Description.ToString (); MarkupSearchResult (filter, ref title); - treeStore.AppendValues (nodeIter, title, subIssue, subIssue.Description); + treeStore.AppendValues (nodeIter, title, new Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor> (node.Item1, subIssue), subIssue.Description); } } } @@ -241,7 +239,7 @@ namespace MonoDevelop.CodeIssues toggleRenderer.Toggled += delegate(object o, ToggledArgs args) { TreeIter iter; if (treeStore.GetIterFromString (out iter, args.Path)) { - var provider = (BaseCodeIssueProvider)treeStore.GetValue (iter, 1); + var provider = (Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor>)treeStore.GetValue (iter, 1); enableState[provider] = !enableState[provider]; } }; @@ -251,7 +249,7 @@ namespace MonoDevelop.CodeIssues titleCol.PackStart (toggleRenderer, false); titleCol.Sizing = TreeViewColumnSizing.Autosize; titleCol.SetCellDataFunc (toggleRenderer, delegate (TreeViewColumn treeColumn, CellRenderer cell, TreeModel model, TreeIter iter) { - var provider = (BaseCodeIssueProvider)model.GetValue (iter, 1); + var provider = (Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor>)treeStore.GetValue (iter, 1); if (provider == null) { toggleRenderer.Visible = false; return; @@ -284,12 +282,11 @@ namespace MonoDevelop.CodeIssues col.MinWidth = 100; col.Expand = false; - var comboBoxStore = new ListStore (typeof(string), typeof(Severity)); + var comboBoxStore = new ListStore (typeof(string), typeof(DiagnosticSeverity)); // comboBoxStore.AppendValues (GetDescription (Severity.None), Severity.None); - comboBoxStore.AppendValues (GetDescription (Severity.Error), Severity.Error); - comboBoxStore.AppendValues (GetDescription (Severity.Warning), Severity.Warning); - comboBoxStore.AppendValues (GetDescription (Severity.Hint), Severity.Hint); - comboBoxStore.AppendValues (GetDescription (Severity.Suggestion), Severity.Suggestion); + comboBoxStore.AppendValues (GetDescription (DiagnosticSeverity.Error), DiagnosticSeverity.Error); + comboBoxStore.AppendValues (GetDescription (DiagnosticSeverity.Warning), DiagnosticSeverity.Warning); + comboBoxStore.AppendValues (GetDescription (DiagnosticSeverity.Info), DiagnosticSeverity.Info); comboRenderer.Model = comboBoxStore; comboRenderer.Mode = CellRendererMode.Activatable; comboRenderer.TextColumn = 0; @@ -307,8 +304,8 @@ namespace MonoDevelop.CodeIssues return; do { if ((string)comboBoxStore.GetValue (storeIter, 0) == args.NewText) { - var provider = (BaseCodeIssueProvider)treeStore.GetValue (iter, 1); - var severity = (Severity)comboBoxStore.GetValue (storeIter, 1); + var provider = (Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor>)treeStore.GetValue (iter, 1); + var severity = (DiagnosticSeverity)comboBoxStore.GetValue (storeIter, 1); severities[provider] = severity; return; } @@ -316,15 +313,19 @@ namespace MonoDevelop.CodeIssues }; col.SetCellDataFunc (comboRenderer, delegate (TreeViewColumn treeColumn, CellRenderer cell, TreeModel model, TreeIter iter) { - var provider = (BaseCodeIssueProvider)model.GetValue (iter, 1); + var provider = (Tuple<CodeDiagnosticDescriptor, DiagnosticDescriptor>)treeStore.GetValue (iter, 1); if (provider == null) { comboRenderer.Visible = false; return; } var severity = severities[provider]; + if (!severity.HasValue) { + comboRenderer.Visible = false; + return; + } comboRenderer.Visible = true; - comboRenderer.Text = GetDescription (severity); - comboRenderer.Icon = GetIcon (severity); + comboRenderer.Text = GetDescription (severity.Value); + comboRenderer.Icon = GetIcon (severity.Value); }); treeviewInspections.HeadersVisible = false; treeviewInspections.Model = treeStore; @@ -342,10 +343,25 @@ namespace MonoDevelop.CodeIssues public void ApplyChanges () { - foreach (var kv in severities) - kv.Key.SetSeverity (kv.Value); - foreach (var kv in enableState) - kv.Key.SetIsEnabled (kv.Value); + foreach (var kv in severities) { + var userSeverity = kv.Value; + if (!userSeverity.HasValue) + continue; + if (kv.Key.Item2 == null) { + kv.Key.Item1.DiagnosticSeverity = userSeverity; + continue; + } + kv.Key.Item1.SetSeverity (kv.Key.Item2, userSeverity.Value); + } + + foreach (var kv in enableState) { + var userIsEnabled = kv.Value; + if (kv.Key.Item2 == null) { + kv.Key.Item1.IsEnabled = userIsEnabled; + continue; + } + kv.Key.Item1.SetIsEnabled (kv.Key.Item2, userIsEnabled); + } } } -}
\ No newline at end of file +} |