# orion.edit.validator

An `orion.edit.validator` service provides a function that can check the contents of a file and return a data structure indicating which lines (if any) have problems. The result of this service is used by the Orion UI to create annotations in the ruler beside each problematic line, and also to underline the specific portion of a line where the problem occurs.

## Service methods

Implementations of `orion.edit.validator` must define the following function:

checkSyntax(title, contents)
  title `String` The path and filename of the file being edited.
  contents `String` The contents of the file being edited.

Returns an `Object` giving the validation result. The returned object must have a `problems` property whose value is an array giving the problems found in the file. Each problem object must have the properties:

  description `String` A description of the problem.
  line `Number` Gives the line number where the problem was found. (Line numbers begin counting from 1.)
  start `Number` Gives the column within the line where the problem begins.
  end `Number` Optional Gives the column within the line where the problems ends. (If omitted, `start+1` is assumed.)
  severity `String` Optional Gives the severity of this problem. The severity affects how the problem is displayed in the Orion UI. Allowed values are `"warning"` and `"error"`. (If omitted, `"error"` is assumed.)

## Service attributes

Implementations of `orion.edit.validator` must define the following attributes:

contentType
  `Array` An array of Content Type IDs giving the types of files that this validator is capable of validating.

## Examples

    var provider = new eclipse.PluginProvider();
    var serviceProvider = provider.registerServiceProvider("orion.edit.validator",
      {
         checkSyntax: function(title, contents) {
           var problems = [];
           var lines = contents.split(/\r?\n/);
           for (var i=0; i < lines.length; i++) {
             var line = linesi;
             var match = /\t \t| \t /.exec(line);
             if (match) {
               problems.push({
                 description: "Mixed spaces and tabs",
                 line: i + 1,
                 start: match.index + 1,
                 end: match.index + match0.length + 1,
                 severity: "warning" });
             }
           }
           var result = { problems: problems };
           return result;
         }
      },
      {
         contentType: "application/javascript"
      });
    provider.connect();

This example will validate JavaScript files. It finds lines containing a sequence of space-tab-space or tab-space-tab and produces a warning on every such line. Note that `+1` is necessary because column and line indices in the Orion UI are numbered from 1, not 0.