Skip to content

Commit

Permalink
fix: offset issue w/ graphql syntax annotation (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Feb 11, 2024
1 parent ba2c4e7 commit ff04898
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-spiders-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': patch
---

Fix offset issue when using the graphql annotation
2 changes: 1 addition & 1 deletion packages/example-tada/src/Pokemon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const Fields = { Pokemon: graphql(`
}`)
}

export const PokemonFields = graphql(`
export const PokemonFields = graphql(/* GraphQL */`
fragment pokemonFields on Pokemon {
name
weight {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphqlsp/src/ast/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getToken = (
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++) {
Expand Down
8 changes: 4 additions & 4 deletions packages/graphqlsp/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
MISSING_FRAGMENT_CODE,
getColocatedFragmentNames,
} from './checkImports';
import { NoSubstitutionTemplateLiteral } from 'typescript';

const clientDirectives = new Set([
'populate',
Expand Down Expand Up @@ -205,13 +206,12 @@ const runDiagnostics = (
// 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 {
Expand Down Expand Up @@ -312,7 +312,7 @@ const runDiagnostics = (
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,
Expand Down

0 comments on commit ff04898

Please sign in to comment.