Skip to content

Commit 3fe103c

Browse files
committed
fix: disable removeDefinitionFromReferences in js class prop definitions
fixes #165
1 parent be05d62 commit 3fe103c

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

typescript/src/references.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
import { GetConfig } from './types'
2-
import { findChildContainingPositionMaxDepth, approveCast } from './utils'
2+
import { findChildContainingPositionMaxDepth, approveCast, findChildContainingExactPosition, matchParents } from './utils'
33

44
export default (proxy: ts.LanguageService, languageService: ts.LanguageService, c: GetConfig) => {
55
proxy.findReferences = (fileName, position) => {
66
let prior = languageService.findReferences(fileName, position)
77
if (!prior) return
8+
const program = languageService.getProgram()!
89
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+
}
1330
}
1431
if (c('removeImportsFromReferences')) {
15-
const program = languageService.getProgram()!
1632
const refCountPerFileName: Record<
1733
string,
1834
{

0 commit comments

Comments
 (0)