Previous: Redirecting the command output, Up: Executing external tools


16.6.4.6 Processing the tool output

The output of the tool has now either been hidden or made visible to the user in one or more windows.

There are several additional things that can be done with this output, for further integration of the tool in GPS.

  1. Parsing error messages External tools can usually display error messages for the user that are associated with specific files and locations in these files. This is for instance the way the GPS builder itself analyzes the output of make.

    This can be done for your own tools using the shell command Locations.parse. This command takes several arguments, so that you can specify your own regular expression to find the file name, line number and so on in the error message. By default, it is configured to work seamlessly with error message of the forms:

              file:line: message
              file:line:column: message
    

    Please refer to the online help for this command to get more information (by e.g. typing help Locations.parse in the GPS Shell).

    Here is a small example on how to run a make command and send the errors to the location window afterward.

    For languages that support it, it is also recommended that you quote the argument with triple quotes, so that any special character (newlines, quotes, ...) in the output of the tool are not specially interpreted by GPS. Note also that you should leave a space at the end, in case the output itself ends with a quote.

              <?xml version="1.0" ?>
              <make>
                <action name="make example" >
                   <external>make</external>
                   <on-failure>
                      <shell>Locations.parse """%1 """ make_example</shell>
                   </on-failure>
                </action>
              </make>
    
  2. Auto-correcting errors GPS has support for automatically correcting errors for some of the languages. You can get access to this auto-fixing feature through the Codefix.parse shell command, which takes the same arguments as for Locations.parse.

    This will automatically add pixmaps to the relevant entries in the location window, and therefore Locations.parse should be called first prior to calling this command.

    Errors can also be fixed automatically by calling the methods of the Codefix class. Several codefix sessions can be active at the same time, each of which is associated with a specific category. The list of currently active sessions can be retrieved through the Codefix.sessions() command.

    If support for python is enabled, you can also manipulate the fixable errors for a given session. To do so, you must first get a handle on that section, as shown in the example below. You can then get the list of fixable errors through the errors command.

    Each error is of the class CodefixError, which has one important method fix which allows you to perform an automatic fixing for that error. The list of possible fixes is retrieved through possible_fixes.

              print GPS.Codefix.sessions ()
              session = GPS.Codefix ("category")
              errors  = session.errors ()
              print errors [0].possible_fixes ()
              errors [0].fix ()