Skip to content

Commit 69f73eb

Browse files
committed
Return mapped locations in alternate fields
1 parent dfef2fa commit 69f73eb

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

src/server/session.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,8 @@ namespace ts.server {
665665
if (simplifiedResult) {
666666
return this.mapDefinitionInfo(definitions, project);
667667
}
668-
else {
669-
return definitions;
670-
}
668+
669+
return definitions.map(Session.mapToOriginalLocation);
671670
}
672671

673672
private getDefinitionAndBoundSpan(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.DefinitionInfoAndBoundSpan | DefinitionInfoAndBoundSpan {
@@ -691,13 +690,30 @@ namespace ts.server {
691690
};
692691
}
693692

694-
return definitionAndBoundSpan;
693+
return {
694+
...definitionAndBoundSpan,
695+
definitions: definitionAndBoundSpan.definitions.map(Session.mapToOriginalLocation)
696+
};
695697
}
696698

697699
private mapDefinitionInfo(definitions: ReadonlyArray<DefinitionInfo>, project: Project): ReadonlyArray<protocol.FileSpan> {
698700
return definitions.map(def => this.toFileSpan(def.fileName, def.textSpan, project));
699701
}
700702

703+
private static mapToOriginalLocation<T extends DocumentSpan>(def: T): T {
704+
if (def.originalFileName) {
705+
Debug.assert(def.originalTextSpan !== undefined, "originalTextSpan should be present if originalFileName is");
706+
return {
707+
...<any>def,
708+
fileName: def.originalFileName,
709+
textSpan: def.originalTextSpan,
710+
targetFileName: def.fileName,
711+
targetTextSpan: def.textSpan
712+
};
713+
}
714+
return def;
715+
}
716+
701717
private toFileSpan(fileName: string, textSpan: TextSpan, project: Project): protocol.FileSpan {
702718
const ls = project.getLanguageService();
703719
const start = ls.toLineColumnOffset(fileName, textSpan.start);
@@ -732,9 +748,8 @@ namespace ts.server {
732748
if (simplifiedResult) {
733749
return implementations.map(({ fileName, textSpan }) => this.toFileSpan(fileName, textSpan, project));
734750
}
735-
else {
736-
return implementations;
737-
}
751+
752+
return implementations.map(Session.mapToOriginalLocation);
738753
}
739754

740755
private getOccurrences(args: protocol.FileLocationRequestArgs): ReadonlyArray<protocol.OccurrencesResponseItem> {

src/services/services.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,9 @@ namespace ts {
16341634
textSpan: {
16351635
start: newLoc.position,
16361636
length: info.textSpan.length
1637-
}
1637+
},
1638+
originalFileName: info.fileName,
1639+
originalTextSpan: info.textSpan
16381640
})
16391641
);
16401642

@@ -1678,7 +1680,9 @@ namespace ts {
16781680
textSpan: {
16791681
start: newLoc.position,
16801682
length: info.textSpan.length
1681-
}
1683+
},
1684+
originalFileName: info.fileName,
1685+
originalTextSpan: info.textSpan
16821686
})
16831687
);
16841688

src/services/types.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,13 @@ namespace ts {
542542
export interface DocumentSpan {
543543
textSpan: TextSpan;
544544
fileName: string;
545+
546+
/**
547+
* If the span represents a location that was remapped (e.g. via a .d.ts.map file),
548+
* then the original filename and span will be specified here
549+
*/
550+
originalTextSpan?: TextSpan;
551+
originalFileName?: string;
545552
}
546553

547554
export interface RenameLocation extends DocumentSpan {
@@ -654,9 +661,7 @@ namespace ts {
654661
indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean;
655662
}
656663

657-
export interface DefinitionInfo {
658-
fileName: string;
659-
textSpan: TextSpan;
664+
export interface DefinitionInfo extends DocumentSpan {
660665
kind: ScriptElementKind;
661666
name: string;
662667
containerKind: ScriptElementKind;

0 commit comments

Comments
 (0)