microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.23k stars 12.39k forks source link

Use sourcemap sources for Go to Implementation and show them in Explorer pane (like Chrome devtools does), even when no debug session is active #53723

Open justingrant opened 1 year ago

justingrant commented 1 year ago

Summary

VS Code should treat the sourcesContent inside source map files (and inline sourcemaps too) as if they were real, read-only, virtual files that exist in the IDE whether or not a debug session is running, similar to how Chrome dev tools exposes sourcemap code.

The user should be able to see sourcemap code as files in the IDE's Explorer pane, should be able to set breakpoints in them without the debugger running, should be able to use Go to Implementation to read library source code, and more.

This feature is a superset of microsoft/vscode#144424, which is a debugger-only, inline-sourcemap-only request.

Justification

A large and increasing portion of packages in the npm registry are transpiled or bundled. Often this is because the original source is TypeScript. Or because the author wants to write ES2021+ code and rely on babel or other transpilers for downlevel support. Or for many other reasons. Package authors have gotten much better about also shipping sourcemaps with their packages.

However, frequently package authors DON'T include the original source files of their package in their NPM distribution. They only ship bundled and/or transpiled JS code, and sourcemaps. Often this is based on strong recommendations from other package authors to omit sources. For example:

image

My point here isn't to hassle @jakebailey (he later amended this to soften the recommendation), but rather to point out that this "don't ship source files" sentiment is common among JS package maintainers.

Sadly, multiple VS Code features don't work well when original source files are unavailable. In particular:

But despite these challenges that users have with missing sources in packages, there are many of reasons why package authors don't want to ship sources in their npm packages. Here's a few I've heard:

Some of these reasons are technical problems that cause real user bug reports and complaints, which package maintainers always want to avoid. Other reasons stem from the fact that package maintainers are usually much more experienced JS developers than package users, so it's harder for them to understand the profound difficulty that novice JS developers have with basic tasks like setting breakpoints in library code, finding the implementation of a particular function, or even reading transpiled code.

Over the last 4 years, I've filed ~20 PRs to try to get package maintainers to ship sources and to fix broken sourcemaps. But, to be honest, I've barely made a dent.

So I think it's time for VS Code to recognize that many package maintainers will *never* ship their sources. But they will ship Chrome-dev-tools-friendly sourcemaps! Can we use those sourcemaps to help developers read and understand library code?

Proposal

VS Code should start treating sourcesContent and inline sourcemaps as read-only, virtual source files that are first-class citizens in the IDE.

Top Priority cases:

Lower-priority cases (these are less important to users and/or may have performance issues that may make them really hard to implement)

There would have to be some limits and constraints:

What I'm asking for here might be very expensive if VS Code doesn't currently have a "virtual file" capability in the IDE. But after 4 years of trying to convince maintainers to ship their sources to enable a better VS Code experience, I'm starting to believe that the easiest and most realistic solution might be to change VS Code instead of trying to convince every maintainer one at a time.

Thanks for listening!

roblourens commented 1 year ago

This is really a feature request for the ts/js language server. It might belong in the Typescript repo

justingrant commented 1 year ago

This is really a feature request for the ts/js language server. It might belong in the Typescript repo

@roblourens Does VS Code's file explorer pane currently have the ability (like Chrome Dev Tools does) to show "virtual" files that don't exist on disk? Or is every file in the explorer pane required to exist on disk?