in server/src/session.ts [912:948]
private tsDefinitionsToLspLocationLinks(
definitions: readonly ts.DefinitionInfo[],
originSelectionRange?: lsp.Range): lsp.LocationLink[] {
const results: lsp.LocationLink[] = [];
for (const d of definitions) {
const scriptInfo = this.projectService.getScriptInfo(d.fileName);
// Some definitions, like definitions of CSS files, may not be recorded files with a
// `scriptInfo` but are still valid definitions because they are files that exist. In this
// case, check to make sure that the text span of the definition is zero so that the file
// doesn't have to be read; if the span is non-zero, we can't do anything with this
// definition.
if (!scriptInfo && d.textSpan.length > 0) {
continue;
}
let mappedInfo = d;
let range = EMPTY_RANGE;
if (scriptInfo) {
const project = this.getDefaultProjectForScriptInfo(scriptInfo);
mappedInfo = project ? getMappedDefinitionInfo(d, project) : mappedInfo;
// After the DTS file maps to original source file, the `scriptInfo` should be updated.
const originalScriptInfo =
this.projectService.getScriptInfo(mappedInfo.fileName) ?? scriptInfo;
range = tsTextSpanToLspRange(originalScriptInfo, mappedInfo.textSpan);
}
const targetUri = filePathToUri(mappedInfo.fileName);
results.push({
originSelectionRange,
targetUri,
targetRange: range,
targetSelectionRange: range,
});
}
return results;
}