Return mapped locations in alternate fields

This commit is contained in:
Ryan Cavanaugh 2018-05-02 14:16:39 -07:00
parent dfef2fa9a2
commit 69f73eba16
3 changed files with 36 additions and 12 deletions

View File

@ -665,9 +665,8 @@ namespace ts.server {
if (simplifiedResult) {
return this.mapDefinitionInfo(definitions, project);
}
else {
return definitions;
}
return definitions.map(Session.mapToOriginalLocation);
}
private getDefinitionAndBoundSpan(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.DefinitionInfoAndBoundSpan | DefinitionInfoAndBoundSpan {
@ -691,13 +690,30 @@ namespace ts.server {
};
}
return definitionAndBoundSpan;
return {
...definitionAndBoundSpan,
definitions: definitionAndBoundSpan.definitions.map(Session.mapToOriginalLocation)
};
}
private mapDefinitionInfo(definitions: ReadonlyArray<DefinitionInfo>, project: Project): ReadonlyArray<protocol.FileSpan> {
return definitions.map(def => this.toFileSpan(def.fileName, def.textSpan, project));
}
private static mapToOriginalLocation<T extends DocumentSpan>(def: T): T {
if (def.originalFileName) {
Debug.assert(def.originalTextSpan !== undefined, "originalTextSpan should be present if originalFileName is");
return {
...<any>def,
fileName: def.originalFileName,
textSpan: def.originalTextSpan,
targetFileName: def.fileName,
targetTextSpan: def.textSpan
};
}
return def;
}
private toFileSpan(fileName: string, textSpan: TextSpan, project: Project): protocol.FileSpan {
const ls = project.getLanguageService();
const start = ls.toLineColumnOffset(fileName, textSpan.start);
@ -732,9 +748,8 @@ namespace ts.server {
if (simplifiedResult) {
return implementations.map(({ fileName, textSpan }) => this.toFileSpan(fileName, textSpan, project));
}
else {
return implementations;
}
return implementations.map(Session.mapToOriginalLocation);
}
private getOccurrences(args: protocol.FileLocationRequestArgs): ReadonlyArray<protocol.OccurrencesResponseItem> {

View File

@ -1634,7 +1634,9 @@ namespace ts {
textSpan: {
start: newLoc.position,
length: info.textSpan.length
}
},
originalFileName: info.fileName,
originalTextSpan: info.textSpan
})
);
@ -1678,7 +1680,9 @@ namespace ts {
textSpan: {
start: newLoc.position,
length: info.textSpan.length
}
},
originalFileName: info.fileName,
originalTextSpan: info.textSpan
})
);

View File

@ -542,6 +542,13 @@ namespace ts {
export interface DocumentSpan {
textSpan: TextSpan;
fileName: string;
/**
* 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
*/
originalTextSpan?: TextSpan;
originalFileName?: string;
}
export interface RenameLocation extends DocumentSpan {
@ -654,9 +661,7 @@ namespace ts {
indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean;
}
export interface DefinitionInfo {
fileName: string;
textSpan: TextSpan;
export interface DefinitionInfo extends DocumentSpan {
kind: ScriptElementKind;
name: string;
containerKind: ScriptElementKind;