Skip to content

Commit

Permalink
Fix getToken signature and predicate checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Apr 26, 2024
1 parent ba8f29c commit 641b752
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 5 additions & 1 deletion packages/graphqlsp/src/ast/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 2 additions & 6 deletions packages/graphqlsp/src/autoComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand Down
8 changes: 2 additions & 6 deletions packages/graphqlsp/src/quickInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 641b752

Please sign in to comment.