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

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Jovi De Croock and committed by
GitHub
8ae6a954 c25ea3cb

+28 -2
+5
.changeset/flat-boats-approve.md
··· 1 + --- 2 + '@0no-co/graphqlsp': patch 3 + --- 4 + 5 + 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
··· 58 58 state, 59 59 tokenKind: token, 60 60 }; 61 + } else if (string === '.' || string === '..') { 62 + prevToken = { 63 + line, 64 + start: stream.getStartOfToken() + 1, 65 + end: stream.getCurrentPosition(), 66 + string, 67 + state, 68 + tokenKind: token, 69 + }; 61 70 } else { 62 71 prevToken = undefined; 63 72 }
+14 -2
packages/graphqlsp/src/autoComplete.ts
··· 57 57 : schema.current?.schema; 58 58 59 59 const foundToken = getToken(node.arguments[0], cursorPosition); 60 - if (!schemaToUse || !foundToken) return undefined; 60 + if ( 61 + !schemaToUse || 62 + !foundToken || 63 + foundToken.string === '.' || 64 + foundToken.string === '..' 65 + ) 66 + return undefined; 61 67 62 68 const queryText = node.arguments[0].getText().slice(1, -1); 63 69 const fragments = getAllFragments(filename, node, info); ··· 66 72 cursor = new Cursor(foundToken.line, foundToken.start - 1); 67 73 } else if (!isCallExpression && checks.isGraphQLTag(node)) { 68 74 const foundToken = getToken(node.template, cursorPosition); 69 - if (!foundToken || !schema.current) return undefined; 75 + if ( 76 + !foundToken || 77 + !schema.current || 78 + foundToken.string === '.' || 79 + foundToken.string === '..' 80 + ) 81 + return undefined; 70 82 71 83 const { combinedText, resolvedSpans } = resolveTemplate( 72 84 node,