Skip to content

Add JSDoc generation from C# XML documentation comments#78

Draft
Copilot wants to merge 9 commits intomasterfrom
copilot/add-comment-info-property
Draft

Add JSDoc generation from C# XML documentation comments#78
Copilot wants to merge 9 commits intomasterfrom
copilot/add-comment-info-property

Conversation

Copy link

Copilot AI commented Feb 16, 2026

Generates JSDoc comments in TypeScript user class proxies from C# XML documentation. Parses <summary>, <remarks>, <param>, <returns>, and <exception> tags from Roslyn symbols during code generation.

Implementation

  • CommentInfo infrastructure: CommentInfo, ParameterCommentInfo, ThrowsCommentInfo classes with CommentInfoBuilder that extracts XML from ISymbol.GetDocumentationCommentXml()
  • Info class updates: Added nullable Comment property to ClassInfo, MethodInfo, PropertyInfo
  • InfoBuilder integration: ClassInfoBuilder, MethodInfoBuilder, PropertyInfoBuilder now populate Comment via CommentInfoBuilder
  • JSDoc rendering: TypeScriptJSDocRenderer converts CommentInfo to JSDoc format using chained ctx.Append().AppendLine() calls to avoid unnecessary string allocations, integrated into TypescriptUserClassProxyRenderer and TypeScriptMethodRenderer

XML Tag Transformations

Transforms C# XML tags to JSDoc-compatible markdown:

  • <c>, <code> → inline code backticks
  • <paramref name="x"/>`x`
  • <see cref="T:Type"/>`Type` (strips namespace and prefixes)
  • <b>, <strong>**bold**
  • <i>, <em>*italic*
  • <summary> + <remarks> → combined description with blank line separator

Example

C# with XML comments:

/// <summary>Adds two numbers.</summary>
/// <param name="a">First number</param>
/// <param name="b">Second number</param>
/// <returns>Sum of <paramref name="a"/> and <paramref name="b"/></returns>
/// <exception cref="System.OverflowException">Thrown on overflow</exception>
public double Add(double a, double b) => a + b;

Generated TypeScript:

/**
 * Adds two numbers.
 *
 * @param a First number
 * @param b Second number
 * @returns Sum of `a` and `b`
 * @throws {System.OverflowException} Thrown on overflow
 */
public Add(a: number, b: number): number {
  return TypeShimConfig.exports.N.CInterop.Add(this.instance, a, b);
}

Testing

Added TypeScriptJSDocTests with 16 test cases covering:

  • Class, method, and property comments
  • Parameter, return, and exception documentation
  • Inner XML tag transformations (<b>, <i>, <c>, <paramref>) in params, returns, and throws
  • Code tags and parameter references
  • Edge cases (no comments, params only, returns only)
Original prompt

for classinfo, methodinfo and propertyinfo I want to add a new property. the property should be set in the respective infobuilder. the new property will be of type CommentInfo? which gets a builder too. the builder will take the respective symbol as a constructor parameter and call the method to get the xml comment. if there is no comment the builder returns null. if there is a comment string it should be xml parsed to get a set of properties that will be used downstream to render the same content but in jsdoc format.

  • Description: content of the summary tag and remark tag appended. the summary tag can contain various inner tags. check the docs and transform these such that the output is jsdoc compatible i.e. tag or code tags are common.
  • Parameters: list of records ParameterCommentInfo that has the name and description. should also parse inner tags
  • returns: the return tag content. also parse inner tags
  • throws: type and description in record. also inner tags.

then we need a new typescript jsdoc renderer that can be used during property, method and class rendering to turn this object into valid jsdoc. this should only be used for the user class proxy and is not necessary for other typescript code generation

make sure existing tests are unaffected. we should only need to add the calls to the jsdoc renderer into the existing renderers for typescript. add a new test file that shows tests for properties methods and classes with comments and also permutations with and without parameter content, exception and returns information in the c# xml comment.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 6 commits February 16, 2026 23:26
Co-authored-by: ArcadeMode <5969155+ArcadeMode@users.noreply.github.com>
Co-authored-by: ArcadeMode <5969155+ArcadeMode@users.noreply.github.com>
Co-authored-by: ArcadeMode <5969155+ArcadeMode@users.noreply.github.com>
… endings

Co-authored-by: ArcadeMode <5969155+ArcadeMode@users.noreply.github.com>
Co-authored-by: ArcadeMode <5969155+ArcadeMode@users.noreply.github.com>
Co-authored-by: ArcadeMode <5969155+ArcadeMode@users.noreply.github.com>
Copilot AI changed the title [WIP] Add CommentInfo property to classinfo, methodinfo, and propertyinfo Add JSDoc generation from C# XML documentation comments Feb 16, 2026
Copilot AI requested a review from ArcadeMode February 16, 2026 23:40
Copy link
Owner

@ArcadeMode ArcadeMode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new class with tests to the generator.tests project that demonstrate various comments with different contents

…class

Co-authored-by: ArcadeMode <5969155+ArcadeMode@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 17, 2026

Add a new class with tests to the generator.tests project that demonstrate various comments with different contents

Added a comprehensive test in commit a46561b that demonstrates a Calculator class with various comment types including:

  • Class documentation with summary and remarks
  • Methods with params, returns, and multiple exceptions
  • Properties with documentation (getter/setter and read-only)
  • Inner XML tag transformations (code tags and paramrefs)

The test validates all JSDoc features working together in a single realistic example. All 12 JSDoc tests pass.

@github-actions
Copy link

Test Results

  3 files  ± 0   17 suites  ±0   25s ⏱️ -1s
668 tests +12  664 ✅ +12  4 💤 ±0  0 ❌ ±0 
842 runs  +12  835 ✅ +12  7 💤 ±0  0 ❌ ±0 

Results for commit a46561b. ± Comparison against base commit 3705083.

Copy link
Owner

@ArcadeMode ArcadeMode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the last added test (the comprehensive one) the rest is fine. Then change the new renderer to not use interpolation expressions, instead chain append and appendline calls on the render context to not cause unnecessary intermediate string allocations

Do add tests for rendering with other tags like bold and italics. Also show the inner tag parsing inside throws returns and params

… tests

Co-authored-by: ArcadeMode <5969155+ArcadeMode@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 17, 2026

Remove the last added test (the comprehensive one) the rest is fine. Then change the new renderer to not use interpolation expressions, instead chain append and appendline calls on the render context ...

Changes completed in commit 00f462c:

  1. Removed the comprehensive test
  2. Refactored TypeScriptJSDocRenderer to use chained ctx.Append().AppendLine() calls instead of string interpolation
  3. Added 5 new tests demonstrating:
    • Bold tag (<b>) → **bold**
    • Italic tag (<i>) → *italic*
    • Inner tags in params (bold, code, italic)
    • Inner tags in returns (bold, code, italic)
    • Inner tags in throws (paramref, code, italic)

All 503 tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants