Add TriviaPiece.commentValue convenience property#3269
Add TriviaPiece.commentValue convenience property#3269William-Laverty wants to merge 3 commits intoswiftlang:mainfrom
TriviaPiece.commentValue convenience property#3269Conversation
Adds a computed property on `TriviaPiece` that returns the text of comment pieces (`.lineComment`, `.blockComment`, `.docLineComment`, `.docBlockComment`) and `nil` for all non-comment pieces. This complements the existing `isComment` property and the higher-level `Trivia.docCommentValue`, providing a simple way to extract the raw text from an individual trivia piece without pattern matching. Includes tests for all comment kinds and non-comment pieces. Resolves swiftlang#1890
|
The key functionality of this property should be to strip the |
Updated commentValue to strip // /// /* */ /** */ markers and return only the actual comment content, consistent with docCommentValue behavior as described in swiftlang#1890. Updated tests to match the new expected values.
|
Updated |
|
Sorry for not reviewing sooner. Could you handle cases like: as described in #1890 (comment) |
|
Also adding a Release Notes entry would be appreciated 🙏 |
- Strip leading '*' decoration from multiline block comments - Skip empty first/last lines in multiline block comments - Add release notes entry for commentValue in 604.md - Add tests for multiline block comment handling Addresses review feedback from @rintaro
|
Thanks for the review @rintaro! I've pushed a fix that:
For the example you mentioned: /*
* Hello, folks!
* // Apples and oranges
* I am a banana!
*/This now returns |
Summary
Adds a
commentValuecomputed property onTriviaPiecethat returns the text of comment pieces andnilfor non-comment pieces.Behavior
commentValue.lineComment("// hello")"// hello".blockComment("/* world */")"/* world */".docLineComment("/// docs")"/// docs".docBlockComment("/** docs */")"/** docs */".spaces(4),.newlines(1), etc.nilThis complements the existing
isCommentproperty and the higher-levelTrivia.docCommentValue, providing a simple way to extract the raw text from an individual trivia piece without pattern matching.Tests
Added
TriviaPieceCommentValueTestscovering all four comment kinds and all non-comment piece types.Resolves #1890