···11import ts from "typescript/lib/tsserverlibrary";
22import { isNoSubstitutionTemplateLiteral, ScriptElementKind, isIdentifier, isTaggedTemplateExpression, isToken, isTemplateExpression, isImportTypeNode, ImportTypeNode } from "typescript";
33import { getHoverInformation, getAutocompleteSuggestions, getDiagnostics, Diagnostic } from 'graphql-language-service'
44-import { GraphQLSchema, parse, Kind, FragmentDefinitionNode, OperationDefinitionNode } from 'graphql'
44+import { parse, Kind, FragmentDefinitionNode, OperationDefinitionNode } from 'graphql'
5566import { Cursor } from "./cursor";
77import { loadSchema } from "./getSchema";
···3636 const tagTemplate = info.config.template || 'gql';
37373838 const proxy = createBasicDecorator(info);
3939+4040+ // TODO: check out interesting stuff on ts.factory
39414042 const schema = loadSchema(info.project.getProjectName(), info.config.schema);
4143···7274 const text = resolveTemplate(node, filename, info)
7375 const lines = text.split('\n')
74767575- // This assumes a prefix of gql`
7676- let startingPosition = node.pos + 4
7777+ let startingPosition = node.pos + (tagTemplate.length + 1)
7878+ // TODO: roll our own diagnostic here for operations without an operationName
7979+ // we can't generate typedDocumentNodes for those hence we will warn our user
7780 return getDiagnostics(text, schema.current).map(x => {
7881 const { start, end } = x.range;
7982···111114112115 if (!newDiagnostics.length) {
113116 try {
114114- // TODO: we might need to issue warnings for documents without an operationName
115115- // as we can't generate types for those
116117 const parts = source.fileName.split('/');
117118 const name = parts[parts.length - 1];
118119 const nameParts = name.split('.');
···159160 scriptInfo!.editContent(0, snapshot.getLength(), text);
160161 info.languageServiceHost.writeFile!(source.fileName, text);
161162 scriptInfo!.registerFileUpdate();
163163+ // script info contains a lot of utils that might come in handy here
164164+ // to save even if the user has local changes, if we could make that work
165165+ // that would be a win. If not we should check if we can figure it out through
166166+ // the script-info whether there are unsaved changes and not run this
167167+ // scriptInfo!.open(text);
162168 })
163169 });
164170 } catch (e) {}