用于清除“错误列表”的 Visual Studio 2010 插件/代码每次构建之前的警告

发布于 2024-12-09 02:57:35 字数 451 浏览 0 评论 0原文

VS2010 让我发疯:每当我重建时,先前编译的“错误列表”警告都会保留下来,并且任何新警告都会简单地添加到列表末尾。随着时间的推移,这个列表变得异常长且难以处理。

我使用 Chirpy 2.0 工具在 JS 文件上运行 JSHintJSLint,这些工具会生成大量误报。

我一直在寻找一种简单的方法来清除此窗口的内容,但唯一 100% 有效的手动机制是关闭并重新打开解决方案。不是很优雅。

我想编写一个小型 VS 插件或一些在编译之前调用的代码来清除此列表,这样我就可以只关注当前加载文件的新警告。

我在输出窗口中看到了 .Clear() 方法,但在错误列表中却没有。这可行吗?

VS2010 is driving me nuts: whenever 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初相遇 2024-12-16 02:57:35

曾几何时,我是一名外接程序/VSIX 包/MEF 开发人员...

答案很快是否定的,但我必须长期这样做:

外接程序、包(托管或非托管)可以访问VS服务级别分开。每个错误都属于报告者(如果他们像 Chirpy 那样管理它们),所以你无法处理 Chirpy 2.0 创建的错误

我仔细查看了它的源代码,它是持久的,它是由单例中的工具获得的错误称为任务列表的集合。

在最新版本中,通过RemoveAll 方法在多个代码点中删除集合元素:

  1. First:解决方案关闭后。

  2. 这样:

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);
                    }
                }
            }
        }

正如您所看到的,结果的清除取决于很多事情。
首先是设置(我不知道在 GUI 或配置上设置的位置,但似乎从复选框中获取其值)。
其次,名称数组不包含每个构建命令名称。

所以我看到了一个解决方案,但仅限于从 Chirpy 修改和重建/重新部署您自己的版本(并发出 Pull 请求):

代码不依赖于命令及其名称。 (例如缺少重建)

您可以更改上面的方法,如下所示:

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);
        }
    }
};

或者使用等效的处理程序方法而不是 lambda 表达式。
您应该将其放入 Chirp 类的订阅 OnStartupComplete 方法中。

取消订阅必须放入同一类中的 OnDisconnection 方法中。 (至于所有其他订阅的处理程序...)

更新:

当加载项断开连接时,并不意味着 Studio 将立即关闭。可以卸载该加载项。所以你也应该从 OnDisconneconnection 调用RemoveAll。 (或者删除并处理任务列表...)

更新2:

您还可以创建自定义命令,并将其绑定到热键。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文