protected virtual ICompletionDataList ClosingTagCompletion (TextEditor buf, DocumentLocation currentLocation) { //get name of current node in document that's being ended var el = tracker.Engine.Nodes.Peek () as XElement; if (el != null && el.Region.End >= currentLocation && !el.IsClosed && el.IsNamed) { string tag = String.Concat ("</", el.Name.FullName, ">"); if (XmlEditorOptions.AutoCompleteElements) { // //make sure we have a clean atomic undo so the user can undo the tag insertion // //independently of the > // bool wasInAtomicUndo = this.Editor.Document.IsInAtomicUndo; // if (wasInAtomicUndo) // this.Editor.Document.EndAtomicUndo (); using (var undo = buf.OpenUndoGroup ()) { buf.InsertText (buf.CaretOffset, tag); buf.CaretOffset -= tag.Length; } // if (wasInAtomicUndo) // this.Editor.Document.BeginAtomicUndo (); return null; } else { var cp = new CompletionDataList (); cp.Add (new XmlTagCompletionData (tag, 0, true)); return cp; } } return null; }
static CommandInfoSet CreateFixMenu (TextEditor editor, DocumentContext ctx, CodeActionContainer container) { if (editor == null) throw new ArgumentNullException ("editor"); if (ctx == null) throw new ArgumentNullException ("ctx"); if (container == null) throw new ArgumentNullException ("container"); var result = new CommandInfoSet (); result.Text = GettextCatalog.GetString ("Fix"); foreach (var diagnostic in container.CodeFixActions) { var info = new CommandInfo (diagnostic.CodeAction.Title); result.CommandInfos.Add (info, new Action (new CodeActionEditorExtension.ContextActionRunner (diagnostic.CodeAction, editor, ctx).Run)); } if (result.CommandInfos.Count == 0) return result; bool firstDiagnosticOption = true; foreach (var fix in container.DiagnosticsAtCaret) { var inspector = BuiltInCodeDiagnosticProvider.GetCodeDiagnosticDescriptor (fix.Id); if (inspector == null) continue; if (firstDiagnosticOption) { result.CommandInfos.AddSeparator (); firstDiagnosticOption = false; } var label = GettextCatalog.GetString ("_Options for \"{0}\"", fix.GetMessage ()); var subMenu = new CommandInfoSet (); subMenu.Text = label; // if (inspector.CanSuppressWithAttribute) { // var menuItem = new FixMenuEntry (GettextCatalog.GetString ("_Suppress with attribute"), // delegate { // // inspector.SuppressWithAttribute (Editor, DocumentContext, GetTextSpan (fix.Item2)); // }); // subMenu.Add (menuItem); // } if (inspector.CanDisableWithPragma) { var info = new CommandInfo (GettextCatalog.GetString ("_Suppress with #pragma")); subMenu.CommandInfos.Add (info, new Action (() => inspector.DisableWithPragma (editor, ctx, fix))); info = new CommandInfo (GettextCatalog.GetString ("_Suppress with file")); subMenu.CommandInfos.Add (info, new Action (() => inspector.DisableWithFile (editor, ctx, fix))); } var configInfo = new CommandInfo (GettextCatalog.GetString ("_Configure Rule")); subMenu.CommandInfos.Add (configInfo, new Action (() => { IdeApp.Workbench.ShowGlobalPreferencesDialog (null, "C#", dialog => { var panel = dialog.GetPanel<CodeIssuePanel> ("C#"); if (panel == null) return; panel.Widget.SelectCodeIssue (inspector.IdString); }); })); foreach (var fix2 in container.CodeFixActions) { var provider = fix2.Diagnostic.GetCodeFixProvider ().GetFixAllProvider (); if (provider == null) continue; if (!provider.GetSupportedFixAllScopes ().Contains (FixAllScope.Document)) continue; var subMenu2 = new CommandInfoSet (); subMenu2.Text = GettextCatalog.GetString ("Fix all"); var diagnosticAnalyzer = fix2.Diagnostic.GetCodeDiagnosticDescriptor (LanguageNames.CSharp).GetProvider (); if (!diagnosticAnalyzer.SupportedDiagnostics.Contains (fix.Descriptor)) continue; var info = new CommandInfo (GettextCatalog.GetString ("In _Document")); subMenu2.CommandInfos.Add (info, new Action (async delegate { var fixAllDiagnosticProvider = new CodeActionEditorExtension.FixAllDiagnosticProvider (diagnosticAnalyzer.SupportedDiagnostics.Select (d => d.Id).ToImmutableHashSet (), async (Microsoft.CodeAnalysis.Document doc, ImmutableHashSet<string> diagnostics, CancellationToken token) => { var model = await doc.GetSemanticModelAsync (token); var compilationWithAnalyzer = model.Compilation.WithAnalyzers (new [] { diagnosticAnalyzer }.ToImmutableArray (), null, token); return await compilationWithAnalyzer.GetAnalyzerSemanticDiagnosticsAsync (model, null, token); }, (arg1, arg2, arg3, arg4) => { return Task.FromResult ((IEnumerable<Diagnostic>)new Diagnostic[] { }); }); var ctx2 = new FixAllContext ( ctx.AnalysisDocument, fix2.Diagnostic.GetCodeFixProvider (), FixAllScope.Document, fix2.CodeAction.EquivalenceKey, diagnosticAnalyzer.SupportedDiagnostics.Select (d => d.Id), fixAllDiagnosticProvider, default (CancellationToken) ); var fixAll = await provider.GetFixAsync (ctx2); using (var undo = editor.OpenUndoGroup ()) { CodeDiagnosticDescriptor.RunAction (ctx, fixAll, default (CancellationToken)); } })); subMenu.CommandInfos.Add (subMenu2); } result.CommandInfos.Add (subMenu); } return result; }