# orion.edit.occurrences

The `orion.edit.occurrences` service allows plugins to compute identifier occurrences for specific content types.

## Service methods

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

computeOccurrences(editorContext, context)
  editorContext is an `orion.edit.EditorContext` object that contains all of the information about the current editor.
  context is an object that contains the current selection in the editor to find occurrences for.

The return value (or fulfillment value) is an Array of top-level occurrence objects, which will be automatically marked in the editor.

## The Occurrence object

Each occurrence object has these properties:

  start `Number` The offset into the file for the start of the occurrence
  end `Number` The offset into the file for the end of the occurrence

## Service attributes

Implementations of `orion.edit.occurrences` may define the following attributes:

contentType
  `String[]` An array of Content Type IDs for which this occurrence computer is valid.
pattern
  `String` A string to create a regular expression to determine if this occurrence service applies to the current context. This attribute has been

deprecated in favor of `contentType`.

## Examples

The following example is how Orion plugs in occurrence support for JavaScript:

    var provider = new orion.PluginProvider();
    provider.registerService('orion.edit.occurrences',
       {
           computeOccurrences: function(editorContext, context) {
    	   return [];
           }
       {
         contentType: ["application/javascript"]
       });
    provider.connect();