2016-11-22 09:10:23 -08:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2019-07-31 10:55:45 -07:00
|
|
|
import * as tss from 'typescript/lib/tsserverlibrary';
|
|
|
|
|
|
2016-11-22 09:10:23 -08:00
|
|
|
import {TemplateInfo} from './common';
|
|
|
|
|
import {locateSymbol} from './locate_symbol';
|
2019-07-31 10:55:45 -07:00
|
|
|
import {Location} from './types';
|
2016-11-22 09:10:23 -08:00
|
|
|
|
2019-07-31 10:55:45 -07:00
|
|
|
export function getDefinition(info: TemplateInfo): Location[]|undefined {
|
2016-11-22 09:10:23 -08:00
|
|
|
const result = locateSymbol(info);
|
|
|
|
|
return result && result.symbol.definition;
|
|
|
|
|
}
|
2019-07-31 10:55:45 -07:00
|
|
|
|
|
|
|
|
export function ngLocationToTsDefinitionInfo(loc: Location): tss.DefinitionInfo {
|
|
|
|
|
return {
|
|
|
|
|
fileName: loc.fileName,
|
|
|
|
|
textSpan: {
|
|
|
|
|
start: loc.span.start,
|
|
|
|
|
length: loc.span.end - loc.span.start,
|
|
|
|
|
},
|
|
|
|
|
// TODO(kyliau): Provide more useful info for name, kind and containerKind
|
|
|
|
|
name: '', // should be name of symbol but we don't have enough information here.
|
|
|
|
|
kind: tss.ScriptElementKind.unknown,
|
|
|
|
|
containerName: loc.fileName,
|
|
|
|
|
containerKind: tss.ScriptElementKind.unknown,
|
|
|
|
|
};
|
|
|
|
|
}
|