|
1 | 1 | import { GetConfig } from './types'
|
2 |
| -import { findChildContainingPositionMaxDepth, approveCast } from './utils' |
| 2 | +import { findChildContainingPositionMaxDepth, approveCast, findChildContainingExactPosition, matchParents } from './utils' |
3 | 3 |
|
4 | 4 | export default (proxy: ts.LanguageService, languageService: ts.LanguageService, c: GetConfig) => {
|
5 | 5 | proxy.findReferences = (fileName, position) => {
|
6 | 6 | let prior = languageService.findReferences(fileName, position)
|
7 | 7 | if (!prior) return
|
| 8 | + const program = languageService.getProgram()! |
8 | 9 | if (c('removeDefinitionFromReferences')) {
|
9 |
| - prior = prior.map(({ references, ...other }) => ({ |
10 |
| - ...other, |
11 |
| - references: references.filter(({ isDefinition }) => !isDefinition), |
12 |
| - })) |
| 10 | + const sourceFile = program.getSourceFile(fileName) |
| 11 | + const node = findChildContainingExactPosition(sourceFile!, position) |
| 12 | + let filterDefs = true |
| 13 | + if ( |
| 14 | + node && |
| 15 | + node.flags & ts.NodeFlags.JavaScriptFile && |
| 16 | + matchParents(node, ['Identifier', 'PropertyAccessExpression'])?.expression.kind === ts.SyntaxKind.ThisKeyword |
| 17 | + ) { |
| 18 | + // https://github.com/zardoy/typescript-vscode-plugins/issues/165 |
| 19 | + filterDefs = false |
| 20 | + } |
| 21 | + |
| 22 | + if (filterDefs) { |
| 23 | + prior = prior.map(({ references, ...other }) => ({ |
| 24 | + ...other, |
| 25 | + references: references.filter(({ isDefinition, textSpan, fileName }) => { |
| 26 | + return !isDefinition |
| 27 | + }), |
| 28 | + })) |
| 29 | + } |
13 | 30 | }
|
14 | 31 | if (c('removeImportsFromReferences')) {
|
15 |
| - const program = languageService.getProgram()! |
16 | 32 | const refCountPerFileName: Record<
|
17 | 33 | string,
|
18 | 34 | {
|
|
0 commit comments