Skip to content

Commit a767276

Browse files
authored
Fix inlay hints crash with property access expression (#2273)
1 parent 7c0aa9e commit a767276

File tree

5 files changed

+179
-0
lines changed

5 files changed

+179
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/ls/lsutil"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestInlayHintsElementAccess(t *testing.T) {
12+
t.Parallel()
13+
14+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15+
const content = `interface MySymbol {
16+
readonly "my dispose": unique symbol
17+
}
18+
19+
declare var mySymbol: MySymbol;
20+
21+
let foo = {
22+
[mySymbol["my dispose"]]: () => {}
23+
}
24+
`
25+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
26+
defer done()
27+
f.VerifyBaselineInlayHints(t, nil /*span*/, &lsutil.UserPreferences{InlayHints: lsutil.InlayHintsPreferences{
28+
IncludeInlayVariableTypeHints: true,
29+
}})
30+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/ls/lsutil"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestInlayHintsUsing(t *testing.T) {
12+
t.Parallel()
13+
14+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15+
const content = `// @target: esnext
16+
using _defer = {
17+
[Symbol.dispose]() {},
18+
};`
19+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
20+
defer done()
21+
f.VerifyBaselineInlayHints(t, nil /*span*/, &lsutil.UserPreferences{InlayHints: lsutil.InlayHintsPreferences{
22+
IncludeInlayVariableTypeHints: true,
23+
}})
24+
}

internal/ls/inlay_hints.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,15 @@ func (s *inlayHintState) getInlayHintLabelParts(node *ast.Node) []*lsproto.Inlay
720720
parts = append(parts, &lsproto.InlayHintLabelPart{Value: "["})
721721
visitForDisplayParts(node.Expression())
722722
parts = append(parts, &lsproto.InlayHintLabelPart{Value: "]"})
723+
case ast.KindPropertyAccessExpression:
724+
visitForDisplayParts(node.Expression())
725+
parts = append(parts, &lsproto.InlayHintLabelPart{Value: "."})
726+
visitForDisplayParts(node.Name())
727+
case ast.KindElementAccessExpression:
728+
visitForDisplayParts(node.Expression())
729+
parts = append(parts, &lsproto.InlayHintLabelPart{Value: "["})
730+
visitForDisplayParts(node.AsElementAccessExpression().ArgumentExpression)
731+
parts = append(parts, &lsproto.InlayHintLabelPart{Value: "]"})
723732
default:
724733
debug.FailBadSyntaxKind(node)
725734
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// === Inlay Hints ===
2+
let foo = {
3+
^
4+
{
5+
"position": {
6+
"line": 6,
7+
"character": 7
8+
},
9+
"label": [
10+
{
11+
"value": ": "
12+
},
13+
{
14+
"value": "{"
15+
},
16+
{
17+
"value": " "
18+
},
19+
{
20+
"value": "["
21+
},
22+
{
23+
"value": "MySymbol"
24+
},
25+
{
26+
"value": "["
27+
},
28+
{
29+
"value": "\"my dispose\""
30+
},
31+
{
32+
"value": "]"
33+
},
34+
{
35+
"value": "]"
36+
},
37+
{
38+
"value": ": "
39+
},
40+
{
41+
"value": "("
42+
},
43+
{
44+
"value": ")"
45+
},
46+
{
47+
"value": " => "
48+
},
49+
{
50+
"value": "void"
51+
},
52+
{
53+
"value": " "
54+
},
55+
{
56+
"value": "}"
57+
}
58+
],
59+
"kind": 1,
60+
"paddingLeft": true
61+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// === Inlay Hints ===
2+
using _defer = {
3+
^
4+
{
5+
"position": {
6+
"line": 0,
7+
"character": 12
8+
},
9+
"label": [
10+
{
11+
"value": ": "
12+
},
13+
{
14+
"value": "{"
15+
},
16+
{
17+
"value": " "
18+
},
19+
{
20+
"value": "["
21+
},
22+
{
23+
"value": "Symbol"
24+
},
25+
{
26+
"value": "."
27+
},
28+
{
29+
"value": "dispose"
30+
},
31+
{
32+
"value": "]"
33+
},
34+
{
35+
"value": "("
36+
},
37+
{
38+
"value": ")"
39+
},
40+
{
41+
"value": ": "
42+
},
43+
{
44+
"value": "void"
45+
},
46+
{
47+
"value": " "
48+
},
49+
{
50+
"value": "}"
51+
}
52+
],
53+
"kind": 1,
54+
"paddingLeft": true
55+
}

0 commit comments

Comments
 (0)