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.

perform an additional dirty check (#27)

authored by

Jovi De Croock and committed by
GitHub
efeed9bf 34feb809

+28 -4
+5
.changeset/olive-jokes-drum.md
··· 1 + --- 2 + '@0no-co/graphqlsp': patch 3 + --- 4 + 5 + Check the `dirty` state of the file an additional time to prevent writing to the file when the user types directly after saving
+15 -4
src/index.ts
··· 26 26 import { Cursor } from './cursor'; 27 27 import { loadSchema } from './getSchema'; 28 28 import { getToken } from './token'; 29 - import { findAllTaggedTemplateNodes, findNode, getSource } from './utils'; 29 + import { 30 + findAllTaggedTemplateNodes, 31 + findNode, 32 + getSource, 33 + isFileDirty, 34 + } from './utils'; 30 35 import { resolveTemplate } from './resolve'; 31 36 import { generateTypedDocumentNodes } from './types/generate'; 32 37 ··· 174 179 const nameParts = name.split('.'); 175 180 nameParts[nameParts.length - 1] = 'generated.ts'; 176 181 parts[parts.length - 1] = nameParts.join('.'); 177 - const contents = fs.readFileSync(filename, 'utf-8'); 178 - const currentText = source.getFullText(); 179 182 180 - if (contents !== currentText) { 183 + if (isFileDirty(filename, source)) { 181 184 return [...newDiagnostics, ...originalDiagnostics]; 182 185 } 183 186 ··· 187 190 texts.join('\n'), 188 191 scalars 189 192 ).then(() => { 193 + if (isFileDirty(filename, source)) { 194 + return; 195 + } 196 + 190 197 nodes.forEach((node, i) => { 191 198 const queryText = texts[i] || ''; 192 199 const parsed = parse(queryText); ··· 222 229 const typeImport = parentChildren.find(x => 223 230 isImportTypeNode(x) 224 231 ) as ImportTypeNode; 232 + 225 233 if (typeImport && typeImport.getText().includes(exportName)) return; 226 234 227 235 const span = { length: 1, start: node.end }; 236 + 237 + // TODO: if we have a typeImport but the name has been updated/is wrong 238 + // we need to leave the "as x" typecast 228 239 const text = 229 240 source.text.substring(0, span.start) + 230 241 imp +
+8
src/utils.ts
··· 3 3 isNoSubstitutionTemplateLiteral, 4 4 isTaggedTemplateExpression, 5 5 } from 'typescript'; 6 + import fs from 'fs'; 7 + 8 + export function isFileDirty(fileName: string, source: ts.SourceFile) { 9 + const contents = fs.readFileSync(fileName, 'utf-8'); 10 + const currentText = source.getFullText(); 11 + 12 + return currentText !== contents; 13 + } 6 14 7 15 export function findNode( 8 16 sourceFile: ts.SourceFile,