# 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 errors, along with the reason for the error. The result of this service is used by the Orion UI to create error annotations in the ruler beside each problematic line.

## 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 an `errors` property whose value is an array giving the errors found in the file. Each error object must have the properties:

  reason `String` A description of the error.
  line `Number` Gives the line number where the error was found. (Line numbers begin counting from 1.)
  character `Number` Gives the column within the line where the error was found. (Not currently displayed in the Orion UI).

## Service attributes

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

pattern
  `String` A regular expression pattern matching the filenames 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 errors = [];
           var lines = contents.split(/\r?\n/);
           for (var i=0; i < lines.length; i++) {
             var line = lines[i];
             var match = /\t \t| \t /.exec(line);
             if (match) {
               errors.push({ reason: "Mixed spaces and tabs", line: i+1, character: match.index });
             }
           }
           var result = { errors: errors };
           return result;
         }
      },
      {
         pattern: "\\.(txt|js)$"
      });<!--
    service.dispatchEvent = serviceProvider.dispatchEvent;-->
    provider.connect();

This example will validate `.txt` and `.js` files. It finds lines containing a sequence of space-tab-space or tab-space-tab and produces an error on every such line.