0

I am writing my custom parser and after validation i am adding information to Error list of Visual studio using "error task" and "error service Provider". It's adding my custom error to error list window. but when i recompile again it adds up the error to the window. if it was 2 before and now is 3 the it shows ac-cumulatively. Is there any way that i can clear those error items from error list window before i add another.

 _errorListProvider.Tasks.Add(new ErrorTask
            {
                Category = TaskCategory.User,
                ErrorCategory = category,
                HelpKeyword = "Automation Id Help text",
                Line = 12,
                Column = 12,
                Text = message
            });

i would appreciate any help on this.

shekhar Kumar
  • 409
  • 4
  • 13

2 Answers2

1
_errorListProvider.Tasks.Clear()

But it won't work if you are crating provider every time you want to add error. So, you need to have it somewhere as variable you can access when you need.

Vic Hytyk
  • 26
  • 1
0

If you also want to remove the errors automatically when the project from where the errors occurred is closed or when the solution is closed, you can do something like this:

public void RemoveErrors(IVsHierarchy aHierarchy)
{
  SuspendRefresh();

  for (int i = errorListProvider.Tasks.Count - 1; i >= 0; --i)
  {
    var errorTask = errorListProvider.Tasks[i] as ErrorTask;
    aHierarchy.GetCanonicalName(Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT, out string nameInHierarchy);
    errorTask.HierarchyItem.GetCanonicalName(Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT, out string nameErrorTaskHierarchy);
    if (nameInHierarchy == nameErrorTaskHierarchy)
    {
      errorTask.Navigate -= ErrorTaskNavigate;
      errorListProvider.Tasks.Remove(errorTask);
    }
  }

  ResumeRefresh();
}

If you will remove more errors from the error list or you will add more errors in the error list you can use SuspendRefresh() and ResumeRefresh() methods to speed up the process. Your operations will be faster then before because usually the error list is refreshed after every remove or add operation.

Ionut Enache
  • 461
  • 8
  • 22
  • Hi @Ionut. This is how I'm doing things everytime the user transforms a file in the project that may cause errors. Because if he transforms a second time, I need to remove any previous error to produce any new ones. The problem is that the errors never actually disappear from the error list window. Any idea? – Hugo Quintela Ribeiro Oct 18 '18 at 14:33