How to use the graphql-language-service-utils.Range function in graphql-language-service-utils

To help you get started, we’ve selected a few graphql-language-service-utils 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 graphql / graphiql / packages / graphql-language-service-interface / src / getDiagnostics.ts View on Github external
? node.name
        : 'variable' in node
        ? node.variable
        : node;

    invariant(error.locations, 'GraphQL validation error requires locations.');
    // @ts-ignore
    // https://github.com/microsoft/TypeScript/pull/32695
    const loc = error.locations[0];
    const highlightLoc = getLocation(highlightNode);
    const end = loc.column + (highlightLoc.end - highlightLoc.start);
    return {
      source: `GraphQL: ${type}`,
      message: error.message,
      severity,
      range: new Range(
        new Position(loc.line - 1, loc.column - 1),
        new Position(loc.line - 1, end),
      ),
    };
  });
}
github graphql / graphiql / packages / graphql-language-service-interface / src / getDiagnostics.ts View on Github external
const style = parser.token(stream, state);
      if (style === 'invalidchar') {
        break;
      }
    }
  }

  invariant(stream, 'Expected Parser stream to be available.');
  const line = location.line - 1;
  // @ts-ignore
  // https://github.com/microsoft/TypeScript/pull/32695
  const start = stream.getStartOfToken();
  // @ts-ignore
  // https://github.com/microsoft/TypeScript/pull/32695
  const end = stream.getCurrentPosition();
  return new Range(new Position(line, start), new Position(line, end));
}
github graphql / graphiql / packages / graphql-language-service-server / src / MessageProcessor.js View on Github external
if (
      text.indexOf('graphql`') === -1 &&
      text.indexOf('graphql.experimental`') === -1 &&
      text.indexOf('gql`') === -1
    ) {
      return [];
    }
    const templates = findGraphQLTags(text);
    return templates.map(({ template, range }) => ({ query: template, range }));
  } else {
    const query = text;
    if (!query && query !== '') {
      return [];
    }
    const lines = query.split('\n');
    const range = new Range(
      new Position(0, 0),
      new Position(lines.length - 1, lines[lines.length - 1].length - 1)
    );
    return [{ query, range }];
  }
}
github graphql / graphiql / src / interfaces / getDiagnostics.js View on Github external
if (style === 'invalidchar') {
        break;
      }
    }
  }

  invariant(
    stream,
    'Expected Parser stream to be available.',
  );

  const line = location.line - 1;
  const start = stream.getStartOfToken();
  const end = stream.getCurrentPosition();

  return new Range(new Position(line, start), new Position(line, end));
}
github graphql / graphiql / src / interfaces / getDiagnostics.js View on Github external
return error.nodes.map(node => {
    const highlightNode: ASTNode =
      node.kind !== 'Variable' && node.name ? node.name :
      node.variable ? node.variable :
      node;

    invariant(error.locations, 'GraphQL validation error requires locations.');
    const loc = error.locations[0];
    const end = loc.column + (highlightNode.loc.end - highlightNode.loc.start);
    return {
      source: 'GraphQL: Validation',
      message: error.message,
      severity: SEVERITY.ERROR,
      range: new Range(
        new Position(loc.line - 1, loc.column - 1),
        new Position(loc.line - 1, end),
      ),
    };
  });
}