Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.

fix: offset issue w/ graphql syntax annotation (#217)

Changed files
+11 -6
.changeset
packages
example-tada
graphqlsp
+5
.changeset/big-spiders-itch.md
···
+
---
+
'@0no-co/graphqlsp': patch
+
---
+
+
Fix offset issue when using the graphql annotation
+1 -1
packages/example-tada/src/Pokemon.tsx
···
}`)
}
-
export const PokemonFields = graphql(`
+
export const PokemonFields = graphql(/* GraphQL */`
fragment pokemonFields on Pokemon {
name
weight {
+1 -1
packages/graphqlsp/src/ast/token.ts
···
const input = text.split('\n');
const parser = onlineParser();
const state = parser.startState();
-
let cPos = template.pos + 1;
+
let cPos = template.getStart() + 1;
let foundToken: Token | undefined = undefined;
for (let line = 0; line < input.length; line++) {
+4 -4
packages/graphqlsp/src/diagnostics.ts
···
MISSING_FRAGMENT_CODE,
getColocatedFragmentNames,
} from './checkImports';
+
import { NoSubstitutionTemplateLiteral } from 'typescript';
const clientDirectives = new Set([
'populate',
···
// by the fact that the parent is an expressionStatement
let startingPosition =
-
node.pos +
+
node.getStart() +
(isCallExpression
? 0
: (node as ts.TaggedTemplateExpression).tag.getText().length +
-
(isExpression ? 2 : 1));
+
(isExpression ? 2 : 0));
const endPosition = startingPosition + node.getText().length;
-
let docFragments = [...fragments];
if (isCallExpression) {
try {
···
if (!op.name) {
graphQLDiagnostics.push({
message: 'Operation needs a name for types to be generated.',
-
start: node.pos,
+
start: node.getStart(),
code: MISSING_OPERATION_NAME_CODE,
length: originalNode.getText().length,
range: {} as any,