Skip to content

Commit 0b82e1a

Browse files
authored
Interactive type inlay hints (microsoft#55141)
1 parent 1a68590 commit 0b82e1a

28 files changed

+1130
-32
lines changed

src/services/inlayHints.ts

+343-13
Large diffs are not rendered by default.

tests/baselines/reference/inlayHintsFunctionParameterTypes1.baseline

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ foo2((a) => { })
4646
foo3(a => {
4747
^
4848
{
49-
"text": ": (c: (d: 2 | 3) => void) => ...",
49+
"text": ": (c: (d: 2 | 3) => void) => void",
5050
"position": 331,
5151
"kind": "Type",
5252
"whitespaceBefore": true

tests/baselines/reference/inlayHintsInterativeAnyParameter1.baseline renamed to tests/baselines/reference/inlayHintsInteractiveAnyParameter1.baseline

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ foo(1);
1212
"start": 14,
1313
"length": 1
1414
},
15-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter1.ts"
15+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter1.ts"
1616
},
1717
{
1818
"text": ":"
@@ -34,7 +34,7 @@ foo('');
3434
"start": 14,
3535
"length": 1
3636
},
37-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter1.ts"
37+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter1.ts"
3838
},
3939
{
4040
"text": ":"
@@ -56,7 +56,7 @@ foo(true);
5656
"start": 14,
5757
"length": 1
5858
},
59-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter1.ts"
59+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter1.ts"
6060
},
6161
{
6262
"text": ":"
@@ -78,7 +78,7 @@ foo((1));
7878
"start": 14,
7979
"length": 1
8080
},
81-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter1.ts"
81+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter1.ts"
8282
},
8383
{
8484
"text": ":"
@@ -100,7 +100,7 @@ foo(foo(1));
100100
"start": 14,
101101
"length": 1
102102
},
103-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter1.ts"
103+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter1.ts"
104104
},
105105
{
106106
"text": ":"

tests/baselines/reference/inlayHintsInterativeAnyParameter2.baseline renamed to tests/baselines/reference/inlayHintsInteractiveAnyParameter2.baseline

+13-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ foo(1);
1212
"start": 14,
1313
"length": 1
1414
},
15-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
15+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
1616
},
1717
{
1818
"text": ":"
@@ -34,7 +34,7 @@ foo('');
3434
"start": 14,
3535
"length": 1
3636
},
37-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
37+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
3838
},
3939
{
4040
"text": ":"
@@ -56,7 +56,7 @@ foo(true);
5656
"start": 14,
5757
"length": 1
5858
},
59-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
59+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
6060
},
6161
{
6262
"text": ":"
@@ -78,7 +78,7 @@ foo(() => 1);
7878
"start": 14,
7979
"length": 1
8080
},
81-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
81+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
8282
},
8383
{
8484
"text": ":"
@@ -100,7 +100,7 @@ foo(function () { return 1 });
100100
"start": 14,
101101
"length": 1
102102
},
103-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
103+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
104104
},
105105
{
106106
"text": ":"
@@ -122,7 +122,7 @@ foo({});
122122
"start": 14,
123123
"length": 1
124124
},
125-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
125+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
126126
},
127127
{
128128
"text": ":"
@@ -144,7 +144,7 @@ foo({ a: 1 });
144144
"start": 14,
145145
"length": 1
146146
},
147-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
147+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
148148
},
149149
{
150150
"text": ":"
@@ -166,7 +166,7 @@ foo([]);
166166
"start": 14,
167167
"length": 1
168168
},
169-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
169+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
170170
},
171171
{
172172
"text": ":"
@@ -188,7 +188,7 @@ foo([1]);
188188
"start": 14,
189189
"length": 1
190190
},
191-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
191+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
192192
},
193193
{
194194
"text": ":"
@@ -210,7 +210,7 @@ foo(foo);
210210
"start": 14,
211211
"length": 1
212212
},
213-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
213+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
214214
},
215215
{
216216
"text": ":"
@@ -232,7 +232,7 @@ foo((1));
232232
"start": 14,
233233
"length": 1
234234
},
235-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
235+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
236236
},
237237
{
238238
"text": ":"
@@ -254,7 +254,7 @@ foo(foo(1));
254254
"start": 14,
255255
"length": 1
256256
},
257-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
257+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
258258
},
259259
{
260260
"text": ":"
@@ -276,7 +276,7 @@ foo(foo(1));
276276
"start": 14,
277277
"length": 1
278278
},
279-
"file": "/tests/cases/fourslash/inlayHintsInterativeAnyParameter2.ts"
279+
"file": "/tests/cases/fourslash/inlayHintsInteractiveAnyParameter2.ts"
280280
},
281281
{
282282
"text": ":"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const f1: F1 = (a, b) => { }
2+
^
3+
{
4+
"text": ": string",
5+
"position": 58,
6+
"kind": "Type",
7+
"whitespaceBefore": true
8+
}
9+
10+
const f1: F1 = (a, b) => { }
11+
^
12+
{
13+
"text": ": number",
14+
"position": 61,
15+
"kind": "Type",
16+
"whitespaceBefore": true
17+
}
18+
19+
const f2: F1 = (a, b: number) => { }
20+
^
21+
{
22+
"text": ": string",
23+
"position": 87,
24+
"kind": "Type",
25+
"whitespaceBefore": true
26+
}
27+
28+
foo1((a) => { })
29+
^
30+
{
31+
"text": ": string",
32+
"position": 157,
33+
"kind": "Type",
34+
"whitespaceBefore": true
35+
}
36+
37+
foo2((a) => { })
38+
^
39+
{
40+
"text": ": 2 | 3",
41+
"position": 232,
42+
"kind": "Type",
43+
"whitespaceBefore": true
44+
}
45+
46+
foo3(a => {
47+
^
48+
{
49+
"text": ": (c: (d: 2 | 3) => void) => void",
50+
"position": 331,
51+
"kind": "Type",
52+
"whitespaceBefore": true
53+
}
54+
55+
a(d => {})
56+
^
57+
{
58+
"text": ": 2 | 3",
59+
"position": 344,
60+
"kind": "Type",
61+
"whitespaceBefore": true
62+
}
63+
64+
foo4(1, a => { })
65+
^
66+
{
67+
"text": ": number",
68+
"position": 409,
69+
"kind": "Type",
70+
"whitespaceBefore": true
71+
}
72+
73+
const foo5: F2 = (a) => { }
74+
^
75+
{
76+
"text": ": { a: number; b: string; }",
77+
"position": 492,
78+
"kind": "Type",
79+
"whitespaceBefore": true
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
=== No inlay hints ===
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
bar: function (x?): void {
2+
^
3+
{
4+
"text": ": boolean",
5+
"position": 87,
6+
"kind": "Type",
7+
"whitespaceBefore": true
8+
}
9+
10+
set foo(value) { this.#value = value; }
11+
^
12+
{
13+
"text": ": number",
14+
"position": 250,
15+
"kind": "Type",
16+
"whitespaceBefore": true
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
=== No inlay hints ===
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
=== No inlay hints ===
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function bar () { return require('./a').a; }
2+
^
3+
{
4+
"text": "",
5+
"displayParts": [
6+
{
7+
"text": ": "
8+
},
9+
{
10+
"text": "1"
11+
}
12+
],
13+
"position": 58,
14+
"kind": "Type",
15+
"whitespaceBefore": true
16+
}
17+
18+
const d = bar()
19+
^
20+
{
21+
"text": "",
22+
"displayParts": [
23+
{
24+
"text": ": "
25+
},
26+
{
27+
"text": "1"
28+
}
29+
],
30+
"position": 111,
31+
"kind": "Type",
32+
"whitespaceBefore": true
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
y.foo(1, 2)
2+
^
3+
{
4+
"text": "",
5+
"position": 88,
6+
"kind": "Parameter",
7+
"whitespaceAfter": true,
8+
"displayParts": [
9+
{
10+
"text": "a",
11+
"span": {
12+
"start": 40,
13+
"length": 1
14+
},
15+
"file": "/a.js"
16+
},
17+
{
18+
"text": ":"
19+
}
20+
]
21+
}
22+
23+
y.foo(1, 2)
24+
^
25+
{
26+
"text": "",
27+
"position": 91,
28+
"kind": "Parameter",
29+
"whitespaceAfter": true,
30+
"displayParts": [
31+
{
32+
"text": "b",
33+
"span": {
34+
"start": 51,
35+
"length": 1
36+
},
37+
"file": "/a.js"
38+
},
39+
{
40+
"text": ":"
41+
}
42+
]
43+
}

0 commit comments

Comments
 (0)