1
+ <?php // Auto-generated from vscode-languageserver-protocol (typescript)
2
+
3
+ namespace Phpactor \LanguageServerProtocol ;
4
+
5
+ use DTL \Invoke \Invoke ;
6
+ use Exception ;
7
+ use RuntimeException ;
8
+
9
+ class InlayHint
10
+ {
11
+ /**
12
+ * The position of this hint.
13
+ *
14
+ * @var Position
15
+ */
16
+ public $ position ;
17
+
18
+ /**
19
+ * The label of this hint. A human readable string or an array of
20
+ * InlayHintLabelPart label parts.
21
+ *
22
+ * *Note* that neither the string nor the label part can be empty.
23
+ *
24
+ * @var string|array<array{value:string,tooltip:string|MarkupContent,location:Location,command:Command}>
25
+ */
26
+ public $ label ;
27
+
28
+ /**
29
+ * The kind of this hint. Can be omitted in which case the client
30
+ * should fall back to a reasonable default.
31
+ *
32
+ * @var InlayHintKind::*|null
33
+ */
34
+ public $ kind ;
35
+
36
+ /**
37
+ * Optional text edits that are performed when accepting this inlay hint.
38
+ *
39
+ * *Note* that edits are expected to change the document so that the inlay
40
+ * hint (or its nearest variant) is now part of the document and the inlay
41
+ * hint itself is now obsolete.
42
+ *
43
+ * @var array<TextEdit>|null
44
+ */
45
+ public $ textEdits ;
46
+
47
+ /**
48
+ * The tooltip text when you hover over this item.
49
+ *
50
+ * @var string|MarkupContent|null
51
+ */
52
+ public $ tooltip ;
53
+
54
+ /**
55
+ * Render padding before the hint.
56
+ *
57
+ * Note: Padding should use the editor's background color, not the
58
+ * background color of the hint itself. That means padding can be used
59
+ * to visually align/separate an inlay hint.
60
+ *
61
+ * @var bool|null
62
+ */
63
+ public $ paddingLeft ;
64
+
65
+ /**
66
+ * Render padding after the hint.
67
+ *
68
+ * Note: Padding should use the editor's background color, not the
69
+ * background color of the hint itself. That means padding can be used
70
+ * to visually align/separate an inlay hint.
71
+ *
72
+ * @var bool|null
73
+ */
74
+ public $ paddingRight ;
75
+
76
+ /**
77
+ * A data entry field that is preserved on an inlay hint between
78
+ * a `textDocument/inlayHint` and a `inlayHint/resolve` request.
79
+ *
80
+ * @var mixed|null
81
+ */
82
+ public $ data ;
83
+
84
+ /**
85
+ * @param Position $position
86
+ * @param string|array<array{value:string,tooltip:string|MarkupContent,location:Location,command:Command}> $label
87
+ * @param InlayHintKind::*|null $kind
88
+ * @param array<TextEdit>|null $textEdits
89
+ * @param string|MarkupContent|null $tooltip
90
+ * @param bool|null $paddingLeft
91
+ * @param bool|null $paddingRight
92
+ * @param mixed|null $data
93
+ */
94
+ public function __construct (Position $ position , $ label , $ kind = null , ?array $ textEdits = null , $ tooltip = null , ?bool $ paddingLeft = null , ?bool $ paddingRight = null , $ data = null )
95
+ {
96
+ $ this ->position = $ position ;
97
+ $ this ->label = $ label ;
98
+ $ this ->kind = $ kind ;
99
+ $ this ->textEdits = $ textEdits ;
100
+ $ this ->tooltip = $ tooltip ;
101
+ $ this ->paddingLeft = $ paddingLeft ;
102
+ $ this ->paddingRight = $ paddingRight ;
103
+ $ this ->data = $ data ;
104
+ }
105
+
106
+ /**
107
+ * @param array<string,mixed> $array
108
+ * @return self
109
+ */
110
+ public static function fromArray (array $ array , bool $ allowUnknownKeys = false )
111
+ {
112
+ $ map = [
113
+ 'position ' => ['names ' => [Position::class], 'iterable ' => false ],
114
+ 'label ' => ['names ' => [], 'iterable ' => false ],
115
+ 'kind ' => ['names ' => [], 'iterable ' => false ],
116
+ 'textEdits ' => ['names ' => [TextEdit::class], 'iterable ' => true ],
117
+ 'tooltip ' => ['names ' => [MarkupContent::class], 'iterable ' => false ],
118
+ 'paddingLeft ' => ['names ' => [], 'iterable ' => false ],
119
+ 'paddingRight ' => ['names ' => [], 'iterable ' => false ],
120
+ 'data ' => ['names ' => [], 'iterable ' => false ],
121
+ ];
122
+
123
+ foreach ($ array as $ key => &$ value ) {
124
+ if (!isset ($ map [$ key ])) {
125
+ if ($ allowUnknownKeys ) {
126
+ unset($ array [$ key ]);
127
+ continue ;
128
+ }
129
+
130
+ throw new RuntimeException (sprintf (
131
+ 'Parameter "%s" on class "%s" not known, known parameters: "%s" ' ,
132
+ $ key ,
133
+ self ::class,
134
+ implode ('", " ' , array_keys ($ map ))
135
+ ));
136
+ }
137
+
138
+ // from here we only care about arrays that can be transformed into
139
+ // objects
140
+ if (!is_array ($ value )) {
141
+ continue ;
142
+ }
143
+
144
+ if (empty ($ map [$ key ]['names ' ])) {
145
+ continue ;
146
+ }
147
+
148
+ if ($ map [$ key ]['iterable ' ]) {
149
+ $ value = array_map (function ($ object ) use ($ map , $ key , $ allowUnknownKeys ) {
150
+ if (!is_array ($ object )) {
151
+ return $ object ;
152
+ }
153
+
154
+ return self ::invokeFromNames ($ map [$ key ]['names ' ], $ object , $ allowUnknownKeys ) ?: $ object ;
155
+ }, $ value );
156
+ continue ;
157
+ }
158
+
159
+ $ names = $ map [$ key ]['names ' ];
160
+ $ value = self ::invokeFromNames ($ names , $ value , $ allowUnknownKeys ) ?: $ value ;
161
+ }
162
+
163
+ return Invoke::new (self ::class, $ array );
164
+ }
165
+
166
+ /**
167
+ * @param array<string> $classNames
168
+ * @param array<string,mixed> $object
169
+ */
170
+ private static function invokeFromNames (array $ classNames , array $ object , bool $ allowUnknownKeys ): ?object
171
+ {
172
+ $ lastException = null ;
173
+ foreach ($ classNames as $ className ) {
174
+ try {
175
+ // @phpstan-ignore-next-line
176
+ return call_user_func_array ($ className . '::fromArray ' , [$ object , $ allowUnknownKeys ]);
177
+ } catch (Exception $ exception ) {
178
+ $ lastException = $ exception ;
179
+ continue ;
180
+ }
181
+ }
182
+
183
+ throw $ lastException ;
184
+ }
185
+
186
+ }
0 commit comments