Skip to content

Commit

Permalink
feat(typescript_indexer): add ref/id from constructor calls to class …
Browse files Browse the repository at this point in the history
…nodes (#5534)
  • Loading branch information
nbeloglazov authored Mar 23, 2023
1 parent 2d9bc38 commit fbf4be9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions kythe/typescript/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,16 @@ class Visitor {
if (refType == RefType.WRITE || refType == RefType.READ_WRITE) {
this.emitEdge(anchor, EdgeKind.REF_WRITES, name);
}
// For classes emit ref/id to the type node in addition to regular
// ref. When user check refs for a class - they usually check get
// refs of the class node, not the constructor node. That's why
// we need ref/id from all usages to the class node.
if (sym.flags & ts.SymbolFlags.Class) {
const className = this.host.getSymbolName(sym, TSNamespace.TYPE);
if (className != null) {
this.emitEdge(anchor, EdgeKind.REF_ID, className);
}
}
this.addInfluencer(name);
}

Expand Down
5 changes: 5 additions & 0 deletions kythe/typescript/testdata/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ class SubSubclass extends Class implements IExtended {
}

//- @Class ref ClassValue
//- @Class ref/id Class
let instance = new Class(3, 'a');
//- @otherMember ref OtherMember
instance.otherMember;

// Using Class in type position should still create a link to the class.
//- @Class ref Class
let useAsType: Class = instance;

//- @Class ref ClassValue
//- @Class ref/id Class
Class;

0 comments on commit fbf4be9

Please sign in to comment.