Skip to content

TypeScript 7 VS Code extension: Go to Source Definition does not run in content-mapped files, although tsc --lsp answers for them #64576

Open

Description

@leonidaz

In a content-mapped file, TypeScript: Go to Source Definition does nothing, while the same command in a .ts file opens the JavaScript behind a .d.ts file. The language server supports it: custom/textDocument/sourceDefinition for the content-mapped file returns the JavaScript location. The extension never sends that request for content-mapped files.

Repro: https://gist.github.com/leonidaz/d1fcd2d140269282c7df1d3b84fe517f, a 47-line identity content mapper (.foo files contain TSX and are returned unchanged as .tsx) and a JavaScript library greeting with its own index.d.ts. TypeScript 7 extension 1.0.1, typescript@7.1.0-dev.20260930.4 through js/ts.tsdk.path, VS Code 1.140.0, macOS.

main.foo and control.ts have the same text:

import { greet } from "greeting";

export const text = greet("x");

In VS Code

Put the cursor on greet in greet("x") and run TypeScript: Go to Source Definition from the Command Palette:

File Hover on greet Go to Source Definition
control.ts (alias) function greet(name: string): string opens node_modules/greeting/index.js
main.foo (alias) function greet(name: string): string opens nothing

The right-click menu has no Go to Source Definition entry in main.foo.

The server supports it

npm run ask sends tsc --lsp the same request on greet in both files:

main.foo definition:        node_modules/greeting/index.d.ts:1:25
main.foo source definition: node_modules/greeting/index.js:1:17
control.ts definition:        node_modules/greeting/index.d.ts:1:25
control.ts source definition: node_modules/greeting/index.js:1:17

Cause

The command checks the language ID before it sends the request (sourceDefinition.ts#L33-L36):

if (!["javascript", "javascriptreact", "typescript", "typescriptreact"].includes(document.languageId)) {
    vscode.window.showErrorMessage(vscode.l10n.t("Go to Source Definition failed. Unsupported file type."));
    return;
}

The right-click menu entry has the same four language IDs in its when clause (package.json#L353-L355). The Command Palette entry has no language condition (package.json#L339-L340), so the command is offered in a content-mapped file and then refuses it.

Suggested fix

Let the command accept the documents that selectorScopedDocumentSelector() in client.ts covers: the static selector plus every content-mapper filter, which hover and multi-document highlight already use (client.ts#L356-L387). For example, check vscode.languages.match(selector, document) instead of the language list. The right-click menu would need a matching condition, such as a context key for the content-mapped extensions.

Related: #64564, where on-auto-insert is also registered only for the static JavaScript and TypeScript selector.

Found while adding TypeScript 7 support for .tsrx files through a content mapper (tsrx-org/tsrx#136).

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions