Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.

chore(lsp): Avoid suggestions leading up to a fragment-spread (#344)

Changed files
+28 -2
.changeset
packages
graphqlsp
+5
.changeset/flat-boats-approve.md
···
+
---
+
'@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
packages/graphqlsp/src/ast/token.ts
···
state,
tokenKind: token,
};
+
} else if (string === '.' || string === '..') {
+
prevToken = {
+
line,
+
start: stream.getStartOfToken() + 1,
+
end: stream.getCurrentPosition(),
+
string,
+
state,
+
tokenKind: token,
+
};
} else {
prevToken = undefined;
}
+14 -2
packages/graphqlsp/src/autoComplete.ts
···
: 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);
···
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,