@alloy-js/csharp 0.18.0-dev.7 → 0.18.0-dev.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/src/components/ClassDeclaration.d.ts +2 -0
  2. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  3. package/dist/src/components/ClassDeclaration.js +6 -1
  4. package/dist/src/components/ClassMethod.d.ts +2 -0
  5. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  6. package/dist/src/components/ClassMethod.js +6 -1
  7. package/dist/src/components/doc/comment.d.ts +69 -0
  8. package/dist/src/components/doc/comment.d.ts.map +1 -0
  9. package/dist/src/components/doc/comment.js +71 -0
  10. package/dist/src/components/doc/comment.test.d.ts +2 -0
  11. package/dist/src/components/doc/comment.test.d.ts.map +1 -0
  12. package/dist/src/components/doc/comment.test.js +338 -0
  13. package/dist/src/components/interface/declaration.d.ts +2 -0
  14. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  15. package/dist/src/components/interface/declaration.js +6 -1
  16. package/dist/src/components/interface/declaration.test.js +13 -0
  17. package/dist/src/components/interface/method.d.ts +2 -0
  18. package/dist/src/components/interface/method.d.ts.map +1 -1
  19. package/dist/src/components/interface/method.js +6 -1
  20. package/dist/src/components/interface/method.test.js +21 -0
  21. package/dist/src/components/interface/property.d.ts +2 -0
  22. package/dist/src/components/interface/property.d.ts.map +1 -1
  23. package/dist/src/components/interface/property.js +7 -2
  24. package/dist/src/components/interface/property.test.js +24 -0
  25. package/dist/test/class-method.test.js +21 -0
  26. package/dist/test/class.test.js +13 -0
  27. package/dist/test/vitest.setup.d.ts +2 -0
  28. package/dist/test/vitest.setup.d.ts.map +1 -0
  29. package/dist/test/vitest.setup.js +1 -0
  30. package/dist/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +2 -2
  32. package/src/components/ClassDeclaration.tsx +4 -0
  33. package/src/components/ClassMethod.tsx +5 -0
  34. package/src/components/doc/comment.test.tsx +336 -0
  35. package/src/components/doc/comment.tsx +122 -0
  36. package/src/components/interface/declaration.test.tsx +11 -0
  37. package/src/components/interface/declaration.tsx +5 -0
  38. package/src/components/interface/method.test.tsx +16 -0
  39. package/src/components/interface/method.tsx +5 -0
  40. package/src/components/interface/property.test.tsx +22 -0
  41. package/src/components/interface/property.tsx +5 -0
  42. package/temp/api.json +112 -0
  43. package/test/class-method.test.tsx +16 -0
  44. package/test/class.test.tsx +11 -0
  45. package/test/vitest.setup.ts +1 -0
  46. package/vitest.config.ts +3 -0
@@ -0,0 +1,336 @@
1
+ import { expect, it } from "vitest";
2
+ import {
3
+ DocC,
4
+ DocCode,
5
+ DocComment,
6
+ DocCompletionList,
7
+ DocDescription,
8
+ DocExample,
9
+ DocException,
10
+ DocInclude,
11
+ DocItem,
12
+ DocList,
13
+ DocPara,
14
+ DocParam,
15
+ DocParamRef,
16
+ DocPermission,
17
+ DocRemarks,
18
+ DocResponse,
19
+ DocReturns,
20
+ DocSee,
21
+ DocSeeAlso,
22
+ DocSummary,
23
+ DocTerm,
24
+ DocTypeParam,
25
+ DocTypeParamRef,
26
+ DocValue,
27
+ } from "./comment.jsx";
28
+
29
+ it("define summary", () => {
30
+ expect(
31
+ <DocComment>
32
+ <DocSummary>This is a sample doc comment</DocSummary>
33
+ </DocComment>,
34
+ ).toRenderTo(`
35
+ /// <summary>
36
+ /// This is a sample doc comment
37
+ /// </summary>
38
+ `);
39
+ });
40
+
41
+ it("define code", () => {
42
+ expect(
43
+ <DocComment>
44
+ <DocCode>code sample</DocCode>
45
+ </DocComment>,
46
+ ).toRenderTo(`
47
+ /// <code>
48
+ /// code sample
49
+ /// </code>
50
+ `);
51
+ });
52
+
53
+ it("define c", () => {
54
+ expect(
55
+ <DocComment>
56
+ <DocC>inline code</DocC>
57
+ </DocComment>,
58
+ ).toRenderTo(`
59
+ /// <c>
60
+ /// inline code
61
+ /// </c>
62
+ `);
63
+ });
64
+
65
+ it("define example", () => {
66
+ expect(
67
+ <DocComment>
68
+ <DocExample>example usage</DocExample>
69
+ </DocComment>,
70
+ ).toRenderTo(`
71
+ /// <example>
72
+ /// example usage
73
+ /// </example>
74
+ `);
75
+ });
76
+
77
+ it("define exception", () => {
78
+ expect(
79
+ <DocComment>
80
+ <DocException>exception info</DocException>
81
+ </DocComment>,
82
+ ).toRenderTo(`
83
+ /// <exception>
84
+ /// exception info
85
+ /// </exception>
86
+ `);
87
+ });
88
+
89
+ it("define include", () => {
90
+ expect(
91
+ <DocComment>
92
+ <>{DocInclude({ file: "external.xml", path: "/doc/summary" })}</>
93
+ </DocComment>,
94
+ ).toRenderTo(`
95
+ /// <include file="external.xml" path="/doc/summary" />
96
+ `);
97
+ });
98
+
99
+ it("define param", () => {
100
+ expect(
101
+ <DocComment>
102
+ <DocParam name="x">parameter x</DocParam>
103
+ </DocComment>,
104
+ ).toRenderTo(`
105
+ /// <param name="x">parameter x</param>
106
+ `);
107
+ });
108
+
109
+ it("define typeparam", () => {
110
+ expect(
111
+ <DocComment>
112
+ <DocTypeParam name="T">type parameter T</DocTypeParam>
113
+ </DocComment>,
114
+ ).toRenderTo(`
115
+ /// <typeparam name="T">type parameter T</typeparam>
116
+ `);
117
+ });
118
+
119
+ it("define returns", () => {
120
+ expect(
121
+ <DocComment>
122
+ <DocReturns>return value</DocReturns>
123
+ </DocComment>,
124
+ ).toRenderTo(`
125
+ /// <returns>
126
+ /// return value
127
+ /// </returns>
128
+ `);
129
+ });
130
+
131
+ it("define remarks", () => {
132
+ expect(
133
+ <DocComment>
134
+ <DocRemarks>remarks here</DocRemarks>
135
+ </DocComment>,
136
+ ).toRenderTo(`
137
+ /// <remarks>
138
+ /// remarks here
139
+ /// </remarks>
140
+ `);
141
+ });
142
+
143
+ it("define value", () => {
144
+ expect(
145
+ <DocComment>
146
+ <DocValue>property value</DocValue>
147
+ </DocComment>,
148
+ ).toRenderTo(`
149
+ /// <value>
150
+ /// property value
151
+ /// </value>
152
+ `);
153
+ });
154
+
155
+ it("define permission", () => {
156
+ expect(
157
+ <DocComment>
158
+ <DocPermission>permission info</DocPermission>
159
+ </DocComment>,
160
+ ).toRenderTo(`
161
+ /// <permission>
162
+ /// permission info
163
+ /// </permission>
164
+ `);
165
+ });
166
+
167
+ it("define response", () => {
168
+ expect(
169
+ <DocComment>
170
+ <DocResponse>response info</DocResponse>
171
+ </DocComment>,
172
+ ).toRenderTo(`
173
+ /// <response>
174
+ /// response info
175
+ /// </response>
176
+ `);
177
+ });
178
+
179
+ it("define completionlist", () => {
180
+ expect(
181
+ <DocComment>
182
+ <DocCompletionList>completion list</DocCompletionList>
183
+ </DocComment>,
184
+ ).toRenderTo(`
185
+ /// <completionlist>
186
+ /// completion list
187
+ /// </completionlist>
188
+ `);
189
+ });
190
+
191
+ it("define list", () => {
192
+ expect(
193
+ <DocComment>
194
+ <DocList>list content</DocList>
195
+ </DocComment>,
196
+ ).toRenderTo(`
197
+ /// <list>
198
+ /// list content
199
+ /// </list>
200
+ `);
201
+ });
202
+
203
+ it("define item", () => {
204
+ expect(
205
+ <DocComment>
206
+ <DocItem>item content</DocItem>
207
+ </DocComment>,
208
+ ).toRenderTo(`
209
+ /// <item>
210
+ /// item content
211
+ /// </item>
212
+ `);
213
+ });
214
+
215
+ it("define term", () => {
216
+ expect(
217
+ <DocComment>
218
+ <DocTerm>term content</DocTerm>
219
+ </DocComment>,
220
+ ).toRenderTo(`
221
+ /// <term>
222
+ /// term content
223
+ /// </term>
224
+ `);
225
+ });
226
+
227
+ it("define description", () => {
228
+ expect(
229
+ <DocComment>
230
+ <DocDescription>description content</DocDescription>
231
+ </DocComment>,
232
+ ).toRenderTo(`
233
+ /// <description>
234
+ /// description content
235
+ /// </description>
236
+ `);
237
+ });
238
+
239
+ it("define para", () => {
240
+ expect(
241
+ <DocComment>
242
+ <DocPara>paragraph content</DocPara>
243
+ </DocComment>,
244
+ ).toRenderTo(`
245
+ /// <para>
246
+ /// paragraph content
247
+ /// </para>
248
+ `);
249
+ });
250
+
251
+ it("define see", () => {
252
+ expect(
253
+ <DocComment>
254
+ <>{DocSee({ cref: "T:MyType" })}</>
255
+ </DocComment>,
256
+ ).toRenderTo(`
257
+ /// <see cref="T:MyType" />
258
+ `);
259
+ });
260
+
261
+ it("define seealso", () => {
262
+ expect(
263
+ <DocComment>
264
+ <>{DocSeeAlso({ cref: "T:OtherType" })}</>
265
+ </DocComment>,
266
+ ).toRenderTo(`
267
+ /// <seealso cref="T:OtherType" />
268
+ `);
269
+ });
270
+
271
+ it("define paramref", () => {
272
+ expect(
273
+ <DocComment>
274
+ <>{DocParamRef({ name: "x" })}</>
275
+ </DocComment>,
276
+ ).toRenderTo(`
277
+ /// <paramref name="x" />
278
+ `);
279
+ });
280
+
281
+ it("define typeparamref", () => {
282
+ expect(
283
+ <DocComment>
284
+ <>{DocTypeParamRef({ name: "T" })}</>
285
+ </DocComment>,
286
+ ).toRenderTo(`
287
+ /// <typeparamref name="T" />
288
+ `);
289
+ });
290
+
291
+ it("wrap long summary", () => {
292
+ expect(
293
+ <DocComment>
294
+ <DocSummary>
295
+ This is a very long sample doc comment that exceeds the typical line
296
+ length limit and should be wrapped appropriately in the generated
297
+ documentation.
298
+ </DocSummary>
299
+ </DocComment>,
300
+ ).toRenderTo(`
301
+ /// <summary>
302
+ /// This is a very long sample doc comment that exceeds the typical line length limit
303
+ /// and should be wrapped appropriately in the generated documentation.
304
+ /// </summary>
305
+ `);
306
+ });
307
+
308
+ it("combine multiple tags", () => {
309
+ expect(
310
+ <DocComment>
311
+ <DocSummary>
312
+ This operator determines whether two Points have the same location.
313
+ </DocSummary>
314
+ <DocParam name="p1">The first Point to be compared.</DocParam>
315
+ <DocParam name="p2">The second Point to be compared.</DocParam>
316
+ <DocReturns>
317
+ True if the Points do not have the same location and the exact same
318
+ type; otherwise, false.
319
+ </DocReturns>
320
+ <DocSeeAlso cref="Equals" />
321
+ <DocSeeAlso cref="operator==" />
322
+ </DocComment>,
323
+ ).toRenderTo(`
324
+ /// <summary>
325
+ /// This operator determines whether two Points have the same location.
326
+ /// </summary>
327
+ /// <param name="p1">The first Point to be compared.</param>
328
+ /// <param name="p2">The second Point to be compared.</param>
329
+ /// <returns>
330
+ /// True if the Points do not have the same location and the exact same type; otherwise,
331
+ /// false.
332
+ /// </returns>
333
+ /// <seealso cref="Equals" />
334
+ /// <seealso cref="operator==" />
335
+ `);
336
+ });
@@ -0,0 +1,122 @@
1
+ import { Children, code, List, Prose, Show } from "@alloy-js/core";
2
+
3
+ export interface DocCommentProps {
4
+ children: Children;
5
+ }
6
+
7
+ export function DocComment(props: DocCommentProps) {
8
+ return (
9
+ <>
10
+ {"/// "}
11
+ <align string="/// ">
12
+ <List>{props.children}</List>
13
+ </align>
14
+ </>
15
+ );
16
+ }
17
+
18
+ export interface DocWhenProps {
19
+ doc: Children | undefined;
20
+ }
21
+
22
+ /** Conditionally render the given doc in a <DocComment /> component and tail with a line */
23
+ export function DocWhen(props: DocWhenProps) {
24
+ return (
25
+ <Show when={Boolean(props.doc)}>
26
+ <DocComment children={props.doc} />
27
+ <hbr />
28
+ </Show>
29
+ );
30
+ }
31
+
32
+ export interface DocCommentTagProps {
33
+ children: Children;
34
+ }
35
+
36
+ export function makeDocCommentTag(name: string) {
37
+ return function DocCommentTag(props: DocCommentProps) {
38
+ return (
39
+ <Prose>
40
+ {code`
41
+ <${name}>
42
+ ${props.children}
43
+ </${name}>`}
44
+ </Prose>
45
+ );
46
+ };
47
+ }
48
+ export function makeInlineDocCommentTag(name: string) {
49
+ return function DocCommentTag(props: DocCommentProps) {
50
+ return `<${name}>${props.children}</${name}>`;
51
+ };
52
+ }
53
+
54
+ export const DocSummary = makeDocCommentTag("summary");
55
+ export const DocCode = makeDocCommentTag("code");
56
+ export const DocC = makeDocCommentTag("c");
57
+ export const DocExample = makeDocCommentTag("example");
58
+ export const DocException = makeDocCommentTag("exception");
59
+
60
+ export interface DocIncludeProps {
61
+ /** is the file name of an external XML file. The file name is interpreted relative to the file that contains the include tag. */
62
+ file: string;
63
+ /** is an XPath expression that selects some of the XML in the external XML file. */
64
+ path?: string;
65
+ }
66
+ export const DocInclude = (props: DocIncludeProps) => {
67
+ return `<include file="${props.file}" path="${props.path}" />`;
68
+ };
69
+
70
+ export interface DocParamProps {
71
+ name: string;
72
+ children: Children;
73
+ }
74
+ export const DocParam = (props: DocParamProps) =>
75
+ code`<param name="${props.name}">${props.children}</param>`;
76
+
77
+ export interface DocTypeParamProps {
78
+ name: string;
79
+ children: Children;
80
+ }
81
+ export const DocTypeParam = (props: DocTypeParamProps) =>
82
+ code`<typeparam name="${props.name}">${props.children}</typeparam>`;
83
+
84
+ export const DocReturns = makeDocCommentTag("returns");
85
+ export const DocRemarks = makeDocCommentTag("remarks");
86
+ export const DocValue = makeDocCommentTag("value");
87
+ export const DocPermission = makeDocCommentTag("permission");
88
+ export const DocResponse = makeDocCommentTag("response");
89
+ export const DocCompletionList = makeDocCommentTag("completionlist");
90
+ export const DocList = makeDocCommentTag("list");
91
+ export const DocItem = makeDocCommentTag("item");
92
+ export const DocTerm = makeDocCommentTag("term");
93
+ export const DocDescription = makeDocCommentTag("description");
94
+ export const DocPara = makeDocCommentTag("para");
95
+
96
+ export interface DocSeeProps {
97
+ cref: string;
98
+ langword?: string;
99
+ children?: Children;
100
+ }
101
+ export const DocSee = (props: DocSeeProps) =>
102
+ `<see cref="${props.cref}"${props.langword ? ` langword="${props.langword}"` : ""}${props.children ? `>${props.children}</see>` : " />"}`;
103
+
104
+ export interface DocSeeAlsoProps {
105
+ cref: string;
106
+ langword?: string;
107
+ children?: Children;
108
+ }
109
+ export const DocSeeAlso = (props: DocSeeAlsoProps) =>
110
+ `<seealso cref="${props.cref}"${props.langword ? ` langword="${props.langword}"` : ""}${props.children ? `>${props.children}</seealso>` : " />"}`;
111
+
112
+ export interface DocParamRefProps {
113
+ name: string;
114
+ }
115
+ export const DocParamRef = (props: DocParamRefProps) =>
116
+ `<paramref name="${props.name}" />`;
117
+
118
+ export interface DocTypeParamRefProps {
119
+ name: string;
120
+ }
121
+ export const DocTypeParamRef = (props: DocTypeParamRefProps) =>
122
+ `<typeparamref name="${props.name}" />`;
@@ -43,3 +43,14 @@ describe("modifiers", () => {
43
43
  `);
44
44
  });
45
45
  });
46
+
47
+ it("specify doc comment", () => {
48
+ expect(
49
+ <TestNamespace>
50
+ <InterfaceDeclaration name="TestInterface" doc="This is a test" />
51
+ </TestNamespace>,
52
+ ).toRenderTo(`
53
+ /// This is a test
54
+ interface TestInterface;
55
+ `);
56
+ });
@@ -8,6 +8,7 @@ import {
8
8
  import { useCSharpNamePolicy } from "../../name-policy.js";
9
9
  import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
10
10
  import { CSharpMemberScope } from "../../symbols/scopes.js";
11
+ import { DocWhen } from "../doc/comment.jsx";
11
12
  import { Name } from "../Name.jsx";
12
13
 
13
14
  export interface InterfaceModifiers {
@@ -22,6 +23,9 @@ export interface InterfaceDeclarationProps
22
23
  AccessModifiers,
23
24
  InterfaceModifiers {
24
25
  name: string;
26
+
27
+ /** Doc comment */
28
+ doc?: core.Children;
25
29
  refkey?: core.Refkey;
26
30
  typeParameters?: Record<string, core.Refkey>;
27
31
  }
@@ -92,6 +96,7 @@ export function InterfaceDeclaration(props: InterfaceDeclarationProps) {
92
96
  ]);
93
97
  return (
94
98
  <core.Declaration symbol={thisInterfaceSymbol}>
99
+ <DocWhen doc={props.doc} />
95
100
  {modifiers}interface <Name />
96
101
  {typeParams}
97
102
  {props.children ?
@@ -102,3 +102,19 @@ it("defines params and return type", () => {
102
102
  }
103
103
  `);
104
104
  });
105
+
106
+ it("specify doc comment", () => {
107
+ expect(
108
+ <TestNamespace>
109
+ <InterfaceDeclaration name="Test">
110
+ <InterfaceMethod name="Method" doc="This is a test" />
111
+ </InterfaceDeclaration>
112
+ </TestNamespace>,
113
+ ).toRenderTo(`
114
+ interface Test
115
+ {
116
+ /// This is a test
117
+ void Method();
118
+ }
119
+ `);
120
+ });
@@ -16,6 +16,7 @@ import { useCSharpNamePolicy } from "../../name-policy.js";
16
16
  import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
17
17
  import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
18
18
  import { ParameterProps, Parameters } from "../Parameters.jsx";
19
+ import { DocWhen } from "../doc/comment.jsx";
19
20
 
20
21
  /** Method modifiers. Can only be one. */
21
22
  export interface InterfaceMethodModifiers {
@@ -33,6 +34,9 @@ export interface InterfaceMethodProps
33
34
  children?: Children;
34
35
  parameters?: Array<ParameterProps>;
35
36
  returns?: Children;
37
+
38
+ /** Doc comment */
39
+ doc?: Children;
36
40
  }
37
41
 
38
42
  // a C# interface method
@@ -66,6 +70,7 @@ export function InterfaceMethod(props: InterfaceMethodProps) {
66
70
  return (
67
71
  <MemberDeclaration symbol={methodSymbol}>
68
72
  <Scope value={methodScope}>
73
+ <DocWhen doc={props.doc} />
69
74
  {modifiers}
70
75
  {props.returns ?? "void"} {name}({params})
71
76
  {props.children ?
@@ -120,3 +120,25 @@ it("has getter and setter", () => {
120
120
  }
121
121
  `);
122
122
  });
123
+
124
+ it("specify doc comment", () => {
125
+ expect(
126
+ <TestNamespace>
127
+ <InterfaceDeclaration name="Test">
128
+ <InterfaceProperty
129
+ name="Method"
130
+ type="string"
131
+ get
132
+ set
133
+ doc="This is a test"
134
+ />
135
+ </InterfaceDeclaration>
136
+ </TestNamespace>,
137
+ ).toRenderTo(`
138
+ interface Test
139
+ {
140
+ /// This is a test
141
+ string Method { get; set; }
142
+ }
143
+ `);
144
+ });
@@ -16,6 +16,7 @@ import {
16
16
  import { useCSharpNamePolicy } from "../../name-policy.js";
17
17
  import { CSharpOutputSymbol } from "../../symbols/csharp-output-symbol.js";
18
18
  import { CSharpMemberScope, useCSharpScope } from "../../symbols/scopes.js";
19
+ import { DocWhen } from "../doc/comment.jsx";
19
20
 
20
21
  /** Method modifiers. Can only be one. */
21
22
  export interface InterfacePropertyModifiers {
@@ -41,6 +42,9 @@ export interface InterfacePropertyProps
41
42
 
42
43
  /** If property should have a setter */
43
44
  set?: boolean;
45
+
46
+ /** Doc comment */
47
+ doc?: Children;
44
48
  }
45
49
 
46
50
  // a C# interface property
@@ -71,6 +75,7 @@ export function InterfaceProperty(props: InterfacePropertyProps) {
71
75
  return (
72
76
  <MemberDeclaration symbol={propertySymbol}>
73
77
  <Scope value={propertyScope}>
78
+ <DocWhen doc={props.doc} />
74
79
  {modifiers}
75
80
  {props.type} {name}{" "}
76
81
  <Block newline inline>