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.

avoid providing diagnostics for other tags (#157)

authored by

Jovi De Croock and committed by
GitHub
380418ab 1efbac2c

+21 -5
+5
.changeset/blue-doors-wink.md
··· 1 + --- 2 + '@0no-co/graphqlsp': patch 3 + --- 4 + 5 + Check whether we are on the correct template tag
+7 -3
packages/graphqlsp/src/ast/index.ts
··· 32 32 } 33 33 34 34 export function findAllTaggedTemplateNodes( 35 - sourceFile: ts.SourceFile | ts.Node 35 + sourceFile: ts.SourceFile | ts.Node, 36 + template: string 36 37 ): Array<ts.TaggedTemplateExpression | ts.NoSubstitutionTemplateLiteral> { 37 38 const result: Array< 38 39 ts.TaggedTemplateExpression | ts.NoSubstitutionTemplateLiteral 39 40 > = []; 40 41 function find(node: ts.Node) { 41 42 if ( 42 - ts.isTaggedTemplateExpression(node) || 43 - ts.isNoSubstitutionTemplateLiteral(node) 43 + (ts.isTaggedTemplateExpression(node) && 44 + node.tag.getText() === template) || 45 + (ts.isNoSubstitutionTemplateLiteral(node) && 46 + ts.isTaggedTemplateExpression(node.parent) && 47 + node.parent.tag.getText() === template) 44 48 ) { 45 49 result.push(node); 46 50 return;
+5 -1
packages/graphqlsp/src/checkImports.ts
··· 16 16 info: ts.server.PluginCreateInfo 17 17 ) => { 18 18 const imports = findAllImports(source); 19 + const tagTemplate = info.config.template || 'gql'; 19 20 20 21 const shouldCheckForColocatedFragments = 21 22 info.config.shouldCheckForColocatedFragments ?? false; ··· 66 67 67 68 if (!declaration) return; 68 69 69 - const [template] = findAllTaggedTemplateNodes(declaration); 70 + const [template] = findAllTaggedTemplateNodes( 71 + declaration, 72 + tagTemplate 73 + ); 70 74 if (template) { 71 75 let node = template; 72 76 if (
+1 -1
packages/graphqlsp/src/diagnostics.ts
··· 76 76 fragments = result.fragments; 77 77 nodes = result.nodes; 78 78 } else { 79 - nodes = findAllTaggedTemplateNodes(source); 79 + nodes = findAllTaggedTemplateNodes(source, tagTemplate); 80 80 } 81 81 82 82 const texts = nodes.map(node => {
+3
test/e2e/fixture-project/fixtures/simple.ts
··· 8 8 } 9 9 } 10 10 `; 11 + 12 + const sql = (x: string | TemplateStringsArray) => x; 13 + const x = sql`'{}'`;