skip to Main Content

I’m writing an extension for Visual Studio 2022 using the Community.VisualStudio.Toolkit package and part of my extension writes errors to the Error List window. I’ve figured out how to populate all the other fields I want (Severity, Description, Project, and Line) but I can’t quite figure out how to write to the Code field.

I created an ErrorListProvider object from the Microsoft.VisualStudio.Shell package that I then add error messages to like so:

errorListProvider.Tasks.Add(new ErrorTask
{
    ErrorCategory = TaskErrorCategory.Warning,
    Text = error.Message,
    Document = error.FileName,
    Line = error.Line - 1, // error list uses 0 based indexing 
    Column = error.Column,
    HierarchyItem = hierarchy, // populates the 'Project' field in the error list
});

The only other fields that I can modify on the ErrorTask item are HelpKeyword and Category, which don’t seem to affect the Code field.

2

Answers


  1. Chosen as BEST ANSWER

    I accomplished this by making a class that implements ITableEntry and has a member variable errorCode

    public bool TryGetValue(string keyName, out object content)
    {
        switch (keyName)
        {
            case StandardTableKeyNames.ErrorCode:
                content = errorCode;
                return true;
            default:
                content = "";
                return false;
        }
    }
    
    public bool CanSetValue(string keyName)
    {
        switch (keyName)
        {
            case StandardTableKeyNames.ErrorCode:
                return true;
            default:
                return false;
        }
    }
    
    list.Add(new MyErrorListEntry()
    {
        errorCode = error.Code
    });
    

  2. Try to use the following code:

    errorListProvider.Tasks.Add(new ErrorTask
    {
        ErrorCategory = TaskErrorCategory.Warning,
        // Code field
        Code = error.ErrorCode,
    });
    

    For more information, please read documents:

    StandardTableKeyNames Fields

    ErrorCode Field

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search