Skip to content

fix(language-server): prevent stack overflow with project references containing non-TS files#16827

Open
matthewp wants to merge 3 commits into
mainfrom
fix-16817
Open

fix(language-server): prevent stack overflow with project references containing non-TS files#16827
matthewp wants to merge 3 commits into
mainfrom
fix-16817

Conversation

@matthewp
Copy link
Copy Markdown
Contributor

Fixes #16817

When a tsconfig uses project references that include .vue or .svelte files, TypeScript's getOutputDeclarationFileName returns the input path unchanged (since changeExtension doesn't recognize these extensions). This creates self-referencing entries in the redirect maps (Hello.vueHello.vue), causing infinite recursion in findSourceFile.

The fix provides getParsedCommandLine on 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/.astro files from the file list, preventing the self-referencing redirect entries. Project references remain fully functional for all standard TS/JS files.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: b382913

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/language-server Patch

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

@matthewp matthewp added pr preview Apply this label to a PR to generate a preview release and removed pr preview Apply this label to a PR to generate a preview release labels May 21, 2026
@matthewp matthewp added pr preview Apply this label to a PR to generate a preview release and removed pr preview Apply this label to a PR to generate a preview release labels May 21, 2026
@github-actions github-actions Bot removed the pr preview Apply this label to a PR to generate a preview release label May 21, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 21, 2026

npm i https://pkg.pr.new/@astrojs/language-server@16827

commit: b4b57b2

@matthewp matthewp marked this pull request as ready for review May 21, 2026 20:57
@matthewp matthewp added the fix verified Reporter confirmed the triage bot fix works label May 21, 2026
@matthewp
Copy link
Copy Markdown
Contributor Author

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'];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our language server supports those files the same way it supports Astro ones

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' }],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the tests verify things against vue/svelte/astro files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/language-tools/language-server/src/core/index.ts Outdated
Comment thread packages/language-tools/language-server/src/core/index.ts Outdated
Copy link
Copy Markdown
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix verified Reporter confirmed the triage bot fix works

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maximum call stack size exceeded from VSCode extension

3 participants