feat(44736): add go-to-definition on overridden members (#44740)

This commit is contained in:
Oleksandr T
2021-06-29 00:58:06 +03:00
committed by GitHub
parent 54b913cf31
commit 066796be54
16 changed files with 229 additions and 1 deletions

View File

@@ -12,10 +12,14 @@ namespace ts.GoToDefinition {
if (node === sourceFile) {
return undefined;
}
const { parent } = node;
const { parent } = node;
const typeChecker = program.getTypeChecker();
if (node.kind === SyntaxKind.OverrideKeyword || (isJSDocOverrideTag(node) && rangeContainsPosition(node.tagName, position))) {
return getDefinitionFromOverriddenMember(typeChecker, node) || emptyArray;
}
// Labels
if (isJumpStatementTarget(node)) {
const label = getTargetLabel(node.parent, node.text);
@@ -126,6 +130,26 @@ namespace ts.GoToDefinition {
}
}
function getDefinitionFromOverriddenMember(typeChecker: TypeChecker, node: Node) {
const classElement = findAncestor(node, isClassElement);
if (!(classElement && classElement.name)) return;
const baseDeclaration = findAncestor(classElement, isClassLike);
if (!baseDeclaration) return;
const baseTypeNode = getEffectiveBaseTypeNode(baseDeclaration);
const baseType = baseTypeNode ? typeChecker.getTypeAtLocation(baseTypeNode) : undefined;
if (!baseType) return;
const name = unescapeLeadingUnderscores(getTextOfPropertyName(classElement.name));
const symbol = hasStaticModifier(classElement)
? typeChecker.getPropertyOfType(typeChecker.getTypeOfSymbolAtLocation(baseType.symbol, baseDeclaration), name)
: typeChecker.getPropertyOfType(baseType, name);
if (!symbol) return;
return getDefinitionFromSymbol(typeChecker, symbol, node);
}
export function getReferenceAtPosition(sourceFile: SourceFile, position: number, program: Program): { reference: FileReference, fileName: string, unverified: boolean, file?: SourceFile } | undefined {
const referencePath = findReferenceInPosition(sourceFile.referencedFiles, position);
if (referencePath) {