Skip to content

Commit

Permalink
Avoid suggestions leading up to a fragment-spread
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jul 21, 2024
1 parent 14106a1 commit d796bf6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-boats-approve.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions packages/graphqlsp/src/ast/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 14 additions & 2 deletions packages/graphqlsp/src/autoComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit d796bf6

Please sign in to comment.