Skip to content

Return mapped locations in alternate fields#24074

Merged
RyanCavanaugh merged 4 commits into
microsoft:masterfrom
RyanCavanaugh:splitTransparentGoToDef
May 15, 2018
Merged

Return mapped locations in alternate fields#24074
RyanCavanaugh merged 4 commits into
microsoft:masterfrom
RyanCavanaugh:splitTransparentGoToDef

Conversation

@RyanCavanaugh
Copy link
Copy Markdown
Member

When we map a .d.ts location to .ts, Visual Studio gets confused because there's no associated Roslyn Document in the same project which corresponds to the file. VS Code has no problem with this, and luckily we have two protocols.

This retains the existing behavior for the "simplified" (VS Code) protocol but stores the .d.ts location in a set of additional fields, and does the reverse for VS (store the .d.ts location where it used to be and stores the .ts location in the additional fields).

This gives both editors maximum flexibility in terms of how they treat go-to-def requests which land in sourcemapped .d.ts files.

I have a separate PR on the managed side to consume these fields when they are present.

@RyanCavanaugh RyanCavanaugh requested a review from weswigham May 12, 2018 00:31
Copy link
Copy Markdown
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

Small comments, maybe one change to the original that probably needs to happen, given that maps can be chained into one another.

Comment thread src/server/session.ts
if (def.originalFileName) {
Debug.assert(def.originalTextSpan !== undefined, "originalTextSpan should be present if originalFileName is");
return {
...<any>def,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lemme guess: excess property warning?

Copy link
Copy Markdown
Member Author

@RyanCavanaugh RyanCavanaugh May 14, 2018

Choose a reason for hiding this comment

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

"Spread types may only be created from object types" (even if T is constrained to DocumentSpan & object!)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This also requires any rather than a different cast because we don't believe that the returned object literal actually conforms to T

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So it's a symptom of how we don't have higher order spread types. :3

Comment thread src/services/types.ts

/**
* If the span represents a location that was remapped (e.g. via a .d.ts.map file),
* then the original filename and span will be specified here
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it worth noting that it may have been mapped multiple times and that (from what I can tell) this isnt currently the original-original, but rather just one step back from the final mapping?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll update the code to return the true original

Comment thread src/services/services.ts Outdated
function makeGetTargetOfMappedPosition<TIn>(
extract: (original: TIn) => sourcemaps.SourceMappableLocation,
create: (result: sourcemaps.SourceMappableLocation, original: TIn) => TIn
create: (result: sourcemaps.SourceMappableLocation, original: TIn, firstOriginal: TIn) => TIn
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

original: TIn, firstOriginal: TIn [](start = 64, length = 33)

As I suggested offline, I think unmapped and original would be clearer.

Comment thread src/server/session.ts
return definitions.map(def => this.toFileSpan(def.fileName, def.textSpan, project));
}

private static mapToOriginalLocation<T extends DocumentSpan>(def: T): T {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mapToOriginalLocation [](start = 23, length = 21)

This name isn't very descriptive but I can't think of one that would be. I'd suggest putting a simplified version of your commit message in the doc comment for this function.

Copy link
Copy Markdown
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

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

:shipit:

@RyanCavanaugh
Copy link
Copy Markdown
Member Author

Travis Node 6 failure seems to be unrelated

@RyanCavanaugh RyanCavanaugh merged commit 2ca0792 into microsoft:master May 15, 2018
@RyanCavanaugh RyanCavanaugh deleted the splitTransparentGoToDef branch May 15, 2018 17:42
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
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.

3 participants