开发者

Custom Output => List of Errors interpretation in VS2008 IDE

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!


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜