BridgeJS: Include Swift doc comments in generated d.ts#771
Merged
Conversation
94347db to
5ccc689
Compare
Propagate Swift `///` and `/** */` documentation on exported declarations into the generated TypeScript declarations as JSDoc, so editors surface hover docs for the bridged API. The exporter now captures the leading doc comment for functions, classes, methods, properties, constructors, structs, and enums into the skeleton, and the linker renders it as a single JSDoc block. The Swift DocC field list is mapped as the inverse of the TS2Swift importer: the leading description becomes the JSDoc body, `- Parameters:`/`- Parameter x:` become `@param`, `- Returns:` becomes `@returns`, and `- Throws:` becomes `@throws`. Existing default-value annotations are merged into the same block so a parameter never emits two comment blocks; declarations without doc comments produce byte-identical output to before.
5ccc689 to
45088be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Resolves #769. Swift API doc comments on exported declarations are now propagated into the generated TypeScript declarations as JSDoc, so editors surface hover documentation for the bridged API.
The exporter captures the leading doc comment (
///and/** */) for each exported declaration into the skeleton, and the linker renders it as a single JSDoc block. The mapping is the inverse of the JSDoc to Swift DocC conversion the TS2Swift importer already performs, so the two directions stay symmetric:- Parameters:/- Parameter name:items become@param name <desc>.- Returns:becomes@returns <desc>.- Throws:becomes@throws <desc>.1. Coverage. Doc comments are emitted for exported functions, classes (description, constructor, methods, properties), structs (description, fields), enums (description and const-style object-type static members), protocols (description, methods, properties), and namespaced declarations in both the
Exportstype hierarchy and thedeclare global { namespace ... }declarations.2. Merged with default-value annotations. The default-value JSDoc that was previously the only thing emitted is now folded into the same block, so a parameter never produces two separate comment blocks. Declarations without doc comments produce byte-identical output to before.
3. Comment terminators are escaped. A
*/inside a Swift doc comment is rewritten so it cannot prematurely close the generated JSDoc block.Example
Testing
Adds a
DocCommentscodegen/link fixture covering the mapping (functions, classes, structs, enums, protocols, namespaced functions, default-value merge, and*/escaping), and documents a namespaced declaration in the existingNamespacesfixture to cover thedeclare globalpath. Snapshot, codegen, and generated-d.ts validation all pass.