Cursor lookup

When you regularly parse a document you enter at the root document level, there is however also the possibility to parse the document and lookup a one-dimensional index or a line and column in the document, which means you enter the document at whichever element is at that location. This can be used for autocomplete providers in an IDE or text editor, or other rich eno document inspection usecases.

const enolib = require('enolib');

const lookup = enolib.lookup({ index: 3 }, 'field: value'); // "what is at string offset 3?"
  // returns {
  //   element: [object AmbiguousElement key=field value=value]
  //   range: 'key'
  // }
  
const lookup = enolib.lookup({ index: 5 }, 'field: value'); // "what is at string offset 5?"
  // returns {
  //   element: [object AmbiguousElement key=field value=value]
  //   range: 'elementOperator'
  // }

const lookup = enolib.lookup({ line: 0, column: 10 }, 'field: value'); // "what is at line 0, column 10?"
  // returns {
  //   element: [object AmbiguousElement key=field value=value]
  //   range: 'value'
  // }

Note that the element returned as a lookup property is of variable type, therefore you need to use the methods described in Dynamic layouts to further query the document from this entry point.

As you don't enter at the root you can also use .parent() to navigate up the hierarchy.


Next page: Querying content