fix(language-server): prevent stack overflow with project references containing non-TS files#16827
Conversation
…containing non-TS files
🦋 Changeset detectedLatest commit: b382913 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
|
Verified by the reporter: #16817 (comment) |
| // getOutputDeclarationFileName returns the input path unchanged (since changeExtension | ||
| // doesn't recognize the extension), creating self-referencing redirect entries that | ||
| // cause infinite recursion in findSourceFile. | ||
| const nonTsExtensions = ['.vue', '.svelte', '.astro']; |
There was a problem hiding this comment.
I don't understand, why do we need to handle non-astro files? Or, why do we need to handle these three files specifically? The comment doesn't actually explain it.
There was a problem hiding this comment.
Our language server supports those files the same way it supports Astro ones
There was a problem hiding this comment.
I added a better comment here, but basically TypeScript doesn't understand non-TypeScript files so it sees Hello.vue and maps that to Hello.vue which causes the loop, so excluding those fixes it.
| const mockHost = { | ||
| getScriptFileNames: () => [], | ||
| getCompilationSettings: () => ({}), | ||
| getProjectReferences: () => [{ path: './tsconfig.app.json' }], |
There was a problem hiding this comment.
Shouldn't the tests verify things against vue/svelte/astro files?
There was a problem hiding this comment.
it has to read the file system to properly test that. so it would need a fixture. Happy to add one if you'd like.
Princesseuh
left a comment
There was a problem hiding this comment.
I don't know if it's the proper fix or not, I guess this is something that is caused by a patch in Volar already? But if this works I'm fine with it, not the first time we do these kinds of patches (but perhaps the last one in this upcoming Go TS world)
Fixes #16817
When a tsconfig uses project references that include
.vueor.sveltefiles, TypeScript'sgetOutputDeclarationFileNamereturns the input path unchanged (sincechangeExtensiondoesn't recognize these extensions). This creates self-referencing entries in the redirect maps (Hello.vue→Hello.vue), causing infinite recursion infindSourceFile.The fix provides
getParsedCommandLineon the language service host, which is TypeScript's official hook for customizing how referenced tsconfigs are parsed. Our implementation parses them normally but filters.vue/.svelte/.astrofiles from the file list, preventing the self-referencing redirect entries. Project references remain fully functional for all standard TS/JS files.