Skip to content

fix(editor): map .cts/.mts to the typescript language id - #11294

Merged
Jinwoo-H merged 2 commits into
stablyai:mainfrom
taehwanis:fix/detect-mts-cts-typescript
Jul 30, 2026
Merged

Jinwoo-H merged 2 commits into
stablyai:mainfrom
taehwanis:fix/detect-mts-cts-typescript

Conversation

@taehwanis

@taehwanis taehwanis commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

.cts and .mts files open as plaintext in the editor. The comment above EXT_TO_LANGUAGE in language-detect.ts already documents that Monaco maps .tsx/.cts/.mts onto the typescript language id, but only .tsx was present in the table, so detectLanguage() fell through to 'plaintext' for the other two.

No new language registration is needed. Monaco's own typescript.contribution.js declares extensions: ['.ts', '.tsx', '.cts', '.mts'], so the id already exists and the TypeScript worker treats these files exactly like .ts — only the lookup entry was missing. MonacoEditor always passes an explicit language, so Monaco's URI-based inference never runs and this table is the only decision point.

The repo was already inconsistent here: file-type-icons.ts maps cts/mts to the code-file icon, so the file explorer showed them as code while the editor rendered plain text.

Screenshots

Before After
Before: .mts file rendered as plaintext After: TypeScript syntax highlighting applied

Same .mts file opened in a build from this branch.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

The two unchecked boxes are explained under Notes.

AI Review Report

Three independent review passes with an AI agent — architecture/layering, error handling and edge cases, and project conventions/security. No critical or major findings.

Flagged and fixed:

  • no regression guard for .d.mts/.d.cts declaration files
  • no assertion protecting the adjacent .mjs/.cjs entries in the same block, so a typo there would have gone unnoticed
  • test description was missing the built-in qualifier that sibling tests use

Checked and deliberately left unchanged:

  • an explanatory comment would only restate what the existing comment already declares
  • the insertion order matches Monaco's own extensions array
  • no downstream consumer needs updating, because 'typescript' was already produced by .ts/.tsx — worker routing, canPreviewLanguage, and viewer selection are untouched

Cross-platform compatibility (macOS, Linux, Windows) was explicitly checked. No platform branch is introduced. extname() handles both / and \, and the extension is lowercased before lookup, so case-insensitive filesystems behave identically; the tests cover a Windows absolute path with an uppercase .MTS. No keyboard shortcuts, labels, shell behavior, path utilities, or Electron platform differences are touched. Nothing here is specific to SSH, remote or local hosts, a particular agent, or a git provider, and there is no performance risk in a two-entry object lookup.

Security Audit

No risk surface. This adds two entries to a static lookup table. There is no input execution, no path resolution, no IPC, no auth, no secrets, and no dependency change. extname() uses lastIndexOf rather than a regex, so there is no ReDoS path, and detectLanguage() never opens the file. No follow-up needed.

Notes

  • pnpm lint: oxlint and the code-quality audits pass. The chain stops later at verify:skill-bundle-manifest, which reports stale generated artifacts under resources/skills/. That is a pre-existing state unrelated to this change, and those files are not part of this diff, so I left them untouched rather than regenerating them here.
  • pnpm test: the full suite on a Windows machine fails 176 tests that require a POSIX shell (spawn /bin/sh ENOENT). The failure count is identical before and after this change, so there is no regression from this PR. language-detect.test.ts passes 12/12.
  • mobile/src/session/mobile-file-language.ts has a parallel extension table that also lacks these two entries, so mobile still renders them as plaintext. It feeds a different highlighter and has already diverged on roughly twenty other extensions, so I kept this PR to a single topic. Happy to follow up separately if you would like them aligned.

@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

Fixes .cts and .mts files rendering as plaintext in both the desktop Monaco editor and the mobile syntax highlighter by adding the two missing entries to each module's EXT_TO_LANGUAGE lookup table. The fix is consistent with the existing comment in language-detect.ts that already documented these extensions as belonging to the typescript language id.

  • src/renderer/src/lib/language-detect.ts and mobile/src/session/mobile-file-language.ts: Two entries (.cts → typescript, .mts → typescript) added to the static lookup table in each file; no other logic is touched.
  • Tests: New cases cover lowercase paths, Windows absolute paths, uppercase extensions (case-insensitive), .d.mts declaration files, and a regression guard confirming .mjs/.cjs remain on javascript.

Confidence Score: 5/5

Safe to merge — two entries added to a static lookup table with no logic changes, no new dependencies, and no cross-cutting impact.

The change is strictly additive: two key-value pairs in an object literal. Both the desktop and mobile tables are updated consistently. The existing toLowerCase() call before lookup already handles case-insensitive filesystems. Tests cover lowercase, uppercase, Windows paths, and a .d.mts declaration file, plus a regression guard for the adjacent .mjs/.cjs entries.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/lib/language-detect.ts Adds .cts and .mts entries to EXT_TO_LANGUAGE; matches the existing comment that already documented these extensions and fixes the plaintext fallback.
src/renderer/src/lib/language-detect.test.ts Adds two new test cases: .cts/.mts to typescript (including Windows paths and case-insensitive variants), and a regression guard asserting .mjs/.cjs remain on javascript.
mobile/src/session/mobile-file-language.ts Mirrors the desktop fix: adds .cts and .mts to typescript in the mobile extension table, resolving the same plaintext-fallback inconsistency.
mobile/src/session/mobile-file-syntax.test.ts Adds .mts and .CTS coverage to the mobile test and a resolveMobileSyntaxLanguage assertion for .cts.

Reviews (2): Last reviewed commit: "fix(mobile): map cts and mts to typescri..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cacacf13-a0d6-4bdc-a718-8a55a80df5bb

📥 Commits

Reviewing files that changed from the base of the PR and between 666f44c9275eca2a00e246d1a772612371702727 and dfa99f0.

📒 Files selected for processing (2)
  • mobile/src/session/mobile-file-language.ts
  • mobile/src/session/mobile-file-syntax.test.ts

📝 Walkthrough

Walkthrough

Updated renderer and mobile language detection to map .cts and .mts extensions to TypeScript. Added tests covering case-insensitive and Windows-path inputs, mobile syntax resolution, and .mjs and .cjs mappings to JavaScript.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: mapping .cts/.mts files to the TypeScript language id.
Description check ✅ Passed The description includes all required sections and provides substantive details, screenshots, testing, review, security, and notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

taehwanis and others added 2 commits July 29, 2026 22:52
The comment above EXT_TO_LANGUAGE already documents that Monaco maps
.tsx/.cts/.mts onto the typescript language id, but only .tsx was in the
table, so .cts/.mts files opened as plaintext.
@Jinwoo-H
Jinwoo-H force-pushed the fix/detect-mts-cts-typescript branch from 666f44c to dfa99f0 Compare July 30, 2026 07:22
@Jinwoo-H
Jinwoo-H merged commit 7ba4332 into stablyai:main Jul 30, 2026
40 of 42 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
)

* fix(editor): map .cts/.mts to the typescript language id

The comment above EXT_TO_LANGUAGE already documents that Monaco maps
.tsx/.cts/.mts onto the typescript language id, but only .tsx was in the
table, so .cts/.mts files opened as plaintext.

* fix(mobile): map cts and mts to typescript

---------

Co-authored-by: OrcaWin <[email protected]>
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.

4 participants