@@ -73,13 +73,35 @@ export class FileIndexer {
73
73
ts . isStringLiteralLike ( node )
74
74
) {
75
75
const sym = this . getTSSymbolAtLocation ( node )
76
- if ( ts . isConstructorDeclaration ( node ) ) {
77
- console . log ( { sym } )
78
- }
79
76
if ( sym ) {
80
77
this . visitSymbolOccurrence ( node , sym )
81
78
}
82
79
}
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
+
83
105
ts . forEachChild ( node , node => this . visit ( node ) )
84
106
}
85
107
@@ -119,7 +141,7 @@ export class FileIndexer {
119
141
if ( isDefinitionNode ) {
120
142
role |= scip . scip . SymbolRole . Definition
121
143
}
122
- const declarations = isDefinitionNode
144
+ const declarations = ts . isConstructorDeclaration ( node ) ? [ node ] : isDefinitionNode
123
145
? // Don't emit ambiguous definition at definition-site. You can reproduce
124
146
// ambiguous results by triggering "Go to definition" in VS Code on `Conflict`
125
147
// in the example below:
@@ -312,6 +334,13 @@ export class FileIndexer {
312
334
}
313
335
}
314
336
} )
337
+ } else if ( ts . isConstructorDeclaration ( declaration ) ) {
338
+ relationships . push (
339
+ new scip . scip . Relationship ( {
340
+ symbol : declarationSymbol . value ,
341
+ is_definition : true ,
342
+ } )
343
+ )
315
344
}
316
345
return relationships
317
346
}
@@ -487,7 +516,9 @@ export class FileIndexer {
487
516
return undefined
488
517
}
489
518
const signatureDeclaration : ts . SignatureDeclaration | undefined =
490
- ts . isFunctionDeclaration ( declaration )
519
+ ts . isConstructorDeclaration ( node )
520
+ ? node
521
+ : ts . isFunctionDeclaration ( declaration )
491
522
? declaration
492
523
: ts . isMethodDeclaration ( declaration )
493
524
? declaration
@@ -515,6 +546,9 @@ export class FileIndexer {
515
546
return 'type ' + node . getText ( )
516
547
case ts . ScriptElementKind . classElement :
517
548
case ts . ScriptElementKind . localClassElement :
549
+ if ( ts . isConstructorDeclaration ( node ) ) {
550
+ return 'constructor' + signature ( )
551
+ }
518
552
return 'class ' + node . getText ( )
519
553
case ts . ScriptElementKind . interfaceElement :
520
554
return 'interface ' + node . getText ( )
@@ -776,5 +810,5 @@ function declarationName(node: ts.Node): ts.Node | undefined {
776
810
* ^^^^^^^^^^^^^^^^^^^^^ node.parent
777
811
*/
778
812
function isDefinition ( node : ts . Node ) : boolean {
779
- return declarationName ( node . parent ) === node
813
+ return declarationName ( node . parent ) === node || ts . isConstructorDeclaration ( node )
780
814
}
0 commit comments