Skip to content

[6.2] Strip Leading Whitespace From Symbol Graph Doc Comments #1210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

patshaughnessy
Copy link
Contributor

  • Explanation: Work around a Clang compiler issue with parsing Objective-C or C comments that are missing the leading asterisk on each line.
  • Scope: Changes the way DocC processes doc comments from symbol graphs.
  • Issues: rdar://147354452
  • Original PRs: Strip Leading Whitespace From Symbol Graph Doc Comments #1190
  • Risk: Medium. This adds code to inspect and possibly mutate all doc comments from all symbol graphs. However, the PR adds some detailed tests, and we performed performance benchmarking while reviewing the original PR.
  • Testing: Unit tests covering the important uses cases
  • Reviewers: @d-ronnqvist

* Strip the minimum leading whitespace from all doc comments loaded from
symbol graphs. This worksaround a Clang compiler issue with parsing
comments like this that are missing the leading asterisk:

/**
 Foo's brief description.

 Foo's discussion.
*/

...as opposed to this which Clang does parse properly:

/**
* Foo's brief description.
*
* Foo's discussion.
*/

"Minumum leading whitespace" is defined as:
- Find the doc comment line with least amount of leading whitespace.
  Ignore blank lines during this search.
- Remove that number of whitespace chars from all the lines (including
  blank lines).

* Update Sources/SwiftDocC/Model/DocumentationNode.swift

Refactor a loop to use `contains(where:)`

Co-authored-by: David Rönnqvist <[email protected]>

* [String].linesWithoutLeadingWhitespace returns an array
of substrings, not strings.

* [String].linesWithoutLeadingWhitespace checks for an empty collection
before continuing to parse all the lines

* Tweak comments

---------

Co-authored-by: David Rönnqvist <[email protected]>
@patshaughnessy patshaughnessy changed the base branch from main to release/6.2 April 30, 2025 00:48
@patshaughnessy
Copy link
Contributor Author

@swift-ci please test

@patshaughnessy
Copy link
Contributor Author

@swift-ci please test

@patshaughnessy patshaughnessy merged commit bc58ec2 into swiftlang:release/6.2 May 2, 2025
2 checks passed
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.

4 participants