From f01338fa338c3efdd628cc45970593a091de1b9f Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 14 May 2018 18:27:21 -0700 Subject: [PATCH] Comments/naming --- src/server/session.ts | 7 +++++++ src/services/services.ts | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/server/session.ts b/src/server/session.ts index 6cd3a7df560..d0c58b20922 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -700,6 +700,13 @@ namespace ts.server { return definitions.map(def => this.toFileSpan(def.fileName, def.textSpan, project)); } + /* + * 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). + */ private static mapToOriginalLocation(def: T): T { if (def.originalFileName) { Debug.assert(def.originalTextSpan !== undefined, "originalTextSpan should be present if originalFileName is"); diff --git a/src/services/services.ts b/src/services/services.ts index 628892960af..3fcd4e8e151 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1600,10 +1600,10 @@ namespace ts { function makeGetTargetOfMappedPosition( extract: (original: TIn) => sourcemaps.SourceMappableLocation, - create: (result: sourcemaps.SourceMappableLocation, original: TIn, firstOriginal: TIn) => TIn + create: (result: sourcemaps.SourceMappableLocation, unmapped: TIn, original: TIn) => TIn ) { return getTargetOfMappedPosition; - function getTargetOfMappedPosition(input: TIn, firstOriginal = input): TIn { + function getTargetOfMappedPosition(input: TIn, original = input): TIn { const info = extract(input); if (endsWith(info.fileName, Extension.Dts)) { let file: SourceFileLike = program.getSourceFile(info.fileName); @@ -1617,7 +1617,7 @@ namespace ts { const mapper = getSourceMapper(info.fileName, file); const newLoc = mapper.getOriginalPosition(info); if (newLoc === info) return input; - return getTargetOfMappedPosition(create(newLoc, input, firstOriginal), firstOriginal); + return getTargetOfMappedPosition(create(newLoc, input, original), original); } return input; } @@ -1625,7 +1625,7 @@ namespace ts { const getTargetOfMappedDeclarationInfo = makeGetTargetOfMappedPosition( (info: DefinitionInfo) => ({ fileName: info.fileName, position: info.textSpan.start }), - (newLoc, info, firstOriginal) => ({ + (newLoc, info, original) => ({ containerKind: info.containerKind, containerName: info.containerName, fileName: newLoc.fileName, @@ -1635,8 +1635,8 @@ namespace ts { start: newLoc.position, length: info.textSpan.length }, - originalFileName: firstOriginal.fileName, - originalTextSpan: firstOriginal.textSpan + originalFileName: original.fileName, + originalTextSpan: original.textSpan }) );