Skip to content

Commit aa48a37

Browse files
authored
fix(48673): allow Find All References on access modifier for constructor (microsoft#48813)
1 parent d6e483b commit aa48a37

9 files changed

+296
-0
lines changed

src/services/utilities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,8 @@ namespace ts {
806806
case SyntaxKind.FunctionDeclaration:
807807
case SyntaxKind.FunctionExpression:
808808
return getAdjustedLocationForFunction(node as FunctionDeclaration | FunctionExpression);
809+
case SyntaxKind.Constructor:
810+
return node;
809811
}
810812
}
811813
if (isNamedDeclaration(node)) {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// === /tests/cases/fourslash/constructorFindAllReferences1.ts ===
2+
// export class C {
3+
// /*FIND ALL REFS*/public [|constructor|]() { }
4+
// public foo() { }
5+
// }
6+
//
7+
// new [|C|]().foo();
8+
9+
[
10+
{
11+
"definition": {
12+
"containerKind": "",
13+
"containerName": "",
14+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences1.ts",
15+
"kind": "class",
16+
"name": "class C",
17+
"textSpan": {
18+
"start": 13,
19+
"length": 1
20+
},
21+
"displayParts": [
22+
{
23+
"text": "class",
24+
"kind": "keyword"
25+
},
26+
{
27+
"text": " ",
28+
"kind": "space"
29+
},
30+
{
31+
"text": "C",
32+
"kind": "className"
33+
}
34+
],
35+
"contextSpan": {
36+
"start": 0,
37+
"length": 68
38+
}
39+
},
40+
"references": [
41+
{
42+
"textSpan": {
43+
"start": 28,
44+
"length": 11
45+
},
46+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences1.ts",
47+
"contextSpan": {
48+
"start": 21,
49+
"length": 24
50+
},
51+
"isWriteAccess": false
52+
},
53+
{
54+
"textSpan": {
55+
"start": 74,
56+
"length": 1
57+
},
58+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences1.ts",
59+
"isWriteAccess": false
60+
}
61+
]
62+
}
63+
]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// === /tests/cases/fourslash/constructorFindAllReferences2.ts ===
2+
// export class C {
3+
// /*FIND ALL REFS*/private [|constructor|]() { }
4+
// public foo() { }
5+
// }
6+
//
7+
// new [|C|]().foo();
8+
9+
[
10+
{
11+
"definition": {
12+
"containerKind": "",
13+
"containerName": "",
14+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences2.ts",
15+
"kind": "class",
16+
"name": "class C",
17+
"textSpan": {
18+
"start": 13,
19+
"length": 1
20+
},
21+
"displayParts": [
22+
{
23+
"text": "class",
24+
"kind": "keyword"
25+
},
26+
{
27+
"text": " ",
28+
"kind": "space"
29+
},
30+
{
31+
"text": "C",
32+
"kind": "className"
33+
}
34+
],
35+
"contextSpan": {
36+
"start": 0,
37+
"length": 69
38+
}
39+
},
40+
"references": [
41+
{
42+
"textSpan": {
43+
"start": 29,
44+
"length": 11
45+
},
46+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences2.ts",
47+
"contextSpan": {
48+
"start": 21,
49+
"length": 25
50+
},
51+
"isWriteAccess": false
52+
},
53+
{
54+
"textSpan": {
55+
"start": 75,
56+
"length": 1
57+
},
58+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences2.ts",
59+
"isWriteAccess": false
60+
}
61+
]
62+
}
63+
]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// === /tests/cases/fourslash/constructorFindAllReferences3.ts ===
2+
// export class C {
3+
// /*FIND ALL REFS*/[|constructor|]() { }
4+
// public foo() { }
5+
// }
6+
//
7+
// new [|C|]().foo();
8+
9+
[
10+
{
11+
"definition": {
12+
"containerKind": "",
13+
"containerName": "",
14+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences3.ts",
15+
"kind": "class",
16+
"name": "class C",
17+
"textSpan": {
18+
"start": 13,
19+
"length": 1
20+
},
21+
"displayParts": [
22+
{
23+
"text": "class",
24+
"kind": "keyword"
25+
},
26+
{
27+
"text": " ",
28+
"kind": "space"
29+
},
30+
{
31+
"text": "C",
32+
"kind": "className"
33+
}
34+
],
35+
"contextSpan": {
36+
"start": 0,
37+
"length": 61
38+
}
39+
},
40+
"references": [
41+
{
42+
"textSpan": {
43+
"start": 21,
44+
"length": 11
45+
},
46+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences3.ts",
47+
"contextSpan": {
48+
"start": 21,
49+
"length": 17
50+
},
51+
"isWriteAccess": false,
52+
"isDefinition": true
53+
},
54+
{
55+
"textSpan": {
56+
"start": 67,
57+
"length": 1
58+
},
59+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences3.ts",
60+
"isWriteAccess": false,
61+
"isDefinition": false
62+
}
63+
]
64+
}
65+
]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// === /tests/cases/fourslash/constructorFindAllReferences4.ts ===
2+
// export class C {
3+
// /*FIND ALL REFS*/protected [|constructor|]() { }
4+
// public foo() { }
5+
// }
6+
//
7+
// new [|C|]().foo();
8+
9+
[
10+
{
11+
"definition": {
12+
"containerKind": "",
13+
"containerName": "",
14+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences4.ts",
15+
"kind": "class",
16+
"name": "class C",
17+
"textSpan": {
18+
"start": 13,
19+
"length": 1
20+
},
21+
"displayParts": [
22+
{
23+
"text": "class",
24+
"kind": "keyword"
25+
},
26+
{
27+
"text": " ",
28+
"kind": "space"
29+
},
30+
{
31+
"text": "C",
32+
"kind": "className"
33+
}
34+
],
35+
"contextSpan": {
36+
"start": 0,
37+
"length": 71
38+
}
39+
},
40+
"references": [
41+
{
42+
"textSpan": {
43+
"start": 31,
44+
"length": 11
45+
},
46+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences4.ts",
47+
"contextSpan": {
48+
"start": 21,
49+
"length": 27
50+
},
51+
"isWriteAccess": false
52+
},
53+
{
54+
"textSpan": {
55+
"start": 77,
56+
"length": 1
57+
},
58+
"fileName": "/tests/cases/fourslash/constructorFindAllReferences4.ts",
59+
"isWriteAccess": false
60+
}
61+
]
62+
}
63+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////export class C {
4+
//// /**/public constructor() { }
5+
//// public foo() { }
6+
////}
7+
////
8+
////new C().foo();
9+
10+
verify.baselineFindAllReferences("");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////export class C {
4+
//// /**/private constructor() { }
5+
//// public foo() { }
6+
////}
7+
////
8+
////new C().foo();
9+
10+
verify.baselineFindAllReferences("");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////export class C {
4+
//// /**/constructor() { }
5+
//// public foo() { }
6+
////}
7+
////
8+
////new C().foo();
9+
10+
verify.baselineFindAllReferences("");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////export class C {
4+
//// /**/protected constructor() { }
5+
//// public foo() { }
6+
////}
7+
////
8+
////new C().foo();
9+
10+
verify.baselineFindAllReferences("");

0 commit comments

Comments
 (0)