How to use the graphql-language-service-utils.Position 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 hasura / graphqurl / src / ui.js View on Github external
const tk = require('terminal-kit');
const {introspectionQuery, buildClientSchema, parse} = require('graphql');
const {cli} = require('cli-ux');
const query = require('./query');
const {validateQuery, getAutocompleteSuggestions} = require('graphql-language-service-interface');
const {Position} = require('graphql-language-service-utils');

// FIXME: needs js idiomatic refactor eslint-disable-line no-warning-comments

var term = tk.terminal;

let qs = '';
let p = new Position(1, 0);
let ib;
let qReady = false;
let schema;
let menuOn = false;
let exit = false;
let gResolve, gReject;

const terminate = error => {
  term.nextLine(1);
  term.grabInput(false);
  term.fullscreen(false);
  if (error) {
    gReject(error);
    return;
  }
  gResolve(qs);
github graphql / graphiql / packages / graphql-language-service-server / src / MessageProcessor.js View on Github external
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 / packages / graphql-language-service-server / src / MessageProcessor.js View on Github external
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 / server / MessageProcessor.js View on Github external
async function provideDiagnosticsMessage(
  query: string,
  uri: Uri,
): Promise> {
  let results = await languageService.getDiagnostics(query, uri);
  if (results && results.length > 0) {
    const queryLines = query.split('\n');
    const totalLines = queryLines.length;
    const lastLineLength = queryLines[totalLines - 1].length;
    const lastCharacterPosition = new Position(totalLines, lastLineLength);
    results = results.filter(diagnostic =>
      diagnostic.range.end.lessThanOrEqualTo(lastCharacterPosition),
    );
  }

  return results;
}
github graphql / graphiql / packages / graphql-language-service-server / src / findGraphQLTags.js View on Github external
fragments.properties.forEach(property => {
          const tagName = getGraphQLTagName(property.value.tag);
          const template = getGraphQLText(property.value.quasi);
          if (tagName) {
            const loc = property.value.loc;
            const range = new Range(
              new Position(loc.start.line - 1, loc.start.column),
              new Position(loc.end.line - 1, loc.end.column)
            );
            result.push({
              tag: tagName,
              template,
              range,
            });
          }
        });
      } else {
github graphql / graphiql / packages / graphql-language-service-server / src / MessageProcessor.js View on Github external
return processedResults.map(diagnostic => ({
      ...diagnostic,
      range: new Range(
        new Position(
          diagnostic.range.start.line + offset.line,
          diagnostic.range.start.character
        ),
        new Position(
          diagnostic.range.end.line + offset.line,
          diagnostic.range.end.character
        )
      ),
    }));
  }
github graphql / graphiql / packages / monaco-graphql / src / monaco-graphql-query.ts View on Github external
export async function provideHoverInfo({
  position,
  model,
  schema
}: ProviderItemInput): Promise {
  const graphQLPosition = new GraphQLPosition(
    position.lineNumber - 1,
    position.column,
  );
  graphQLPosition.setCharacter(position.column);
  graphQLPosition.line = position.lineNumber - 1;
  const hoverInfo = getHoverInformation(
    schema,
    model.getValue(),
    graphQLPosition,
  );
  if (!hoverInfo) {
    return {
      contents: [],
    };
  }
  return {
github graphql / graphiql / packages / graphql-language-service-server / src / MessageProcessor.js View on Github external
return processedResults.map(diagnostic => ({
      ...diagnostic,
      range: new Range(
        new Position(
          diagnostic.range.start.line + offset.line,
          diagnostic.range.start.character
        ),
        new Position(
          diagnostic.range.end.line + offset.line,
          diagnostic.range.end.character
        )
      ),
    }));
  }