Skip to content

Commit 9f80ef3

Browse files
committed
Add additional example when a type has a namespace
1 parent 3e59949 commit 9f80ef3

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pages/docs/manual/v12.0.0/editor-plugins.mdx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ let x = [1, 2, 3]->
196196
- ArrayExtra.myOtherArrayFn
197197
```
198198

199+
**Note**: generic types like `promise.t` and `result.t` do not need any additional types in the `rescript.json`:
200+
201+
```json
202+
"editor": {
203+
"autocomplete": {
204+
"promise": ["PromiseExt"],
205+
"result": ["ResultExt"]
206+
}
207+
}
208+
```
209+
199210
##### Enhancing completion for non-builtin types
200211

201212
Now, let's look at an example of when you have a non-builtin type that you don't have control over.
@@ -221,3 +232,35 @@ Let's configure this using the `editor.autocomplete` config in `rescript.json`:
221232
```
222233

223234
Now, when using pipes on anything of type `Fastify.t`, we'll also get completions from our custom `FastifyExtra`.
235+
236+
##### Enhancing completion for non-builtin types with namespaces
237+
238+
When a project uses a namespace, this affects the internal representation of type names used in the `autocomplete` configuration.
239+
240+
Consider the [geolocation](https://rescript-lang.github.io/experimental-rescript-webapi/apidocs/geolocation-api/#geolocation) type from the [Experimental WebAPI bindings](https://rescript-lang.github.io/experimental-rescript-webapi/).
241+
This project specifies in its `rescript.json`:
242+
243+
```json
244+
{
245+
"name": "@rescript/webapi",
246+
"namespace": "WebAPI"
247+
}
248+
```
249+
250+
This makes the `geolocation` type internally represented as `GeolocationAPI-WebAPI.geolocation`, where:
251+
252+
- `GeolocationAPI` is the module name
253+
- `WebAPI` is the namespace
254+
- `geolocation` is the type name
255+
256+
**Important**: You must use this internal representation when configuring autocomplete for namespaced types:
257+
258+
```json
259+
{
260+
"editor": {
261+
"autocomplete": {
262+
"GeolocationAPI-WebAPI.geolocation": ["GeolocationExt"]
263+
}
264+
}
265+
}
266+
```

0 commit comments

Comments
 (0)