Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when changing file language mode: Registered script kind should match new script kind #42613

Closed
mjbvz opened this issue Feb 2, 2021 · 0 comments · Fixed by #43474
Closed
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Feb 2, 2021

Bug Report

🔎 Search Terms

  • TS Server
  • updateopen
  • untitled

🕗 Version & Regression Information

Version: 4.2.0-dev.20210201

This also happens in 4.1 so it is not a regression

💻 Repo

  1. In VS Code
  2. Create a untitled file: ctrl+n
  3. Change the language mode of the file to javascript (ctrl+k ctrl+m)
  4. Now change the mode of the file to TypeScript react

🙁 Bug

This sometimes sees to throw an exception.

Here is the tsserver.log

The relevant section seems is below. My understanding of what is happening:

  1. VS Code closes ^untitled:Untitled-1 with update open
  2. We then try to open it again with a new call to updateOpen
  3. The exception happens
Info 134  [12:03:17.700] request:
    {"seq":33,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":["^untitled:Untitled-1"],"openFiles":[]}}
Info 135  [12:03:17.700] Project '/dev/null/inferredProject1*' (Inferred)
Info 135  [12:03:17.700] 	Files (7)

Info 135  [12:03:17.700] -----------------------------------------------
Info 135  [12:03:17.700] Open files: 
Info 135  [12:03:17.700] 	FileName: /Users/matb/projects/san/e.ts ProjectRootPath: /Users/matb/projects/san
Info 135  [12:03:17.700] 		Projects: /dev/null/inferredProject1*
Perf 135  [12:03:17.700] 33::updateOpen: elapsed time (in milliseconds) 0.3229
Info 136  [12:03:17.700] response:
    {"seq":0,"type":"response","command":"updateOpen","request_seq":33,"success":true,"body":true}
Info 137  [12:03:17.897] request:
    {"seq":34,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":[],"openFiles":[{"file":"^untitled:Untitled-1","fileContent":"11\n","projectRootPath":"/Users/matb/projects/san","scriptKindName":"TSX"}]}}
Info 138  [12:03:17.898] Starting updateGraphWorker: Project: /dev/null/inferredProject1*
Err 139   [12:03:17.955] Exception on executing command {"seq":34,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":[],"openFiles":[{"file":"^untitled:Untitled-1","fileContent":"11\n","projectRootPath":"/Users/matb/projects/san","scriptKindName":"TSX"}]}}:

    Debug Failure. Expected 4 === 3. Registered script kind should match new script kind.

    Error: Debug Failure. Expected 4 === 3. Registered script kind should match new script kind.
        at Object.getOrCreateSourceFileByPath [as getSourceFileByPath] (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:149050:34)
        at tryReuseStructureFromOldProgram (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:106865:28)
        at Object.createProgram (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:106396:29)
        at synchronizeHostData (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:148973:26)
        at Proxy.getProgram (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:149065:13)
        at InferredProject.Project.updateGraphWorker (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:153950:53)
        at InferredProject.Project.updateGraph (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:153880:42)
        at ProjectService.assignOrphanScriptInfoToInferredProject (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:156048:25)
        at ProjectService.assignProjectToOpenedScriptInfo (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:157605:26)
        at /Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:157879:97
        at Object.flatMap (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:515:25)
        at ProjectService.applyChangesInOpenFiles (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:157879:41)
        at Session.handlers.ts.Map.ts.getEntries._a.<computed> (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:158934:46)
        at /Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:160818:88
        at IOSession.Session.executeWithRequestId (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:160809:28)
        at IOSession.Session.executeCommand (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:160818:33)
        at IOSession.Session.onMessage (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:160844:35)
        at Interface.<anonymous> (/Users/matb/projects/san/node_modules/typescript/lib/tsserver.js:163507:31)
        at Interface.emit (events.js:315:20)
        at Interface._onLine (readline.js:329:10)
        at Interface._normalWrite (readline.js:474:12)
        at Socket.ondata (readline.js:186:10)
        at Socket.emit (events.js:315:20)
        at addChunk (_stream_readable.js:295:12)
        at readableAddChunk (_stream_readable.js:271:9)
        at Socket.Readable.push (_stream_readable.js:212:10)
        at Pipe.onStreamRead (internal/stream_base_commons.js:186:23)
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 5, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.3.0 milestone Feb 5, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Apr 1, 2021
sheetalkamat added a commit that referenced this issue Apr 5, 2021
…and document registry key(compiler options affecting source file) but different ScriptKind (#43474)

* Test that fails because of change in scriptKind of untitled file

* buckets are keyed with DocumentRegistryBucketKey

* Use scriptKind in document Registry to distinguish between files
Fixes #42613
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
5 participants