@@ -73,13 +73,35 @@ export class FileIndexer {
7373 ts . isStringLiteralLike ( node )
7474 ) {
7575 const sym = this . getTSSymbolAtLocation ( node )
76- if ( ts . isConstructorDeclaration ( node ) ) {
77- console . log ( { sym } )
78- }
7976 if ( sym ) {
8077 this . visitSymbolOccurrence ( node , sym )
8178 }
8279 }
80+
81+ if (
82+ ts . isNewExpression ( node ) &&
83+ ts . isIdentifier ( node . expression )
84+ ) {
85+ const sym = this . getTSSymbolAtLocation ( node . expression )
86+ const declaration = sym ?. declarations ?. at ( 0 ) ;
87+ if ( declaration && ts . isClassDeclaration ( declaration ) ) {
88+ for ( const member of declaration . members ) {
89+ if ( ts . isConstructorDeclaration ( member ) ) {
90+ const scipSymbol = this . scipSymbol ( member )
91+ this . pushOccurrence ( new scip . scip . Occurrence ( {
92+ range : Range . fromNode ( node . expression ) . toLsif ( ) ,
93+ symbol : scipSymbol . value ,
94+ } ) )
95+ break
96+ }
97+ }
98+ }
99+
100+ node . typeArguments ? node . typeArguments . forEach ( node => this . visit ( node ) ) : void { }
101+ node . arguments ? node . arguments . forEach ( node => this . visit ( node ) ) : void { }
102+ return
103+ }
104+
83105 ts . forEachChild ( node , node => this . visit ( node ) )
84106 }
85107
@@ -119,7 +141,7 @@ export class FileIndexer {
119141 if ( isDefinitionNode ) {
120142 role |= scip . scip . SymbolRole . Definition
121143 }
122- const declarations = isDefinitionNode
144+ const declarations = ts . isConstructorDeclaration ( node ) ? [ node ] : isDefinitionNode
123145 ? // Don't emit ambiguous definition at definition-site. You can reproduce
124146 // ambiguous results by triggering "Go to definition" in VS Code on `Conflict`
125147 // in the example below:
@@ -312,6 +334,13 @@ export class FileIndexer {
312334 }
313335 }
314336 } )
337+ } else if ( ts . isConstructorDeclaration ( declaration ) ) {
338+ relationships . push (
339+ new scip . scip . Relationship ( {
340+ symbol : declarationSymbol . value ,
341+ is_definition : true ,
342+ } )
343+ )
315344 }
316345 return relationships
317346 }
@@ -487,7 +516,9 @@ export class FileIndexer {
487516 return undefined
488517 }
489518 const signatureDeclaration : ts . SignatureDeclaration | undefined =
490- ts . isFunctionDeclaration ( declaration )
519+ ts . isConstructorDeclaration ( node )
520+ ? node
521+ : ts . isFunctionDeclaration ( declaration )
491522 ? declaration
492523 : ts . isMethodDeclaration ( declaration )
493524 ? declaration
@@ -515,6 +546,9 @@ export class FileIndexer {
515546 return 'type ' + node . getText ( )
516547 case ts . ScriptElementKind . classElement :
517548 case ts . ScriptElementKind . localClassElement :
549+ if ( ts . isConstructorDeclaration ( node ) ) {
550+ return 'constructor' + signature ( )
551+ }
518552 return 'class ' + node . getText ( )
519553 case ts . ScriptElementKind . interfaceElement :
520554 return 'interface ' + node . getText ( )
@@ -776,5 +810,5 @@ function declarationName(node: ts.Node): ts.Node | undefined {
776810 * ^^^^^^^^^^^^^^^^^^^^^ node.parent
777811 */
778812function isDefinition ( node : ts . Node ) : boolean {
779- return declarationName ( node . parent ) === node
813+ return declarationName ( node . parent ) === node || ts . isConstructorDeclaration ( node )
780814}
0 commit comments