@@ -78,6 +78,7 @@ export class ProjectPrincipal {
78
78
} ;
79
79
80
80
findReferences ?: ts . LanguageService [ 'findReferences' ] ;
81
+ getImplementationAtPosition ?: ts . LanguageService [ 'getImplementationAtPosition' ] ;
81
82
82
83
constructor ( {
83
84
compilerOptions,
@@ -260,14 +261,30 @@ export class ProjectPrincipal {
260
261
}
261
262
262
263
public findUnusedMembers ( filePath : string , members : ExportMember [ ] ) {
263
- if ( ! this . findReferences ) {
264
+ if ( ! this . findReferences || ! this . getImplementationAtPosition ) {
264
265
const languageService = ts . createLanguageService ( this . backend . languageServiceHost , ts . createDocumentRegistry ( ) ) ;
265
266
this . findReferences = timerify ( languageService . findReferences ) ;
267
+ this . getImplementationAtPosition = timerify ( languageService . getImplementationAtPosition ) ;
266
268
}
267
269
268
270
return members . filter ( member => {
269
271
if ( member . jsDocTags . has ( PUBLIC_TAG ) ) return false ;
270
- const referencedSymbols = this . findReferences ?.( filePath , member . pos ) ?? [ ] ;
272
+ const implementations =
273
+ this . getImplementationAtPosition ?.( filePath , member . pos ) ?. filter (
274
+ impl => impl . fileName !== filePath || impl . textSpan . start !== member . pos
275
+ ) ?? [ ] ;
276
+
277
+ const referencedSymbols =
278
+ this . findReferences ?.( filePath , member . pos ) ?. filter (
279
+ sym =>
280
+ ! implementations . some (
281
+ impl =>
282
+ impl . fileName === sym . definition . fileName &&
283
+ impl . textSpan . start === sym . definition . textSpan . start &&
284
+ impl . textSpan . length === sym . definition . textSpan . length
285
+ )
286
+ ) ?? [ ] ;
287
+
271
288
const refs = referencedSymbols . flatMap ( refs => refs . references ) . filter ( ref => ! ref . isDefinition ) ;
272
289
return refs . length === 0 ;
273
290
} ) ;
@@ -276,9 +293,10 @@ export class ProjectPrincipal {
276
293
public hasExternalReferences ( filePath : string , exportedItem : Export ) {
277
294
if ( exportedItem . jsDocTags . has ( PUBLIC_TAG ) ) return false ;
278
295
279
- if ( ! this . findReferences ) {
296
+ if ( ! this . findReferences || ! this . getImplementationAtPosition ) {
280
297
const languageService = ts . createLanguageService ( this . backend . languageServiceHost , ts . createDocumentRegistry ( ) ) ;
281
298
this . findReferences = timerify ( languageService . findReferences ) ;
299
+ this . getImplementationAtPosition = timerify ( languageService . getImplementationAtPosition ) ;
282
300
}
283
301
284
302
const referencedSymbols = this . findReferences ( filePath , exportedItem . pos ) ;
0 commit comments