Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSCode doesn't respect sourceRoot in declarationMaps #25322

Closed
michaelaird opened this issue Jun 29, 2018 · 12 comments
Closed

VSCode doesn't respect sourceRoot in declarationMaps #25322

michaelaird opened this issue Jun 29, 2018 · 12 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@michaelaird
Copy link

michaelaird commented Jun 29, 2018

TypeScript Version: 2.9.2

I'm running into an issue when building declaration maps with gulp-typescript/gulp-sourcemaps.

the output of gulp-sourcemaps does this:

{"version":3,"sources":["BaseClass.ts"],"names":[],"mappings":"AAAA,kBAAU,UAAU,CACpB;IACI;QAEI,OAAO,CAAC,UAAU,CAAS;;2BAOb,SAAS,EAAK,MAAM;QAK3B,WAAW,IAAI,IAAI;KAI7B;CACJ","file":"Dependency.d.ts","sourceRoot":"../../Dependency"}

where the output of tsc does this:

{"version":3,"file":"Dependency.d.ts","sourceRoot":"","sources":["../../Dependency/BaseClass.ts"],"names":[],"mappings":"AAAA,kBAAU,UAAU,CACpB;IACI;QAEI,OAAO,CAAC,UAAU,CAAS;;2BAOb,SAAS,EAAK,MAAM;QAK3B,WAAW,IAAI,IAAI;KAI7B;CACJ"}

Expected behavior:

VSCode should respect sourceRoot and find the source code

Actual behavior:

VSCode can't find the declaration when navigating.

I can provide a simple repro if needed.

Note

In VSCode, when you try to navigate it does nothing. In VS 15.8.0 Preview 3 it navigates to the d.ts file.

@mhegazy mhegazy added the Bug A bug in TypeScript label Jun 29, 2018
@mhegazy mhegazy added this to the TypeScript 3.0 milestone Jun 29, 2018
@weswigham
Copy link
Member

weswigham commented Jun 29, 2018

@michaelaird what command line options are you compiling with (your tsconfig and/or command line settings) when you're using vscode?

@michaelaird
Copy link
Author

michaelaird commented Jun 29, 2018 via email

@weswigham
Copy link
Member

Hmmmmm the only differences I see are that we set sourceRoot to "" and each of the paths in sources to be relative to the sourcemap directly (so ../../Dependency/BaseClass.ts), while your other sourcemap tool has removed the common path part from all the sources (../../Dependency) and placed it as the sourceRoot (leaving the source filename as just BaseClass.ts).

AFAIK these should function identically. - in both cases applying the sourceRoot to the sourcemaps's dir and joining the filename should yield the same final path.

If anything, "sourceRoot":"../../Dependency" from gulp-sourcemaps is missing a tailing slash 🤷‍♂️

But anyway - I think I'm going to need more to reproduce your issue; both of those sourcemaps should work fine. Also it'd be nice if you could check if the issue still repros when you use typescript@next's tsserver, since we have made a bunch of fixes to the sourcemaped LS calls recently.

@vvs
Copy link

vvs commented Jul 8, 2018

I am seeing the same problem with TS 2.9.2, the sourcemaps for *.d.ts files, generated by gulp-sourcemaps are unusable in VS Code (latest insiders), since the navigation is completely disabled.

In the latest TS@next, the navigation is restored, but I end up in the *.d.ts file, NOT the actual *.ts file.

The difference between the tsc's generated maps and the ones generated via gulp-sourcemaps, is that:

  1. TSC: sourceRoot: "", sources:["../../../../name.ts"]
  2. gulp-sourcemaps: sourceRoot: "../../", sources: ["../../name.ts"]

So, the end-result should be the same, but it is not, VS Code properly works with the first version.

@michaelaird
Copy link
Author

@weswigham I can share a small repro project. where should I send it?

@weswigham
Copy link
Member

weswigham commented Jul 10, 2018

If public, here. Failing that, mhegazy at Microsoft dot com is a decent option. In any case, in pretty sure I know the issue. In sourcemapDecoder.ts, where it says const sourceRoot = map.sourceRoot || currentDirectory toPath needs to be called on map.sourceRoot if present, to ensure we always have a rooted absolute path.

@michaelaird
Copy link
Author

michaelaird commented Jul 17, 2018

@weswigham I sent a small repro to @mhegazy .

Edit: attaching the repro here because MS's email server is too smart.
DeclarationMaps.zip

@michaelaird
Copy link
Author

This still fails when project references are used.

Here's a repro:
DeclarationMaps.zip

@mhegazy
Copy link
Contributor

mhegazy commented Jul 26, 2018

@weswigham can you take a look

@weswigham
Copy link
Member

weswigham commented Jul 26, 2018

@michaelaird The sourceRoot generated by gulp-sourcemaps is off. It's emitting "sourceRoot":"../../DeclarationMaps/Dependency", when it should just be "sourceRoot":"../../Dependency", since the file is in /Output/js and the sources are in /Dependency. It looks like your gulp task is moving around the outdir in a way it doesn't respect?

@michaelaird
Copy link
Author

Yep. you're right. i'll fight with gulp-sourcemaps to sort out the relative paths. sorry about the false alarm!

@domoritz
Copy link

domoritz commented Jul 7, 2021

@michaelaird have you figured out how to get declarationMap working with gulp-sourcemaps? Could you share a repo where you used it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants