Skip to content

Commit d782475

Browse files
Add support for Promise<void> and Generator<void, void, void> (#84)
* Add support for Promise<void> and Generator<void, void, void> * Change files
1 parent a596b9f commit d782475

File tree

9 files changed

+229
-4
lines changed

9 files changed

+229
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Fix support for Promise<void> and Generator<void, void, void>",
4+
"packageName": "@minecraft/api-docs-generator",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

tools/api-docs-generator-test-snapshots/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"build": "just-scripts build",
1212
"clean": "just-scripts clean",
1313
"lint": "just-scripts lint",
14-
"test": "just-scripts test"
14+
"test": "just-scripts test",
15+
"test:update": "just-scripts test --update"
1516
},
1617
"devDependencies": {
1718
"@minecraft/core-build-tasks": "*",

tools/api-docs-generator-test-snapshots/test/generator/__snapshots__/generator.spec.ts.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ description: Contents of the generator-module.ExampleClass class.
2929
3030
### **methodWhichTakesGenerator**
3131
\`
32-
methodWhichTakesGenerator(generator: Generator<ExampleClass, number, string>): number
32+
methodWhichTakesGenerator(generator: Generator<ExampleClass, number, string>, generatorWithVoids: Generator<void, void, void>): number
3333
\`
3434
3535
#### **Parameters**
3636
- **generator**: Generator<[*ExampleClass*](ExampleClass.md), *number*, *string*>
37+
- **generatorWithVoids**: Generator<*void*, *void*, *void*>
3738
3839
**Returns** *number*
3940
"
@@ -91,7 +92,10 @@ exports[`Generator > Properly generates generator documentation and definitions
9192
*/
9293
export class ExampleClass {
9394
private constructor();
94-
methodWhichTakesGenerator(generator: Generator<ExampleClass, number, string>): number;
95+
methodWhichTakesGenerator(
96+
generator: Generator<ExampleClass, number, string>,
97+
generatorWithVoids: Generator<void, void, void>
98+
): number;
9599
}
96100
"
97101
`;

tools/api-docs-generator-test-snapshots/test/generator/input/test-script-module.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@
3131
"is_errorable": false,
3232
"name": "generator"
3333
}
34+
},
35+
{
36+
"details": null,
37+
"name": "generatorWithVoids",
38+
"type": {
39+
"generator_type": {
40+
"next_type": {
41+
"is_bind_type": false,
42+
"is_errorable": false,
43+
"name": "undefined"
44+
},
45+
"return_type": {
46+
"is_bind_type": false,
47+
"is_errorable": false,
48+
"name": "undefined"
49+
},
50+
"yield_type": {
51+
"is_bind_type": false,
52+
"is_errorable": false,
53+
"name": "undefined"
54+
}
55+
},
56+
"is_bind_type": false,
57+
"is_errorable": false,
58+
"name": "generator"
59+
}
3460
}
3561
],
3662
"is_constructor": false,
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Promises > Properly generates promises documentation and definitions > # Of Files Generated 1`] = `4`;
4+
5+
exports[`Promises > Properly generates promises documentation and definitions > msdocs/scriptapi/TOC.yml 1`] = `
6+
" - name: promise-module
7+
items:
8+
- name: promise-module
9+
href: promise-module/promise-module.md
10+
- name: ExampleClass
11+
href: promise-module/ExampleClass.md
12+
"
13+
`;
14+
15+
exports[`Promises > Properly generates promises documentation and definitions > msdocs/scriptapi/promise-module/ExampleClass.md 1`] = `
16+
"---
17+
# DO NOT TOUCH — This file was automatically generated by @minecraft/api-docs-generator, to report problems file an issue at https://github.com/Mojang/minecraft-scripting-libraries
18+
author: jakeshirley
19+
ms.author: jashir
20+
ms.service: minecraft-bedrock-edition
21+
ms.date: 02/10/2025
22+
title: promise-module.ExampleClass Class
23+
description: Contents of the promise-module.ExampleClass class.
24+
---
25+
# ExampleClass Class
26+
27+
## Methods
28+
- [methodWhichTakesPromises](#methodwhichtakespromises)
29+
30+
### **methodWhichTakesPromises**
31+
\`
32+
methodWhichTakesPromises(promiseWithType: Promise<string>, promiseWithVoid: Promise<void>): Promise<void>
33+
\`
34+
35+
#### **Parameters**
36+
- **promiseWithType**: Promise&lt;*string*&gt;
37+
- **promiseWithVoid**: Promise&lt;*void*&gt;
38+
39+
**Returns** Promise&lt;*void*&gt;
40+
"
41+
`;
42+
43+
exports[`Promises > Properly generates promises documentation and definitions > msdocs/scriptapi/promise-module/promise-module.md 1`] = `
44+
"---
45+
# DO NOT TOUCH — This file was automatically generated by @minecraft/api-docs-generator, to report problems file an issue at https://github.com/Mojang/minecraft-scripting-libraries
46+
author: jakeshirley
47+
ms.author: jashir
48+
ms.service: minecraft-bedrock-edition
49+
ms.date: 02/10/2025
50+
title: promise-module Module
51+
description: Contents of the promise-module module
52+
---
53+
# \`promise-module\` Module
54+
55+
## Manifest Details
56+
\`\`\`json
57+
{
58+
"module_name": "promise-module",
59+
"version": "1.0.0"
60+
}
61+
\`\`\`
62+
This is version 1.x.x of this module, which is the latest as of version 1.0.0 of Minecraft.
63+
64+
## Available Versions
65+
- \`1.0.0\`
66+
67+
## Classes
68+
- [ExampleClass](ExampleClass.md)
69+
"
70+
`;
71+
72+
exports[`Promises > Properly generates promises documentation and definitions > typescript/[email protected] 1`] = `
73+
"// Type definitions for Minecraft Bedrock Edition script APIs
74+
// Project: https://docs.microsoft.com/minecraft/creator/
75+
// Definitions by: Jake Shirley <https://github.com/JakeShirley>
76+
// Mike Ammerlaan <https://github.com/mammerla>
77+
78+
/* *****************************************************************************
79+
Copyright (c) Microsoft Corporation.
80+
***************************************************************************** */
81+
/**
82+
* @packageDocumentation
83+
*
84+
* Manifest Details
85+
* \`\`\`json
86+
* {
87+
* "module_name": "promise-module",
88+
* "version": "1.0.0"
89+
* }
90+
* \`\`\`
91+
*
92+
*/
93+
export class ExampleClass {
94+
private constructor();
95+
methodWhichTakesPromises(promiseWithType: Promise<string>, promiseWithVoid: Promise<void>): Promise<void>;
96+
}
97+
"
98+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// File exists to ensure docs folder exists
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"classes": [
3+
{
4+
"base_types": [],
5+
"constants": [],
6+
"functions": [
7+
{
8+
"arguments": [
9+
{
10+
"details": null,
11+
"name": "promiseWithType",
12+
"type": {
13+
"is_bind_type" : false,
14+
"is_errorable" : true,
15+
"name" : "promise",
16+
"promise_type" : {
17+
"is_bind_type" : false,
18+
"is_errorable" : false,
19+
"name" : "string"
20+
}
21+
}
22+
},
23+
{
24+
"details": null,
25+
"name": "promiseWithVoid",
26+
"type": {
27+
"is_bind_type" : false,
28+
"is_errorable" : true,
29+
"name" : "promise",
30+
"promise_type" : {
31+
"is_bind_type" : false,
32+
"is_errorable" : false,
33+
"name" : "undefined"
34+
}
35+
}
36+
}
37+
],
38+
"is_constructor": false,
39+
"is_static": false,
40+
"name": "methodWhichTakesPromises",
41+
"privilege": "read_only",
42+
"return_type": {
43+
"is_bind_type": false,
44+
"is_errorable": false,
45+
"name" : "promise",
46+
"promise_type" : {
47+
"is_bind_type" : false,
48+
"is_errorable" : false,
49+
"name" : "undefined"
50+
}
51+
}
52+
}
53+
],
54+
"name": "ExampleClass",
55+
"properties": [],
56+
"type": {
57+
"is_bind_type": true,
58+
"is_errorable": false,
59+
"name": "ExampleClass"
60+
}
61+
}
62+
],
63+
"minecraft_version": "1.0.0",
64+
"name": "promise-module",
65+
"uuid": "62d6396b-856d-4388-b8ac-8cff647c3345",
66+
"version": "1.0.0",
67+
"module_type": "script"
68+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { describe, it } from 'vitest';
5+
import { runGeneratorForTest } from '../runGeneratorForTest';
6+
7+
describe('Promises', () => {
8+
it('Properly generates promises documentation and definitions', () => {
9+
runGeneratorForTest({
10+
testDir: __dirname,
11+
generators: ['ts', 'msdocs'],
12+
});
13+
});
14+
});

tools/api-docs-generator/src/filters/CommonFilters.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,13 @@ function typeFlags(releases: MinecraftRelease[]) {
16581658
if (typeJson.name === 'string') {
16591659
typeJson.is_string = true;
16601660
} else if (typeJson.name === 'undefined') {
1661-
if (propertyName === 'return_type') {
1661+
if (
1662+
propertyName === 'return_type' ||
1663+
propertyName === 'promise_type' ||
1664+
propertyName === 'generator_type' ||
1665+
propertyName === 'yield_type' ||
1666+
propertyName === 'next_type'
1667+
) {
16621668
typeJson.is_void_return = true;
16631669
} else {
16641670
typeJson.is_undefined = true;

0 commit comments

Comments
 (0)