diff --git a/packages/graphqlsp/src/ast/token.ts b/packages/graphqlsp/src/ast/token.ts index 2efcca38..2914428c 100644 --- a/packages/graphqlsp/src/ast/token.ts +++ b/packages/graphqlsp/src/ast/token.ts @@ -11,9 +11,13 @@ export interface Token { } export const getToken = ( - template: ts.StringLiteralLike, + template: ts.Expression, cursorPosition: number ): Token | undefined => { + if (!ts.isTemplateLiteral(template) && !ts.isStringLiteralLike(template)) { + return undefined; + } + const text = template.getText().slice(1, -1); const input = text.split('\n'); const parser = onlineParser(); diff --git a/packages/graphqlsp/src/autoComplete.ts b/packages/graphqlsp/src/autoComplete.ts index dda5897c..e29dd38d 100644 --- a/packages/graphqlsp/src/autoComplete.ts +++ b/packages/graphqlsp/src/autoComplete.ts @@ -56,9 +56,7 @@ export function getGraphQLCompletions( ? schema.multi[schemaName]?.schema : schema.current?.schema; - const foundToken = ts.isStringLiteralLike(node.arguments[0]) - ? getToken(node.arguments[0], cursorPosition) - : undefined; + const foundToken = getToken(node.arguments[0], cursorPosition); if (!schemaToUse || !foundToken) return undefined; const queryText = node.arguments[0].getText().slice(1, -1); @@ -67,9 +65,7 @@ export function getGraphQLCompletions( text = `${queryText}\n${fragments.map(x => print(x)).join('\n')}`; cursor = new Cursor(foundToken.line, foundToken.start - 1); } else if (!isCallExpression && checks.isGraphQLTag(node)) { - const foundToken = ts.isStringLiteralLike(node.template) - ? getToken(node.template, cursorPosition) - : undefined; + const foundToken = getToken(node.template, cursorPosition); if (!foundToken || !schema.current) return undefined; const { combinedText, resolvedSpans } = resolveTemplate( diff --git a/packages/graphqlsp/src/quickInfo.ts b/packages/graphqlsp/src/quickInfo.ts index 43a74191..c48ba170 100644 --- a/packages/graphqlsp/src/quickInfo.ts +++ b/packages/graphqlsp/src/quickInfo.ts @@ -46,17 +46,13 @@ export function getGraphQLQuickInfo( ? schema.multi[schemaName]?.schema : schema.current?.schema; - const foundToken = ts.isStringLiteralLike(node.arguments[0]) - ? getToken(node.arguments[0], cursorPosition) - : undefined; + const foundToken = getToken(node.arguments[0], cursorPosition); if (!schemaToUse || !foundToken) return undefined; text = node.arguments[0].getText(); cursor = new Cursor(foundToken.line, foundToken.start - 1); } else if (!isCallExpression && checks.isGraphQLTag(node)) { - const foundToken = ts.isStringLiteralLike(node.template) - ? getToken(node.template, cursorPosition) - : undefined; + const foundToken = getToken(node.template, cursorPosition); if (!foundToken || !schema.current) return undefined; const { combinedText, resolvedSpans } = resolveTemplate(