Skip to content

Commit f01338f

Browse files
committed
Comments/naming
1 parent 64b1c23 commit f01338f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/server/session.ts

+7
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,13 @@ namespace ts.server {
700700
return definitions.map(def => this.toFileSpan(def.fileName, def.textSpan, project));
701701
}
702702

703+
/*
704+
* When we map a .d.ts location to .ts, Visual Studio gets confused because there's no associated Roslyn Document in
705+
* the same project which corresponds to the file. VS Code has no problem with this, and luckily we have two protocols.
706+
* This retains the existing behavior for the "simplified" (VS Code) protocol but stores the .d.ts location in a
707+
* set of additional fields, and does the reverse for VS (store the .d.ts location where
708+
* it used to be and stores the .ts location in the additional fields).
709+
*/
703710
private static mapToOriginalLocation<T extends DocumentSpan>(def: T): T {
704711
if (def.originalFileName) {
705712
Debug.assert(def.originalTextSpan !== undefined, "originalTextSpan should be present if originalFileName is");

src/services/services.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1600,10 +1600,10 @@ namespace ts {
16001600

16011601
function makeGetTargetOfMappedPosition<TIn>(
16021602
extract: (original: TIn) => sourcemaps.SourceMappableLocation,
1603-
create: (result: sourcemaps.SourceMappableLocation, original: TIn, firstOriginal: TIn) => TIn
1603+
create: (result: sourcemaps.SourceMappableLocation, unmapped: TIn, original: TIn) => TIn
16041604
) {
16051605
return getTargetOfMappedPosition;
1606-
function getTargetOfMappedPosition(input: TIn, firstOriginal = input): TIn {
1606+
function getTargetOfMappedPosition(input: TIn, original = input): TIn {
16071607
const info = extract(input);
16081608
if (endsWith(info.fileName, Extension.Dts)) {
16091609
let file: SourceFileLike = program.getSourceFile(info.fileName);
@@ -1617,15 +1617,15 @@ namespace ts {
16171617
const mapper = getSourceMapper(info.fileName, file);
16181618
const newLoc = mapper.getOriginalPosition(info);
16191619
if (newLoc === info) return input;
1620-
return getTargetOfMappedPosition(create(newLoc, input, firstOriginal), firstOriginal);
1620+
return getTargetOfMappedPosition(create(newLoc, input, original), original);
16211621
}
16221622
return input;
16231623
}
16241624
}
16251625

16261626
const getTargetOfMappedDeclarationInfo = makeGetTargetOfMappedPosition(
16271627
(info: DefinitionInfo) => ({ fileName: info.fileName, position: info.textSpan.start }),
1628-
(newLoc, info, firstOriginal) => ({
1628+
(newLoc, info, original) => ({
16291629
containerKind: info.containerKind,
16301630
containerName: info.containerName,
16311631
fileName: newLoc.fileName,
@@ -1635,8 +1635,8 @@ namespace ts {
16351635
start: newLoc.position,
16361636
length: info.textSpan.length
16371637
},
1638-
originalFileName: firstOriginal.fileName,
1639-
originalTextSpan: firstOriginal.textSpan
1638+
originalFileName: original.fileName,
1639+
originalTextSpan: original.textSpan
16401640
})
16411641
);
16421642

0 commit comments

Comments
 (0)