diff options
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/CommentTasksChangedEventHandler.cs | 10 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/CommentTasksView.cs | 142 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/ProjectCommentTags.cs | 83 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskListEntry.cs (renamed from main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/UserTask.cs) | 22 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskService.cs | 6 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskStore.cs | 52 |
6 files changed, 211 insertions, 104 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/CommentTasksChangedEventHandler.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/CommentTasksChangedEventHandler.cs index 514601b9f1..945cd9a5fb 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/CommentTasksChangedEventHandler.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/CommentTasksChangedEventHandler.cs @@ -33,11 +33,11 @@ namespace MonoDevelop.Ide.Tasks { public class CommentTasksChangedEventArgs : EventArgs { - string filename; - IList<Tag> tagComments; - Project project; + readonly string filename; + readonly IReadOnlyList<Tag> tagComments; + readonly Project project; - public CommentTasksChangedEventArgs (string filename, IList<Tag> tagComments, Project project) + public CommentTasksChangedEventArgs (string filename, IReadOnlyList<Tag> tagComments, Project project) { this.filename = filename; this.tagComments = tagComments; @@ -46,7 +46,7 @@ namespace MonoDevelop.Ide.Tasks public string FileName { get { return filename; } } - public IList<Tag> TagComments { get { return tagComments; } } + public IReadOnlyList<Tag> TagComments { get { return tagComments; } } public Project Project { get { return project; } } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/CommentTasksView.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/CommentTasksView.cs index b01e917033..509f2998b7 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/CommentTasksView.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/CommentTasksView.cs @@ -36,10 +36,11 @@ using MonoDevelop.Core; using MonoDevelop.Projects; using MonoDevelop.Ide; using MonoDevelop.Ide.Gui; -using MonoDevelop.Projects.Text; using MonoDevelop.Ide.TypeSystem; -using ICSharpCode.NRefactory.TypeSystem; using System.Linq; +using MonoDevelop.Ide.Editor; +using System.Threading; +using System.Threading.Tasks; namespace MonoDevelop.Ide.Tasks { @@ -83,9 +84,12 @@ namespace MonoDevelop.Ide.Tasks TaskService.CommentTasksChanged += OnCommentTasksChanged; CommentTag.SpecialCommentTagsChanged += OnCommentTagsChanged; - IdeApp.Workspace.WorkspaceItemLoaded += OnWorkspaceItemLoaded; + + MonoDevelopWorkspace.LoadingFinished += OnWorkspaceItemLoaded; IdeApp.Workspace.WorkspaceItemUnloaded += OnWorkspaceItemUnloaded; - + IdeApp.Workbench.DocumentOpened += WorkbenchDocumentOpened; + IdeApp.Workbench.DocumentClosed += WorkbenchDocumentClosed;; + highPrioColor = StringToColor ((string)PropertyService.Get ("Monodevelop.UserTasksHighPrioColor", "")); normalPrioColor = StringToColor ((string)PropertyService.Get ("Monodevelop.UserTasksNormalPrioColor", "")); lowPrioColor = StringToColor ((string)PropertyService.Get ("Monodevelop.UserTasksLowPrioColor", "")); @@ -124,15 +128,8 @@ namespace MonoDevelop.Ide.Tasks col.Resizable = true; LoadColumnsVisibility (); - - comments.BeginTaskUpdates (); - try { - foreach (var item in IdeApp.Workspace.Items) { - LoadWorkspaceItemContents (item); - } - } finally { - comments.EndTaskUpdates (); - } + + OnWorkspaceItemLoaded (null, EventArgs.Empty); comments.TasksAdded += GeneratedTaskAdded; comments.TasksRemoved += GeneratedTaskRemoved; @@ -147,7 +144,7 @@ namespace MonoDevelop.Ide.Tasks view.RowActivated -= OnRowActivated; TaskService.CommentTasksChanged -= OnCommentTasksChanged; CommentTag.SpecialCommentTagsChanged -= OnCommentTagsChanged; - IdeApp.Workspace.WorkspaceItemLoaded -= OnWorkspaceItemLoaded; + MonoDevelopWorkspace.LoadingFinished -= OnWorkspaceItemLoaded; IdeApp.Workspace.WorkspaceItemUnloaded -= OnWorkspaceItemUnloaded; comments.TasksAdded -= GeneratedTaskAdded; comments.TasksRemoved -= GeneratedTaskRemoved; @@ -156,6 +153,38 @@ namespace MonoDevelop.Ide.Tasks }; } + void WorkbenchDocumentClosed (object sender, DocumentEventArgs e) + { + e.Document.DocumentParsed -= HandleDocumentParsed; + } + + void WorkbenchDocumentOpened (object sender, DocumentEventArgs e) + { + e.Document.DocumentParsed += HandleDocumentParsed; + } + + void HandleDocumentParsed (object sender, EventArgs e) + { + var doc = (Document)sender; + var pd = doc.ParsedDocument; + var project = doc.Project; + if (pd == null || project == null) + return; + ProjectCommentTags tags; + if (!projectTags.TryGetValue (project, out tags)) + return; + var token = src.Token; + var file = doc.FileName; + Task.Run (async () => { + try { + tags.UpdateTags (project, file, await pd.GetTagCommentsAsync (token)); + } catch (TaskCanceledException) { + } catch (AggregateException ae) { + ae.Flatten ().Handle (x => x is TaskCanceledException); + } + }); + } + void LoadColumnsVisibility () { string columns = (string)PropertyService.Get ("Monodevelop.CommentTasksColumns", "TRUE;TRUE;TRUE;TRUE"); @@ -181,76 +210,66 @@ namespace MonoDevelop.Ide.Tasks PropertyService.Set ("Monodevelop.CommentTasksColumns", columns); } - void OnWorkspaceItemLoaded (object sender, WorkspaceItemEventArgs e) + void OnWorkspaceItemLoaded (object sender, EventArgs e) { comments.BeginTaskUpdates (); try { - LoadWorkspaceItemContents (e.Item); + foreach (var sln in IdeApp.Workspace.GetAllSolutions ()) + LoadSolutionContents (sln); } finally { comments.EndTaskUpdates (); } } - - void LoadWorkspaceItemContents (WorkspaceItem wob) - { - foreach (var sln in wob.GetAllItems<Solution> ()) - LoadSolutionContents (sln); - } - void UpdateCommentTagsForProject (Solution solution, Project project) + Dictionary<Project, ProjectCommentTags> projectTags = new Dictionary<Project, ProjectCommentTags> (); + CancellationTokenSource src = new CancellationTokenSource (); + void UpdateCommentTagsForProject (Solution solution, Project project, CancellationToken token) { - var ctx = TypeSystemService.GetProjectContentWrapper (project); - if (ctx == null) + if (token.IsCancellationRequested) return; - var tags = ctx.GetExtensionObject<ProjectCommentTags> (); - if (tags == null) { + ProjectCommentTags tags; + if (!projectTags.TryGetValue (project, out tags)) { tags = new ProjectCommentTags (); - ctx.UpdateExtensionObject (tags); - tags.Update (ctx.Project); - } else { - foreach (var kv in tags.Tags) { - UpdateCommentTags (solution, kv.Key, kv.Value); - } + projectTags [project] = tags; } - } - - void HandleSolutionItemAdded (object sender, SolutionItemChangeEventArgs e) - { - var newProject = e.SolutionItem as Project; - if (newProject == null) - return; - UpdateCommentTagsForProject (e.Solution, newProject); + var files = project.Files.ToArray (); + Task.Run (async () => { + try { + await tags.UpdateAsync (project, files, token); + } catch (TaskCanceledException) { + } catch (AggregateException ae) { + ae.Flatten ().Handle (x => x is TaskCanceledException); + } catch (Exception e) { + LoggingService.LogError ("Error while updating comment tags.", e); + } + }); } void LoadSolutionContents (Solution sln) { + src.Cancel (); + src = new CancellationTokenSource (); + var token = src.Token; + loadedSlns.Add (sln); - System.Threading.ThreadPool.QueueUserWorkItem (delegate { - sln.SolutionItemAdded += HandleSolutionItemAdded; + Task.Run (delegate { + sln.SolutionItemAdded += delegate(object sender, SolutionItemChangeEventArgs e) { + var newProject = e.SolutionItem as Project; + if (newProject == null) + return; + UpdateCommentTagsForProject (sln, newProject, token); + }; // Load all tags that are stored in pidb files foreach (Project p in sln.GetAllProjects ()) { - UpdateCommentTagsForProject (sln, p); + UpdateCommentTagsForProject (sln, p, token); } }); } - - static IEnumerable<Tag> GetSpecialComments (IProjectContent ctx, string name) - { - var doc = ctx.GetFile (name) as ParsedDocument; - if (doc == null) - return Enumerable.Empty<Tag> (); - return (IEnumerable<Tag>)doc.TagComments; - } - void OnWorkspaceItemUnloaded (object sender, WorkspaceItemEventArgs e) { - foreach (var sln in e.Item.GetAllItems<Solution>()) { - if (loadedSlns.Remove (sln)) - sln.SolutionItemAdded -= HandleSolutionItemAdded; - } comments.RemoveItemTasks (e.Item, true); } @@ -506,7 +525,7 @@ namespace MonoDevelop.Ide.Tasks { TaskListEntry task = SelectedTask; if (task != null && ! String.IsNullOrEmpty (task.FileName)) { - Document doc = IdeApp.Workbench.OpenDocument (task.FileName, Math.Max (1, task.Line), Math.Max (1, task.Column)); + var doc = IdeApp.Workbench.OpenDocument (task.FileName, Math.Max (1, task.Line), Math.Max (1, task.Column)); if (doc != null && doc.HasProject && doc.Project is DotNetProject) { string[] commentTags = doc.CommentTags; if (commentTags != null && commentTags.Length == 1) { @@ -515,10 +534,11 @@ namespace MonoDevelop.Ide.Tasks string line = doc.Editor.GetLineText (task.Line); int index = line.IndexOf (commentTags[0]); if (index != -1) { - doc.Editor.SetCaretTo (task.Line, task.Column); + doc.Editor.CaretLocation = new DocumentLocation (task.Line, task.Column); + doc.Editor.StartCaretPulseAnimation (); line = line.Substring (0, index); - var ls = doc.Editor.Document.GetLine (task.Line); - doc.Editor.Replace (ls.Offset, ls.Length, line); + var ls = doc.Editor.GetLine (task.Line); + doc.Editor.ReplaceText (ls.Offset, ls.Length, line); comments.Remove (task); } }); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/ProjectCommentTags.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/ProjectCommentTags.cs new file mode 100644 index 0000000000..9f9fcb9476 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/ProjectCommentTags.cs @@ -0,0 +1,83 @@ +// +// ProjectCommentTags.cs +// +// Author: +// Mike Krüger <mkrueger@xamarin.com> +// +// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Collections.Concurrent; +using MonoDevelop.Projects; +using MonoDevelop.Ide.Tasks; +using System.Threading; +using MonoDevelop.Ide.TypeSystem; +using System.Threading.Tasks; + +namespace MonoDevelop.Ide.Tasks +{ + class ProjectCommentTags + { + readonly Dictionary<string, List<Tag>> tags = new Dictionary<string, List<Tag>> (); + + public IDictionary<string, List<Tag>> Tags { + get { + return tags; + } + } + + public void UpdateTags (Project project, string fileName, IReadOnlyList<Tag> tagComments) + { + var list = tagComments == null || tagComments.Count == 0 ? null : new List<Tag> (tagComments); + lock (tags) { + List<Tag> oldList; + tags.TryGetValue (fileName, out oldList); + if (list == null && oldList == null) + return; + tags[fileName] = list; + TaskService.InformCommentTasks (new CommentTasksChangedEventArgs (fileName, tagComments, project)); + } + } + + public void RemoveFile (Project project, string fileName) + { + lock (tags) { + if (!tags.ContainsKey (fileName)) + return; + tags[fileName] = null; + } + + TaskService.InformCommentTasks (new CommentTasksChangedEventArgs (fileName, null, project)); + } + + internal async Task UpdateAsync (Project project, ProjectFile[] files, CancellationToken token = default (CancellationToken)) + { + foreach (var file in files) { + if (file.BuildAction == BuildAction.None) + continue; + var pd = await TypeSystemService.ParseFile (project, file.FilePath, token).ConfigureAwait (false); + if (pd != null) + UpdateTags (project, file.FilePath, await pd.GetTagCommentsAsync (token)); + } + } + } +}
\ No newline at end of file diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/UserTask.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskListEntry.cs index 9ddda8db4d..fb8db5ea77 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/UserTask.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskListEntry.cs @@ -1,5 +1,5 @@ // -// Task.cs +// TaskListEntry.cs // // Author: // Lluis Sanchez Gual <lluis@novell.com> @@ -31,7 +31,7 @@ using System.CodeDom.Compiler; using MonoDevelop.Projects; using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Gui.Components; -using MonoDevelop.Ide.Gui.Pads.ProjectPad;
+using MonoDevelop.Ide.Gui.Pads.ProjectPad; using MonoDevelop.Core; using MonoDevelop.Core.Serialization; @@ -64,7 +64,7 @@ namespace MonoDevelop.Ide.Tasks bool completed; object owner; - WorkspaceObject parentObject; + IWorkspaceObject parentObject; internal int SavedLine; public TaskListEntry (FilePath file, string description, int column, int line, TaskSeverity severity) @@ -77,12 +77,12 @@ namespace MonoDevelop.Ide.Tasks { } - public TaskListEntry (FilePath file, string description, int column, int line, TaskSeverity severity, TaskPriority priority, WorkspaceObject parent) + public TaskListEntry (FilePath file, string description, int column, int line, TaskSeverity severity, TaskPriority priority, IWorkspaceObject parent) : this (file, description, column, line, severity, priority, parent, null) { } - public TaskListEntry (FilePath file, string description, int column, int line, TaskSeverity severity, TaskPriority priority, WorkspaceObject parent, object owner) + public TaskListEntry (FilePath file, string description, int column, int line, TaskSeverity severity, TaskPriority priority, IWorkspaceObject parent, object owner) { this.file = file; this.description = description; @@ -106,7 +106,7 @@ namespace MonoDevelop.Ide.Tasks public TaskListEntry (BuildError error, object owner) { - parentObject = error.SourceTarget as WorkspaceObject; + parentObject = error.SourceTarget; file = error.FileName; this.owner = owner; description = error.ErrorText; @@ -179,7 +179,7 @@ namespace MonoDevelop.Ide.Tasks } } - public WorkspaceObject WorkspaceObject { + public IWorkspaceObject WorkspaceObject { get { return parentObject; } @@ -224,17 +224,17 @@ namespace MonoDevelop.Ide.Tasks TaskService.InformJumpToTask (this); } - public bool BelongsToItem (WorkspaceObject item, bool checkHierarchy) + public bool BelongsToItem (IWorkspaceObject item, bool checkHierarchy) { if (!checkHierarchy) return item == parentObject; - WorkspaceObject cit = parentObject; + IWorkspaceObject cit = parentObject; do { if (cit == item) return true; - if (cit is SolutionFolderItem) { - SolutionFolderItem si = (SolutionFolderItem) cit; + if (cit is SolutionItem) { + SolutionItem si = (SolutionItem) cit; if (si.ParentFolder != null) cit = si.ParentFolder; else diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskService.cs index a00767d569..408d4189cb 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskService.cs @@ -54,8 +54,10 @@ namespace MonoDevelop.Ide.Tasks static TaskService () { - IdeApp.Workspace.WorkspaceItemLoaded += OnWorkspaceItemLoaded; - IdeApp.Workspace.WorkspaceItemUnloaded += OnWorkspaceItemUnloaded; + if (IdeApp.Workspace != null) { + IdeApp.Workspace.WorkspaceItemLoaded += OnWorkspaceItemLoaded; + IdeApp.Workspace.WorkspaceItemUnloaded += OnWorkspaceItemUnloaded; + } errors.ItemName = GettextCatalog.GetString ("Warning/Error"); userTasks.ItemName = GettextCatalog.GetString ("User Task"); } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskStore.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskStore.cs index 5bc6c0215d..7db2b7aef8 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskStore.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Tasks/TaskStore.cs @@ -23,17 +23,17 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -//------------------------------------------------------------------------------
-// <auto-generated>
-// This code was generated by a tool.
-// Runtime Version:2.0.50727.3074
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-using System;
+//------------------------------------------------------------------------------ +// <auto-generated> +// This code was generated by a tool. +// Runtime Version:2.0.50727.3074 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// </auto-generated> +//------------------------------------------------------------------------------ + +using System; using System.Collections; using System.Collections.Generic; using MonoDevelop.Core; @@ -42,12 +42,12 @@ using MonoDevelop.Ide.Gui; using MonoDevelop.Ide.Gui.Content; using MonoDevelop.Ide.Navigation; using MonoDevelop.Ide.TextEditing; -using MonoDevelop.Ide.Desktop;
-
-namespace MonoDevelop.Ide.Tasks
-{
- public class TaskStore: IEnumerable<TaskListEntry>, ILocationList
- {
+using MonoDevelop.Ide.Desktop; + +namespace MonoDevelop.Ide.Tasks +{ + public class TaskStore: IEnumerable<TaskListEntry>, ILocationList + { int taskUpdateCount; List<TaskListEntry> tasks = new List<TaskListEntry> (); Dictionary<FilePath,TaskListEntry[]> taskIndex = new Dictionary<FilePath, TaskListEntry[]> (); @@ -59,11 +59,13 @@ namespace MonoDevelop.Ide.Tasks List<TaskListEntry> tasksAdded; List<TaskListEntry> tasksRemoved; - public TaskStore ()
- {
- IdeApp.Workspace.FileRenamedInProject += ProjectFileRenamed; - IdeApp.Workspace.FileRemovedFromProject += ProjectFileRemoved; - + public TaskStore () + { + if (IdeApp.Workspace != null) { + IdeApp.Workspace.FileRenamedInProject += ProjectFileRenamed; + IdeApp.Workspace.FileRemovedFromProject += ProjectFileRemoved; + } + TextEditorService.LineCountChangesCommitted += delegate (object sender, TextFileEventArgs args) { foreach (TaskListEntry task in GetFileTasks (args.TextFile.Name.FullPath)) task.SavedLine = -1; @@ -198,7 +200,7 @@ namespace MonoDevelop.Ide.Tasks yield return t; } } -
+ public TaskListEntry[] GetFileTasks (FilePath file) { TaskListEntry[] ta; @@ -523,7 +525,7 @@ namespace MonoDevelop.Ide.Tasks } #endregion - }
+ } public delegate void TaskEventHandler (object sender, TaskEventArgs e); @@ -545,4 +547,4 @@ namespace MonoDevelop.Ide.Tasks get { return tasks; } } } -}
+} |