diff --git a/.changeset/flat-boats-approve.md b/.changeset/flat-boats-approve.md new file mode 100644 index 00000000..3365ef93 --- /dev/null +++ b/.changeset/flat-boats-approve.md @@ -0,0 +1,5 @@ +--- +'@0no-co/graphqlsp': patch +--- + +Bail on dots, when there's one or two dots we are leading up to a fragment-spread and should avoid giving suggestions diff --git a/packages/graphqlsp/src/ast/token.ts b/packages/graphqlsp/src/ast/token.ts index 2914428c..b0991e62 100644 --- a/packages/graphqlsp/src/ast/token.ts +++ b/packages/graphqlsp/src/ast/token.ts @@ -58,6 +58,15 @@ export const getToken = ( state, tokenKind: token, }; + } else if (string === '.' || string === '..') { + prevToken = { + line, + start: stream.getStartOfToken() + 1, + end: stream.getCurrentPosition(), + string, + state, + tokenKind: token, + }; } else { prevToken = undefined; } diff --git a/packages/graphqlsp/src/autoComplete.ts b/packages/graphqlsp/src/autoComplete.ts index e29dd38d..69704df3 100644 --- a/packages/graphqlsp/src/autoComplete.ts +++ b/packages/graphqlsp/src/autoComplete.ts @@ -57,7 +57,13 @@ export function getGraphQLCompletions( : schema.current?.schema; const foundToken = getToken(node.arguments[0], cursorPosition); - if (!schemaToUse || !foundToken) return undefined; + if ( + !schemaToUse || + !foundToken || + foundToken.string === '.' || + foundToken.string === '..' + ) + return undefined; const queryText = node.arguments[0].getText().slice(1, -1); const fragments = getAllFragments(filename, node, info); @@ -66,7 +72,13 @@ export function getGraphQLCompletions( cursor = new Cursor(foundToken.line, foundToken.start - 1); } else if (!isCallExpression && checks.isGraphQLTag(node)) { const foundToken = getToken(node.template, cursorPosition); - if (!foundToken || !schema.current) return undefined; + if ( + !foundToken || + !schema.current || + foundToken.string === '.' || + foundToken.string === '..' + ) + return undefined; const { combinedText, resolvedSpans } = resolveTemplate( node,