自定义输出=> VS2008 IDE中的错误解释列表

发布于 2024-08-24 18:32:20 字数 636 浏览 13 评论 0原文

我在 VS2008 中有一个“数据库解决方案”项目 - 它从某种模板为多个数据库供应商生成 SQL。为了节省时间,我还在VS2008中配置了一个工具(一个Python脚本),它可以编译单独的存储过程。现在,通过 Python 脚本,我可以自由地处理输出并使其呈现出我想要的任何形式。我正在考虑以某种方式识别这些错误和警告并填充可点击的错误/警告列表。这是典型的 Oracle 错误的样子:

LINE/COL ERROR
-------- -----------------------------------------------------------------
324/5    PL/SQL: Statement ignored
324/82   PLS-00363: expression 'VSOURCE_SYSTEM_ID' cannot be used as an
     assignment target
Warning: Procedure created with compilation errors.
PROCEDURE: ADD_PROPOSED error on creation
Errors for PROCEDURE ADD_PROPOSED:
LINE/COL ERROR

这可能是一个不太可能的事情,但对我来说是值得的。我经常做这种事。谢谢你!

I have a "database solution" project in VS2008 - it generates SQL for more than one DB vendor from some sort of templates. In order to save time, I also have a tool in VS2008 configured (a Python script), which can compile an individual stored procedure. Now, with the Python script I have the freedom of processing the output and have it take on whatever form I want. I am toying with an idea of having these errors and warnings somehow recognized and populating the click-able Error / Warning list. This is what a typical Oracle error looks like:

LINE/COL ERROR
-------- -----------------------------------------------------------------
324/5    PL/SQL: Statement ignored
324/82   PLS-00363: expression 'VSOURCE_SYSTEM_ID' cannot be used as an
     assignment target
Warning: Procedure created with compilation errors.
PROCEDURE: ADD_PROPOSED error on creation
Errors for PROCEDURE ADD_PROPOSED:
LINE/COL ERROR

This might be a long shot, but it is worthwhile for me. I do this stuff a lot. Thank you!

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

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

发布评论

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

评论(1

山田美奈子 2024-08-31 18:32:20

IVsSingleFileGenerator 接口有一个方法调用 void 生成(...) 具有 IVsGeneratorProgress。此接口有一个方法 void GeneratorError( ),它允许您向 Visual Studio 错误列表报告错误和警告。 GenerateError() 在其他参数中接受一行和一列,因此我假设双击您的自定义错误会将您带到源文件中的适当位置。

为了将它们整合在一起,我会执行如下操作:

public class MyGenerator : IVsSingleFileGenerator
{
   public Generate(string path, string inputContents, string namespace, IntPtr[] outputContents, out unit outputLength, IVsGeneratorProgress progress)
   {
      // Invoke your Python script

      // Parse the error output from either a file or structure
      // Assume you generate two lists: one for warnings, one for errors

      foreach (var error in PythonErrors)
        progress.GenerateError(false, 0, error.Text, error.Line, error.Column);

      foreach (var warning in PythonErrors)
         progress.GenerateError(true, 0, warning.Text, warning.Line, warning.Colum);
   }
}

将其编译成程序集。 (我不清楚这应该是 EXE 还是 DLL,但我怀疑它们都可以工作,因为您有一个实现正确接口的类。)然后转到项目中每个 SQL 文件的属性并关联 MyGenerator用它定制工具。编译项目时,Visual Studio 现在应该运行自定义工具并在错误窗口中生成输出。

The IVsSingleFileGenerator interface has a method call void Generate(...) which has a parameter of the type IVsGeneratorProgress. This interface has a method void GeneratorError() which lets you report errors and warnings to the Visual Studio error list. GenerateError() takes a line and a column among other parameters so I assume double clicking your custom error will take you to the appropriate location in your source file.

To pull it all together, I'd do something like the following:

public class MyGenerator : IVsSingleFileGenerator
{
   public Generate(string path, string inputContents, string namespace, IntPtr[] outputContents, out unit outputLength, IVsGeneratorProgress progress)
   {
      // Invoke your Python script

      // Parse the error output from either a file or structure
      // Assume you generate two lists: one for warnings, one for errors

      foreach (var error in PythonErrors)
        progress.GenerateError(false, 0, error.Text, error.Line, error.Column);

      foreach (var warning in PythonErrors)
         progress.GenerateError(true, 0, warning.Text, warning.Line, warning.Colum);
   }
}

Compile this into an assembly. (I'm unclear if this is supposed to be an EXE or DLL, but I suspect either will work since you have a class that implements the right interface.) Then go to the properties of each SQL file in your project and associate the MyGenerator custom tool with it. When you compile the project Visual Studio should now run your custom tool and generate output in the error window.

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