Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Fix overlay script kind fallback for unknown LSP language IDs - #4189

Merged
Jake Bailey (jakebailey) merged 2 commits into
mainfrom
copilot/fix-tsgo-lsp-crash-mts-file
Jun 3, 2026
Merged

Jake Bailey (jakebailey) merged 2 commits into
mainfrom
copilot/fix-tsgo-lsp-crash-mts-file

Conversation

Copilot AI commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Opening a .mts file could crash tsgo LSP when the client sent a non-standard languageId such as "mts". The overlay shadowed the disk file with ScriptKindUnknown, which later reached the parser.

  • Overlay handling
    • Resolve the script kind from the LSP language ID first.
    • Fall back to the file extension when the language ID is unknown.
scriptKind := lsconv.LanguageKindToScriptKind(events.openChange.LanguageKind)
if scriptKind == core.ScriptKindUnknown {
    scriptKind = core.GetScriptKindFromFileName(uri.FileName())
}
  • Regression coverage
    • Added an overlayfs test for opening file:///test1.mts with languageId: "mts".
    • Verifies the overlay uses the TypeScript script kind instead of ScriptKindUnknown.

Copilot AI changed the title [WIP] Fix tsgo LSP crashes when opening .mts file in mixed CJS/ESM repo Fix overlay script kind fallback for unknown LSP language IDs Jun 3, 2026
@jakebailey
Jake Bailey (jakebailey) marked this pull request as ready for review June 3, 2026 17:23
@jakebailey

Copy link
Copy Markdown
Member

I'm not 100% thrilled that we would need to do this to appease a client, but, it's not the worst thought.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in the tsgo LSP overlay filesystem when the client sends a non-standard/unknown languageId (e.g. "mts"), ensuring overlays don’t end up with ScriptKindUnknown and later fail in parsing.

Changes:

  • Resolve overlay ScriptKind from LSP languageId, but fall back to file-extension-based detection when the ID is unknown.
  • Add a regression test to ensure opening file:///test1.mts with languageId: "mts" results in ScriptKindTS.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/project/overlayfs.go Adds a safe fallback to determine ScriptKind from filename when LSP language ID is not recognized.
internal/project/overlayfs_test.go Adds a regression test covering unknown LSP language IDs for .mts overlays.

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Jun 3, 2026
Merged via the queue into main with commit 01fb3f4 Jun 3, 2026
26 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the copilot/fix-tsgo-lsp-crash-mts-file branch June 3, 2026 20:10
Jake Bailey (jakebailey) added a commit to jakebailey/TypeScript that referenced this pull request Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsgo LSP crashes in WebStorm when opening .mts file in mixed CJS/ESM repo

4 participants