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

avoid providing diagnostics for other tags (#157)

Changed files
+21 -5
.changeset
packages
test
e2e
fixture-project
fixtures
+5
.changeset/blue-doors-wink.md
···
+
---
+
'@0no-co/graphqlsp': patch
+
---
+
+
Check whether we are on the correct template tag
+7 -3
packages/graphqlsp/src/ast/index.ts
···
}
export function findAllTaggedTemplateNodes(
-
sourceFile: ts.SourceFile | ts.Node
+
sourceFile: ts.SourceFile | ts.Node,
+
template: string
): Array<ts.TaggedTemplateExpression | ts.NoSubstitutionTemplateLiteral> {
const result: Array<
ts.TaggedTemplateExpression | ts.NoSubstitutionTemplateLiteral
> = [];
function find(node: ts.Node) {
if (
-
ts.isTaggedTemplateExpression(node) ||
-
ts.isNoSubstitutionTemplateLiteral(node)
+
(ts.isTaggedTemplateExpression(node) &&
+
node.tag.getText() === template) ||
+
(ts.isNoSubstitutionTemplateLiteral(node) &&
+
ts.isTaggedTemplateExpression(node.parent) &&
+
node.parent.tag.getText() === template)
) {
result.push(node);
return;
+5 -1
packages/graphqlsp/src/checkImports.ts
···
info: ts.server.PluginCreateInfo
) => {
const imports = findAllImports(source);
+
const tagTemplate = info.config.template || 'gql';
const shouldCheckForColocatedFragments =
info.config.shouldCheckForColocatedFragments ?? false;
···
if (!declaration) return;
-
const [template] = findAllTaggedTemplateNodes(declaration);
+
const [template] = findAllTaggedTemplateNodes(
+
declaration,
+
tagTemplate
+
);
if (template) {
let node = template;
if (
+1 -1
packages/graphqlsp/src/diagnostics.ts
···
fragments = result.fragments;
nodes = result.nodes;
} else {
-
nodes = findAllTaggedTemplateNodes(source);
+
nodes = findAllTaggedTemplateNodes(source, tagTemplate);
}
const texts = nodes.map(node => {
+3
test/e2e/fixture-project/fixtures/simple.ts
···
}
}
`;
+
+
const sql = (x: string | TemplateStringsArray) => x;
+
const x = sql`'{}'`;