1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
//! Relationship-oriented `ApiClient` methods.
//!
//! This group answers questions about how types, signatures, and symbols relate
//! to each other after the checker has already identified them.
use super::{
ApiClient, IndexInfo, ProjectHandle, SignatureHandle, SnapshotHandle, TypeHandle,
TypePredicateResponse, TypeResponse,
requests_symbols::{SignatureOnlyRequest, TypeOnlyRequest, TypeProjectRequest},
};
use crate::Result;
impl ApiClient {
/// Returns the symbol attached to a type, if one exists.
pub async fn get_symbol_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Option<super::SymbolResponse>> {
self.call_optional("getSymbolOfType", TypeOnlyRequest { snapshot, r#type })
.await
}
/// Returns the return type of a signature.
pub async fn get_return_type_of_signature(
&self,
snapshot: SnapshotHandle,
project: ProjectHandle,
signature: SignatureHandle,
) -> Result<Option<TypeResponse>> {
self.call_optional(
"getReturnTypeOfSignature",
SignatureOnlyRequest {
snapshot,
project,
signature,
},
)
.await
}
/// Returns the rest type of a signature, if any.
pub async fn get_rest_type_of_signature(
&self,
snapshot: SnapshotHandle,
project: ProjectHandle,
signature: SignatureHandle,
) -> Result<Option<TypeResponse>> {
self.call_optional(
"getRestTypeOfSignature",
SignatureOnlyRequest {
snapshot,
project,
signature,
},
)
.await
}
/// Returns the type predicate declared on a signature, if any.
pub async fn get_type_predicate_of_signature(
&self,
snapshot: SnapshotHandle,
project: ProjectHandle,
signature: SignatureHandle,
) -> Result<Option<TypePredicateResponse>> {
self.call_optional(
"getTypePredicateOfSignature",
SignatureOnlyRequest {
snapshot,
project,
signature,
},
)
.await
}
/// Returns the immediate base types of a type.
///
/// Missing server data is normalized to an empty vector.
pub async fn get_base_types(
&self,
snapshot: SnapshotHandle,
project: ProjectHandle,
r#type: TypeHandle,
) -> Result<Vec<TypeResponse>> {
self.call::<Option<Vec<TypeResponse>>, _>(
"getBaseTypes",
TypeProjectRequest {
snapshot,
project,
r#type,
},
)
.await
.map(|items| items.unwrap_or_default())
}
/// Returns the properties exposed by a type.
///
/// Missing server data is normalized to an empty vector.
pub async fn get_properties_of_type(
&self,
snapshot: SnapshotHandle,
project: ProjectHandle,
r#type: TypeHandle,
) -> Result<Vec<super::SymbolResponse>> {
self.call::<Option<Vec<super::SymbolResponse>>, _>(
"getPropertiesOfType",
TypeProjectRequest {
snapshot,
project,
r#type,
},
)
.await
.map(|items| items.unwrap_or_default())
}
/// Returns index signature information for a type.
///
/// Missing server data is normalized to an empty vector.
pub async fn get_index_infos_of_type(
&self,
snapshot: SnapshotHandle,
project: ProjectHandle,
r#type: TypeHandle,
) -> Result<Vec<IndexInfo>> {
self.call::<Option<Vec<IndexInfo>>, _>(
"getIndexInfosOfType",
TypeProjectRequest {
snapshot,
project,
r#type,
},
)
.await
.map(|items| items.unwrap_or_default())
}
/// Returns the constraint of a type parameter, if one exists.
pub async fn get_constraint_of_type_parameter(
&self,
snapshot: SnapshotHandle,
project: ProjectHandle,
r#type: TypeHandle,
) -> Result<Option<TypeResponse>> {
self.call_optional(
"getConstraintOfTypeParameter",
TypeProjectRequest {
snapshot,
project,
r#type,
},
)
.await
}
/// Returns the type arguments of an instantiated type.
///
/// Missing server data is normalized to an empty vector. A stale type
/// handle that the server has dropped from its snapshot registry is also
/// treated as "no type arguments" so callers can keep analyzing the type;
/// see [`ApiClient::is_stale_handle_error`].
pub async fn get_type_arguments(
&self,
snapshot: SnapshotHandle,
project: ProjectHandle,
r#type: TypeHandle,
) -> Result<Vec<TypeResponse>> {
match self
.call::<Option<Vec<TypeResponse>>, _>(
"getTypeArguments",
TypeProjectRequest {
snapshot,
project,
r#type,
},
)
.await
{
Ok(items) => Ok(items.unwrap_or_default()),
Err(error) if Self::is_stale_handle_error(&error) => Ok(Vec::new()),
Err(error) => Err(error),
}
}
/// Returns the target type underlying an instantiated or mapped type.
pub async fn get_target_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Option<TypeResponse>> {
self.call_optional("getTargetOfType", TypeOnlyRequest { snapshot, r#type })
.await
}
/// Returns nested or constituent types associated with a type.
///
/// Missing server data is normalized to an empty vector.
pub async fn get_types_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Vec<TypeResponse>> {
self.call::<Option<Vec<TypeResponse>>, _>(
"getTypesOfType",
TypeOnlyRequest { snapshot, r#type },
)
.await
.map(|items| items.unwrap_or_default())
}
/// Returns the direct type parameters declared on a type.
///
/// Missing server data is normalized to an empty vector.
pub async fn get_type_parameters_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Vec<TypeResponse>> {
self.call::<Option<Vec<TypeResponse>>, _>(
"getTypeParametersOfType",
TypeOnlyRequest { snapshot, r#type },
)
.await
.map(|items| items.unwrap_or_default())
}
/// Returns outer type parameters captured by a type.
///
/// Missing server data is normalized to an empty vector.
pub async fn get_outer_type_parameters_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Vec<TypeResponse>> {
self.call::<Option<Vec<TypeResponse>>, _>(
"getOuterTypeParametersOfType",
TypeOnlyRequest { snapshot, r#type },
)
.await
.map(|items| items.unwrap_or_default())
}
/// Returns local type parameters introduced while resolving a type.
///
/// Missing server data is normalized to an empty vector.
pub async fn get_local_type_parameters_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Vec<TypeResponse>> {
self.call::<Option<Vec<TypeResponse>>, _>(
"getLocalTypeParametersOfType",
TypeOnlyRequest { snapshot, r#type },
)
.await
.map(|items| items.unwrap_or_default())
}
/// Returns the object side of a wrapper type, if one exists.
pub async fn get_object_type_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Option<TypeResponse>> {
self.call_optional("getObjectTypeOfType", TypeOnlyRequest { snapshot, r#type })
.await
}
/// Returns the index side of a wrapper type, if one exists.
pub async fn get_index_type_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Option<TypeResponse>> {
self.call_optional("getIndexTypeOfType", TypeOnlyRequest { snapshot, r#type })
.await
}
/// Returns the check side of a wrapper or conditional type, if one exists.
pub async fn get_check_type_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Option<TypeResponse>> {
self.call_optional("getCheckTypeOfType", TypeOnlyRequest { snapshot, r#type })
.await
}
/// Returns the `extends` side of a conditional type, if one exists.
pub async fn get_extends_type_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Option<TypeResponse>> {
self.call_optional("getExtendsTypeOfType", TypeOnlyRequest { snapshot, r#type })
.await
}
/// Returns the base type recorded directly on a type, if one exists.
pub async fn get_base_type_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Option<TypeResponse>> {
self.call_optional("getBaseTypeOfType", TypeOnlyRequest { snapshot, r#type })
.await
}
/// Returns the constraint recorded directly on a type, if one exists.
pub async fn get_constraint_of_type(
&self,
snapshot: SnapshotHandle,
r#type: TypeHandle,
) -> Result<Option<TypeResponse>> {
self.call_optional("getConstraintOfType", TypeOnlyRequest { snapshot, r#type })
.await
}
}