开发者

Visual Studio 2010 plugin / code to clear "Error List" warnings before each build

开发者 https://www.devze.com 2023-04-12 21:40 出处:网络
VS2010 is driving me nuts: whenev开发者_如何学运维er I rebuild, the \"Error List\" warnings from the previous compilation are persisted and any new warnings are simply added to the end of the list. Ov

VS2010 is driving me nuts: whenev开发者_如何学运维er I rebuild, the "Error List" warnings from the previous compilation are persisted and any new warnings are simply added to the end of the list. Over time, this list becomes ridiculously long and unwieldy.

I'm using the Chirpy 2.0 tools to run JSHint and JSLint on my JS files, and these tools generate a lot of false positives.

I've been looking for an easy way to clear the contents of this window, but the only manual mechanism that works 100% of the time is to close and re-open the solution. Not very elegant.

I'd like to write a small VS Plug-In or some code that gets called right before a compilation to clear out this list so I can focus only on new warnings for the currently loaded file(s).

I see a .Clear() method for the Output window but not for the Error List. Is this doable?


Once upon a time I was an Add-In/VSIX Package/MEF developer ...

The answer is shortly no, but I have to do it on the long way:

Add-Ins, packages (Managed or not) have access to the VS service level separatedly. Every error belongs to the reporter (If they are manage them as Chirpy do), so you can not handle the errors created by Chirpy 2.0

I take a several look to it's source code and it is persist it's erros gained by the tools in a Singleton collection called TaskList.

The deletion of the collection elements is happening in several point of code in the latest release through the RemoveAll method:

  1. First: after the soulution is closed.

  2. by this:

private static string[] buildCommands = new[] { "Build.BuildSelection", "Build.BuildSolution", "ClassViewContextMenus.ClassViewProject.Build" };

    private void CommandEvents_BeforeExecute(string guid, int id, object customIn, object customOut, ref bool cancelDefault) {
            EnvDTE.Command objCommand = default(EnvDTE.Command);
            string commandName = null;

            try {
                objCommand = this.App.Commands.Item(guid, id);
            } catch (System.ArgumentException) {
            }

            if (objCommand != null) {
                commandName = objCommand.Name;

                var settings = new Settings();
                if (settings.T4RunAsBuild) {
                    if (buildCommands.Contains(commandName)) {
                        if (this.tasks != null) {
                            this.tasks.RemoveAll();
                        }

                        Engines.T4Engine.RunT4Template(this.App, settings.T4RunAsBuildTemplate);
                    }
                }
            }
        }

As you may see, clear of results depends on many thigs. First on a setting (which I don't know where to set on GUI or configs, but seems to get its value form a check box). Second the array of names which are not contains every build commands name.

So I see a solution, but only on the way to modify and rebuild/redepeloy your own version from Chirpy (and make a Pull request):

The code souldn't depend on the commands, and their names. (rebuilds are missing for example)

You could change the method above something like this:

this.eventsOnBuild.OnBuildBegin += ( scope, action ) =>
{
    if (action != vsBuildAction.vsBuildActionDeploy)
    {
        if (this.tasks != null)
        {
            this.tasks.RemoveAll();
        }

        if (settings.T4RunAsBuild && action != vsBuildAction.vsBuildActionClean)
        {
           Engines.T4Engine.RunT4Template(this.App, settings.T4RunAsBuildTemplate);
        }
    }
};

Or with something equivalent handler method instead of lambda expression. You shold place it into the subscription OnStartupComplete method of Chirp class.

The unsubscription have to placed into OnDisconnection method in the same class. (As for all other subscribed handlers...)

Update:

When an Add-In disconneced, it isn't means the Studio will be closed immediately. The Add-In could be unloaded. So you should call the RemoveAll from OnDisconneconnection too. (Or Remove and Dispose the TaskList...)

Update2:

You can also make a custom command, and bind it to a hotkey.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号