Skip to content

fix(typescript): set original file's script kind to match the service script's in proxyCreateProgram#299

Merged
johnsoncodehk merged 1 commit intovolarjs:masterfrom
auvred:proxy-create-program-original-file-script-kind
Jan 31, 2026
Merged

fix(typescript): set original file's script kind to match the service script's in proxyCreateProgram#299
johnsoncodehk merged 1 commit intovolarjs:masterfrom
auvred:proxy-create-program-original-file-script-kind

Conversation

@auvred
Copy link
Copy Markdown
Contributor

@auvred auvred commented Jan 8, 2026

In flint-fyi/flint#1179 I'm using proxyCreateProgram to patch the programs created by the Project Service. Parsed files are stored in TypeScript's document registry. When a file is parsed and later updated in the Project Service, it tries to reuse the old document, but the script kinds don't match, so TS fails with:

Error: Debug Failure. False expression: Script kind should match provided ScriptKind:4 and sourceFile.scriptKind: 3, !entry: false
 ❯ getDocumentRegistryEntry ../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/typescript.js:143966:11
 ❯ Object.releaseDocumentWithKey ../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/typescript.js:144060:19
 ❯ Object.getOrCreateSourceFileByPath [as getSourceFileByPath] ../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/typescript.js:152941:30
 ❯ tryReuseStructureFromOldProgram ../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/typescript.js:127648:59
 ❯ _createProgram ../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/typescript.js:127100:23
 ❯ Object.apply ../../node_modules/.pnpm/@volar+typescript@2.4.27/node_modules/@volar/typescript/lib/node/proxyCreateProgram.js:180:37
 ❯ Object.apply src/language.ts:111:47
    109|     });
    110|
    111|     const program: ProxiedTSProgram = Reflect.apply(proxied, thisArg, args);
       |                                               ^
    112|
    113|     if (volarLanguage == null) {
 ❯ createProgram ../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/typescript.js:126939:3
 ❯ synchronizeHostDataWorker ../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/typescript.js:152877:15
 ❯ synchronizeHostData ../../node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/typescript.js:152772:7

If we set the original file's script kind to match the service script's script kind, then everything works as expected: https://github.com/flint-fyi/flint/blob/75d19831b7476b89271989fbe25e9d1593d4e628/patches/%40volar__typescript%402.4.27.patch

@auvred auvred changed the title fix(typescript): set original file's script kind to match the service script's fix(typescript): set original file's script kind to match the service script's in proxyCreateProgram Jan 8, 2026
@johnsoncodehk johnsoncodehk merged commit 8272ef2 into volarjs:master Jan 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants