diff options
Diffstat (limited to 'main/src/addins/MonoDevelop.Refactoring')
10 files changed, 69 insertions, 38 deletions
diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/AnalysisCommands.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/AnalysisCommands.cs index 4fe2c5f86f..392aacd522 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/AnalysisCommands.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/AnalysisCommands.cs @@ -59,10 +59,18 @@ namespace MonoDevelop.AnalysisCore { protected override void Update (CommandInfo info) { - MonoDevelop.Ide.Gui.Document document; - IList<FixableResult> results; - info.Enabled = FixOperationsHandler.GetFixes (out document, out results) - && results.Any (r => FixOperationsHandler.GetActions (document, r).Any ()); + var doc = MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument; + if (doc == null || doc.Editor == null) { + info.Enabled = false; + return; + } + var codeActionExtension = doc.GetContent <CodeActionEditorExtension> (); + if (codeActionExtension == null) { + info.Enabled = false; + return; + } + var fixes = codeActionExtension.GetCurrentFixes (); + info.Enabled = fixes.Any (); } protected override void Run () diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs index 9c3b135e75..ea74e0f17b 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs @@ -607,12 +607,12 @@ namespace MonoDevelop.CodeActions currentSmartTag.Popup (); } + static readonly List<CodeAction> emptyList = new List<CodeAction> (); internal List<CodeAction> GetCurrentFixes () { - if (currentSmartTag == null) + if (QuickTaskStrip.EnableFancyFeatures && currentSmartTag == null) return RefactoringService.GetValidActions (document, document.Editor.Caret.Location).Result.ToList (); - return currentSmartTag.fixes; + return currentSmartTag == null ? emptyList : currentSmartTag.fixes; } } -} - +}
\ No newline at end of file diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/BatchFixer.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/BatchFixer.cs index 783b45ff03..a0d4cf4cde 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/BatchFixer.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/BatchFixer.cs @@ -46,9 +46,9 @@ namespace MonoDevelop.CodeIssues { readonly IActionMatcher matcher; - readonly IProgressMonitor monitor; + readonly ProgressMonitor monitor; - public BatchFixer (IActionMatcher matcher, IProgressMonitor monitor) + public BatchFixer (IActionMatcher matcher, ProgressMonitor monitor) { this.matcher = matcher; this.monitor = monitor; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/Runner/ProgressMonitorWrapperJob.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/Runner/ProgressMonitorWrapperJob.cs index 6557a3c04e..b1eea307cf 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/Runner/ProgressMonitorWrapperJob.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeIssues/Runner/ProgressMonitorWrapperJob.cs @@ -36,7 +36,7 @@ namespace MonoDevelop.CodeIssues { readonly IAnalysisJob wrappedJob; - IProgressMonitor monitor;
+ ProgressMonitor monitor;
int reportingThinningFactor = 100;
diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs index c39249dc12..cb6bf8acef 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs @@ -113,6 +113,10 @@ namespace MonoDevelop.Refactoring.Rename entry.Text = member.Name; } // fileName = member.Region.FileName; + } else if (options.SelectedItem is IType) { + var lvar = (IType)options.SelectedItem; + entry.Text = lvar.Name; + // this.fileName = lvar.Region.FileName; } else if (options.SelectedItem is ITypeParameter) { var lvar = (ITypeParameter)options.SelectedItem; entry.Text = lvar.Name; @@ -183,7 +187,7 @@ namespace MonoDevelop.Refactoring.Rename var properties = Properties; ((Widget)this).Destroy (); List<Change> changes = rename.PerformChanges (options, properties); - IProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor (this.Title, null); + ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor (this.Title, null); RefactoringService.AcceptChanges (monitor, changes); } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs index 7a3cf5a6c3..2faf66fb59 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameRefactoring.cs @@ -89,7 +89,7 @@ namespace MonoDevelop.Refactoring.Rename new RenameRefactoring ().Run (options); return; } - using (var monitor = new NullProgressMonitor ()) { + using (var monitor = new ProgressMonitor ()) { var col = ReferenceFinder.FindReferences (entity, true, monitor); List<Change> result = new List<Change> (); @@ -110,7 +110,7 @@ namespace MonoDevelop.Refactoring.Rename public static void RenameVariable (IVariable variable, string newName) { - using (var monitor = new NullProgressMonitor ()) { + using (var monitor = new ProgressMonitor ()) { var col = ReferenceFinder.FindReferences (variable, true, monitor); List<Change> result = new List<Change> (); @@ -139,7 +139,7 @@ namespace MonoDevelop.Refactoring.Rename return; } - using (var monitor = new NullProgressMonitor ()) { + using (var monitor = new ProgressMonitor ()) { var col = ReferenceFinder.FindReferences (typeParameter, true, monitor); List<Change> result = new List<Change> (); @@ -160,7 +160,7 @@ namespace MonoDevelop.Refactoring.Rename public static void RenameNamespace (INamespace ns, string newName) { - using (var monitor = new NullProgressMonitor ()) { + using (var monitor = new ProgressMonitor ()) { var col = ReferenceFinder.FindReferences (ns, true, monitor); List<Change> result = new List<Change> (); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Change.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Change.cs index 0f3805e639..3b09f630f7 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Change.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/Change.cs @@ -47,7 +47,7 @@ namespace MonoDevelop.Refactoring { } - public abstract void PerformChange (IProgressMonitor monitor, RefactoringOptions rctx); + public abstract void PerformChange (ProgressMonitor monitor, RefactoringOptions rctx); } public class TextReplaceChange : Change @@ -118,7 +118,7 @@ namespace MonoDevelop.Refactoring return GetTextEditorData (FileName); } } - public override void PerformChange (IProgressMonitor monitor, RefactoringOptions rctx) + public override void PerformChange (ProgressMonitor monitor, RefactoringOptions rctx) { if (rctx == null) throw new InvalidOperationException ("Refactory context not available."); @@ -177,11 +177,11 @@ namespace MonoDevelop.Refactoring this.Description = string.Format (GettextCatalog.GetString ("Create file '{0}'"), Path.GetFileName (fileName)); } - public override void PerformChange (IProgressMonitor monitor, RefactoringOptions rctx) + public override void PerformChange (ProgressMonitor monitor, RefactoringOptions rctx) { File.WriteAllText (FileName, Content); rctx.Document.Project.AddFile (FileName); - IdeApp.ProjectOperations.Save (rctx.Document.Project); + IdeApp.ProjectOperations.SaveAsync (rctx.Document.Project); } } @@ -198,7 +198,7 @@ namespace MonoDevelop.Refactoring this.Description = string.Format (GettextCatalog.GetString ("Open file '{0}'"), Path.GetFileName (fileName)); } - public override void PerformChange (IProgressMonitor monitor, RefactoringOptions rctx) + public override void PerformChange (ProgressMonitor monitor, RefactoringOptions rctx) { IdeApp.Workbench.OpenDocument (FileName); } @@ -227,7 +227,7 @@ namespace MonoDevelop.Refactoring this.Description = string.Format (GettextCatalog.GetString ("Rename file '{0}' to '{1}'"), Path.GetFileName (oldName), Path.GetFileName (newName)); } - public override void PerformChange (IProgressMonitor monitor, RefactoringOptions rctx) + public override void PerformChange (ProgressMonitor monitor, RefactoringOptions rctx) { if (rctx == null) throw new ArgumentNullException ("rctx"); @@ -235,7 +235,7 @@ namespace MonoDevelop.Refactoring if (IdeApp.ProjectOperations.CurrentSelectedSolution != null) { foreach (var p in IdeApp.ProjectOperations.CurrentSelectedSolution.GetAllProjects ()) { if (p.GetProjectFile (NewName) != null) - IdeApp.ProjectOperations.Save (p); + IdeApp.ProjectOperations.SaveAsync (p); } } } @@ -254,9 +254,9 @@ namespace MonoDevelop.Refactoring this.Description = string.Format (GettextCatalog.GetString ("Save project {0}"), project.Name); } - public override void PerformChange (IProgressMonitor monitor, RefactoringOptions rctx) + public override void PerformChange (ProgressMonitor monitor, RefactoringOptions rctx) { - IdeApp.ProjectOperations.Save (this.Project); + IdeApp.ProjectOperations.SaveAsync (this.Project); } } } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewDialog.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewDialog.cs index ecfbf2e593..0f98ee8010 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewDialog.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringPreviewDialog.cs @@ -87,7 +87,7 @@ namespace MonoDevelop.Refactoring }; buttonOk.Clicked += delegate { - IProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor (this.Title, null); + ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor (this.Title, null); RefactoringService.AcceptChanges (monitor, changes); Destroy (); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs index d91b6f9a6d..1d9353ba5e 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs @@ -156,12 +156,12 @@ namespace MonoDevelop.Refactoring } } - public static void AcceptChanges (IProgressMonitor monitor, List<Change> changes) + public static void AcceptChanges (ProgressMonitor monitor, List<Change> changes) { AcceptChanges (monitor, changes, MonoDevelop.Ide.TextFileProvider.Instance); } - public static void AcceptChanges (IProgressMonitor monitor, List<Change> changes, MonoDevelop.Projects.Text.ITextFileProvider fileProvider) + public static void AcceptChanges (ProgressMonitor monitor, List<Change> changes, MonoDevelop.Projects.Text.ITextFileProvider fileProvider) { var rctx = new RefactoringOptions (null); var handler = new RenameHandler (changes); @@ -199,6 +199,9 @@ namespace MonoDevelop.Refactoring return inspectors.Where (i => i.MimeType == mimeType); } + static Stopwatch validActionsWatch = new Stopwatch (); + static Stopwatch actionWatch = new Stopwatch (); + public static Task<IEnumerable<CodeAction>> GetValidActions (Document doc, TextLocation loc, CancellationToken cancellationToken = default (CancellationToken)) { var editor = doc.Editor; @@ -207,6 +210,8 @@ namespace MonoDevelop.Refactoring var result = new List<CodeAction> (); var timer = InstrumentationService.CreateTimerCounter ("Source analysis background task", "Source analysis"); timer.BeginTiming (); + validActionsWatch.Restart (); + var timeTable = new Dictionary<CodeActionProvider, long> (); try { var parsedDocument = doc.ParsedDocument; if (editor != null && parsedDocument != null && parsedDocument.CreateRefactoringContext != null) { @@ -217,7 +222,10 @@ namespace MonoDevelop.Refactoring disabledNodes.IndexOf (fix.IdString, StringComparison.Ordinal) < 0)) { try { + actionWatch.Restart (); result.AddRange (provider.GetActions (doc, ctx, loc, cancellationToken)); + actionWatch.Stop (); + timeTable[provider] = actionWatch.ElapsedMilliseconds; } catch (Exception ex) { LoggingService.LogError ("Error in context action provider " + provider.Title, ex); } @@ -228,6 +236,14 @@ namespace MonoDevelop.Refactoring LoggingService.LogError ("Error in analysis service", ex); } finally { timer.EndTiming (); + validActionsWatch.Stop (); + if (validActionsWatch.ElapsedMilliseconds > 1000) { + LoggingService.LogWarning ("Warning slow edit action update."); + foreach (var pair in timeTable) { + if (pair.Value > 50) + LoggingService.LogInfo ("ACTION '" + pair.Key.Title + "' took " + pair.Value +"ms"); + } + } } return (IEnumerable<CodeAction>)result; }, cancellationToken); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/ResolveCommandHandler.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/ResolveCommandHandler.cs index bb4555eb46..97ab500655 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/ResolveCommandHandler.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/ResolveCommandHandler.cs @@ -202,9 +202,12 @@ namespace MonoDevelop.Refactoring var unit = SyntaxTree.Parse (CreateStub (doc, offset), doc.FileName); + var parsedDocument = doc.ParsedDocument; + if (parsedDocument == null) + return null; return ResolveAtLocation.Resolve ( doc.Compilation, - doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile, + parsedDocument.ParsedFile as CSharpUnresolvedFile, unit, location, out node); @@ -276,14 +279,14 @@ namespace MonoDevelop.Refactoring if (OnlyAddReference) return GettextCatalog.GetString ( "Reference '{0}'", - GetLibraryName ()); + GetLibraryName ().Replace ("_", "__")); if (Reference != null) return GettextCatalog.GetString ( "Reference '{0}' and use '{1}'", GetLibraryName (), - string.Format ("using {0};", Namespace)); + string.Format ("using {0};", Namespace.Replace ("_", "__"))); - return string.Format ("using {0};", Namespace); + return string.Format ("using {0};", Namespace.Replace ("_", "__")); } public string GetInsertNamespaceText (string member) @@ -291,10 +294,10 @@ namespace MonoDevelop.Refactoring if (Reference != null) return GettextCatalog.GetString ( "Reference '{0}' and use '{1}'", - GetLibraryName (), - Namespace + "." + member + GetLibraryName ().Replace ("_", "__"), + (Namespace + "." + member).Replace ("_", "__") ); - return Namespace + "." + member; + return (Namespace + "." + member).Replace ("_", "__"); } } @@ -338,14 +341,14 @@ namespace MonoDevelop.Refactoring var compilations = new List<Tuple<ICompilation, MonoDevelop.Projects.ProjectReference>> (); compilations.Add (Tuple.Create (doc.Compilation, (MonoDevelop.Projects.ProjectReference)null)); - var referencedItems = IdeApp.Workspace != null ? project.GetReferencedItems (IdeApp.Workspace.ActiveConfiguration).ToList () : (IEnumerable<SolutionItem>) new SolutionItem[0]; + var referencedItems = IdeApp.Workspace != null ? project.GetReferencedItems (IdeApp.Workspace.ActiveConfiguration).ToList () : (IEnumerable<SolutionFolderItem>) new SolutionFolderItem[0]; var solution = project != null ? project.ParentSolution : null; if (solution != null) { foreach (var curProject in solution.GetAllProjects ()) { if (curProject == project || referencedItems.Contains (curProject)) continue; - var otherRefes = IdeApp.Workspace != null ? curProject.GetReferencedItems (IdeApp.Workspace.ActiveConfiguration).ToList () : (IEnumerable<SolutionItem>) new SolutionItem[0]; + var otherRefes = IdeApp.Workspace != null ? curProject.GetReferencedItems (IdeApp.Workspace.ActiveConfiguration).ToList () : (IEnumerable<SolutionFolderItem>) new SolutionFolderItem[0]; if (otherRefes.Contains (project)) continue; @@ -540,7 +543,7 @@ namespace MonoDevelop.Refactoring if (reference != null) { var project = doc.Project; project.Items.Add (reference); - IdeApp.ProjectOperations.Save (project); + IdeApp.ProjectOperations.SaveAsync (project); } if (string.IsNullOrEmpty (ns)) |