How to use the codemirror-graphql/utils/CharacterStream function in codemirror-graphql

To help you get started, we’ve selected a few codemirror-graphql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github orionsoft / atom-graphql-autocomplete / lib / graphql / getToken.js View on Github external
const getToken = function (query, {row, column}) {
  const parserOptions = {
    eatWhitespace: stream => stream.eatWhile(isIgnored),
    LexRules,
    ParseRules
  }
  const parser = onlineParser(parserOptions)
  const state = parser.startState()
  const lines = query.split('\n')

  for (let i = 0; i < lines.length; i++) {
    const line = lines[i]
    const stream = new CharacterStream(line)
    let style = null
    for (let i = 0; !stream.eol() && i < 1000; i++) {
      style = parser.token(stream, state)
      if (style === 'invalidchar') {
        return {stream, state, style}
      }
      if (i === row && column === stream._pos) {
        return {stream, state, style}
      }
    }
    if (i === row) {
      if (!style) return null
      return {stream, state, style}
    }
  }
}

codemirror-graphql

GraphQL mode and helpers for CodeMirror.

MIT
Latest version published 3 months ago

Package Health Score

95 / 100
Full package analysis