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.

fixies

+11 -5
+11 -5
src/index.ts
··· 1 1 import ts from "typescript/lib/tsserverlibrary"; 2 2 import { isNoSubstitutionTemplateLiteral, ScriptElementKind, isIdentifier, isTaggedTemplateExpression, isToken, isTemplateExpression, isImportTypeNode, ImportTypeNode } from "typescript"; 3 3 import { getHoverInformation, getAutocompleteSuggestions, getDiagnostics, Diagnostic } from 'graphql-language-service' 4 - import { GraphQLSchema, parse, Kind, FragmentDefinitionNode, OperationDefinitionNode } from 'graphql' 4 + import { parse, Kind, FragmentDefinitionNode, OperationDefinitionNode } from 'graphql' 5 5 6 6 import { Cursor } from "./cursor"; 7 7 import { loadSchema } from "./getSchema"; ··· 36 36 const tagTemplate = info.config.template || 'gql'; 37 37 38 38 const proxy = createBasicDecorator(info); 39 + 40 + // TODO: check out interesting stuff on ts.factory 39 41 40 42 const schema = loadSchema(info.project.getProjectName(), info.config.schema); 41 43 ··· 72 74 const text = resolveTemplate(node, filename, info) 73 75 const lines = text.split('\n') 74 76 75 - // This assumes a prefix of gql` 76 - let startingPosition = node.pos + 4 77 + let startingPosition = node.pos + (tagTemplate.length + 1) 78 + // TODO: roll our own diagnostic here for operations without an operationName 79 + // we can't generate typedDocumentNodes for those hence we will warn our user 77 80 return getDiagnostics(text, schema.current).map(x => { 78 81 const { start, end } = x.range; 79 82 ··· 111 114 112 115 if (!newDiagnostics.length) { 113 116 try { 114 - // TODO: we might need to issue warnings for documents without an operationName 115 - // as we can't generate types for those 116 117 const parts = source.fileName.split('/'); 117 118 const name = parts[parts.length - 1]; 118 119 const nameParts = name.split('.'); ··· 159 160 scriptInfo!.editContent(0, snapshot.getLength(), text); 160 161 info.languageServiceHost.writeFile!(source.fileName, text); 161 162 scriptInfo!.registerFileUpdate(); 163 + // script info contains a lot of utils that might come in handy here 164 + // to save even if the user has local changes, if we could make that work 165 + // that would be a win. If not we should check if we can figure it out through 166 + // the script-info whether there are unsaved changes and not run this 167 + // scriptInfo!.open(text); 162 168 }) 163 169 }); 164 170 } catch (e) {}